Move stuff only needed by pthread-timers.c into pthread-timers.c.
Change-Id: I4915b3fff9c4f5a36b4f51027fb22019c11607b0
diff --git a/libc/bionic/pthread-timers.c b/libc/bionic/pthread-timers.c
index 2ad0b90..d81bfef 100644
--- a/libc/bionic/pthread-timers.c
+++ b/libc/bionic/pthread-timers.c
@@ -33,6 +33,12 @@
#include <stdio.h>
#include <string.h>
+extern int __pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*,
+ clockid_t);
+
+extern int __pthread_cond_timedwait_relative(pthread_cond_t*, pthread_mutex_t*,
+ const struct timespec*);
+
// Normal (i.e. non-SIGEV_THREAD) timers are created directly by the kernel
// and are passed as is to/from the caller.
//
@@ -279,6 +285,49 @@
pthread_mutex_unlock(&t->mutex);
}
+
+static __inline__ void timespec_add(struct timespec* a, const struct timespec* b) {
+ a->tv_sec += b->tv_sec;
+ a->tv_nsec += b->tv_nsec;
+ if (a->tv_nsec >= 1000000000) {
+ a->tv_nsec -= 1000000000;
+ a->tv_sec += 1;
+ }
+}
+
+static __inline__ void timespec_sub(struct timespec* a, const struct timespec* b) {
+ a->tv_sec -= b->tv_sec;
+ a->tv_nsec -= b->tv_nsec;
+ if (a->tv_nsec < 0) {
+ a->tv_nsec += 1000000000;
+ a->tv_sec -= 1;
+ }
+}
+
+static __inline__ void timespec_zero(struct timespec* a) {
+ a->tv_sec = a->tv_nsec = 0;
+}
+
+static __inline__ int timespec_is_zero(const struct timespec* a) {
+ return (a->tv_sec == 0 && a->tv_nsec == 0);
+}
+
+static __inline__ int timespec_cmp(const struct timespec* a, const struct timespec* b) {
+ if (a->tv_sec < b->tv_sec) return -1;
+ if (a->tv_sec > b->tv_sec) return +1;
+ if (a->tv_nsec < b->tv_nsec) return -1;
+ if (a->tv_nsec > b->tv_nsec) return +1;
+ return 0;
+}
+
+static __inline__ int timespec_cmp0(const struct timespec* a) {
+ if (a->tv_sec < 0) return -1;
+ if (a->tv_sec > 0) return +1;
+ if (a->tv_nsec < 0) return -1;
+ if (a->tv_nsec > 0) return +1;
+ return 0;
+}
+
/** POSIX TIMERS APIs */
extern int __timer_create(clockid_t, struct sigevent*, timer_t*);