diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-05-29 03:57:40 +0300 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-05-29 03:57:40 +0300 |
commit | 836ec0a47f3b852e9a95f3792fb3f72ea3c875c3 (patch) | |
tree | b53c7a877da78fce42bfe4274f7bfe21ed4b038b | |
parent | e8a6b27656080ac8f21a79d7b56c95c834b35cc8 (diff) |
pthread: Implement monotonic/relative wait funcs
-rw-r--r-- | src/libpthread.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/libpthread.c b/src/libpthread.c index f640c45..0488365 100644 --- a/src/libpthread.c +++ b/src/libpthread.c @@ -121,20 +121,6 @@ bionic___pthread_cleanup_pop(void *c, int execute) } int -bionic_pthread_cond_timedwait_relative_np(bionic_cond_t *cond, bionic_mutex_t *mutex, const struct timespec *reltime) -{ - assert(0 && "implement"); - return 0; -} - -int -bionic_pthread_cond_timedwait_monotonic_np(bionic_cond_t *cond, bionic_mutex_t *mutex, const struct timespec *abstime) -{ - assert(0 && "implement"); - return 0; -} - -int bionic_sem_destroy(bionic_sem_t *sem) { assert(sem); @@ -452,3 +438,33 @@ bionic_pthread_cond_timedwait(bionic_cond_t *cond, bionic_mutex_t *mutex, const INIT_IF_NOT_MAPPED(mutex, default_pthread_mutex_init); return pthread_cond_timedwait(cond->glibc, mutex->glibc, abs_timeout); } + +int +bionic_pthread_cond_timedwait_relative_np(bionic_cond_t *cond, bionic_mutex_t *mutex, const struct timespec *reltime) +{ + assert(cond && mutex && reltime); + struct timespec tv; + clock_gettime(CLOCK_REALTIME, &tv); + tv.tv_sec += reltime->tv_sec; + tv.tv_nsec += reltime->tv_nsec; + if (tv.tv_nsec >= 1000000000) { + ++tv.tv_sec; + tv.tv_nsec -= 1000000000; + } + return bionic_pthread_cond_timedwait(cond, mutex, &tv); +} + +int +bionic_pthread_cond_timedwait_monotonic_np(bionic_cond_t *cond, bionic_mutex_t *mutex, const struct timespec *abstime) +{ + assert(cond && mutex && abstime); + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + tv.tv_sec += abstime->tv_sec; + tv.tv_nsec += abstime->tv_nsec; + if (tv.tv_nsec >= 1000000000) { + ++tv.tv_sec; + tv.tv_nsec -= 1000000000; + } + return bionic_pthread_cond_timedwait(cond, mutex, &tv); +} |