diff options
author | Bruno Haible <bruno@clisp.org> | 2019-11-27 06:03:21 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-11-27 06:03:21 +0100 |
commit | 721d00b4505054875aa5530c230ca9ede5452d96 (patch) | |
tree | b540f6c499f77f67ccd084610ad321c44409f855 /lib/glthread/cond.c | |
parent | 42a045242f9d156becfb4d3fb63dcc607230369a (diff) | |
download | gnulib-721d00b4505054875aa5530c230ca9ede5452d96.tar.gz |
New options --enable-threads=isoc and --enable-threads=isoc+posix.
* m4/threadlib.m4 (gl_THREADLIB_EARLY_BODY): Accept the options
--enable-threads=isoc and --enable-threads=isoc+posix.
(gl_THREADLIB_BODY): Test whether the ISO C threads API is available.
When both the ISO C and the POSIX threads API are available, choose
USE_ISOC_AND_POSIX_THREADS instead of USE_POSIX_THREADS if
--enable-threads=isoc+posix was specified. When only the ISO C threads
API is available and --enable-threads=iso was specified, choose
USE_ISOC_THREADS.
* lib/glthread/lock.h: Add new code for USE_ISOC_THREADS ||
USE_ISOC_AND_POSIX_THREADS.
* lib/glthread/lock.c: Likewise.
* lib/glthread/cond.h: Likewise.
* lib/glthread/cond.c: Likewise.
* lib/glthread/tls.h: Likewise.
* lib/glthread/tls.c: Likewise.
* lib/glthread/yield.h: Likewise.
* lib/glthread/thread.h: Add new code for USE_ISOC_THREADS. Treat
USE_ISOC_AND_POSIX_THREADS like USE_POSIX_THREADS.
* lib/glthread/thread.c: Likewise.
* lib/glthread/threadlib.c: Likewise.
* tests/test-lock.c: Save and restore the values of USE_ISOC_THREADS and
USE_ISOC_AND_POSIX_THREADS.
* tests/test-cond.c: Consider USE_ISOC_THREADS and
USE_ISOC_AND_POSIX_THREADS.
* tests/test-tls.c: Likewise.
* tests/test-thread_create.c (main): Likewise.
* tests/test-pthread-cond.c: Likewise.
* tests/test-pthread-mutex.c: Likewise.
* tests/test-pthread-once2.c: Likewise.
* tests/test-pthread-rwlock.c: Likewise.
* tests/test-pthread-tss.c: Likewise.
* tests/test-pthread_sigmask2.c: Treat USE_ISOC_AND_POSIX_THREADS like
USE_POSIX_THREADS.
Diffstat (limited to 'lib/glthread/cond.c')
-rw-r--r-- | lib/glthread/cond.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/glthread/cond.c b/lib/glthread/cond.c index f6a06cc9fa..df166bfe4b 100644 --- a/lib/glthread/cond.c +++ b/lib/glthread/cond.c @@ -24,6 +24,88 @@ /* ========================================================================= */ +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +int +glthread_cond_init (gl_cond_t *condition) +{ + if (cnd_init (&condition->condition) != thrd_success) + return ENOMEM; + condition->init_needed = 0; + return 0; +} + +int +glthread_cond_wait (gl_cond_t *condition, gl_lock_t *lock) +{ + if (condition->init_needed) + call_once (&condition->init_once, condition->init_func); + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (cnd_wait (&condition->condition, &lock->mutex) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_cond_timedwait (gl_cond_t *condition, gl_lock_t *lock, + const struct timespec *abstime) +{ + if (condition->init_needed) + call_once (&condition->init_once, condition->init_func); + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + switch (cnd_timedwait (&condition->condition, &lock->mutex, abstime)) + { + case thrd_success: + break; + case thrd_timedout: + return ETIMEDOUT; + default: + return EINVAL; + } + return 0; +} + +int +glthread_cond_signal (gl_cond_t *condition) +{ + if (condition->init_needed) + call_once (&condition->init_once, condition->init_func); + if (cnd_signal (&condition->condition) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_cond_broadcast (gl_cond_t *condition) +{ + if (condition->init_needed) + call_once (&condition->init_once, condition->init_func); + if (cnd_broadcast (&condition->condition) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_cond_destroy (gl_cond_t *condition) +{ + if (condition->init_needed) + call_once (&condition->init_once, condition->init_func); + cnd_destroy (&condition->condition); + return 0; +} + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +#endif + +/* ========================================================================= */ + #if USE_WINDOWS_THREADS #endif |