diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/thread/cnd_broadcast.c | 10 | ||||
-rw-r--r-- | src/thread/cnd_destroy.c | 6 | ||||
-rw-r--r-- | src/thread/cnd_init.c | 7 | ||||
-rw-r--r-- | src/thread/cnd_signal.c | 10 | ||||
-rw-r--r-- | src/thread/cnd_timedwait.c | 15 | ||||
-rw-r--r-- | src/thread/cnd_wait.c | 9 |
6 files changed, 57 insertions, 0 deletions
diff --git a/src/thread/cnd_broadcast.c b/src/thread/cnd_broadcast.c new file mode 100644 index 00000000..85d4d3ea --- /dev/null +++ b/src/thread/cnd_broadcast.c @@ -0,0 +1,10 @@ +#include <threads.h> + +int __private_cond_signal(cnd_t *, int); + +int cnd_broadcast(cnd_t *c) +{ + /* This internal function never fails, and always returns zero, + * which matches the value thrd_success is defined with. */ + return __private_cond_signal(c, -1); +} diff --git a/src/thread/cnd_destroy.c b/src/thread/cnd_destroy.c new file mode 100644 index 00000000..453c90be --- /dev/null +++ b/src/thread/cnd_destroy.c @@ -0,0 +1,6 @@ +#include <threads.h> + +void cnd_destroy(cnd_t *c) +{ + /* For private cv this is a no-op */ +} diff --git a/src/thread/cnd_init.c b/src/thread/cnd_init.c new file mode 100644 index 00000000..18c50855 --- /dev/null +++ b/src/thread/cnd_init.c @@ -0,0 +1,7 @@ +#include <threads.h> + +int cnd_init(cnd_t *c) +{ + *c = (cnd_t){ 0 }; + return thrd_success; +} diff --git a/src/thread/cnd_signal.c b/src/thread/cnd_signal.c new file mode 100644 index 00000000..1211260b --- /dev/null +++ b/src/thread/cnd_signal.c @@ -0,0 +1,10 @@ +#include <threads.h> + +int __private_cond_signal(cnd_t *, int); + +int cnd_signal(cnd_t *c) +{ + /* This internal function never fails, and always returns zero, + * which matches the value thrd_success is defined with. */ + return __private_cond_signal(c, 1); +} diff --git a/src/thread/cnd_timedwait.c b/src/thread/cnd_timedwait.c new file mode 100644 index 00000000..59976793 --- /dev/null +++ b/src/thread/cnd_timedwait.c @@ -0,0 +1,15 @@ +#include <threads.h> +#include <errno.h> + +int __pthread_cond_timedwait(cnd_t *restrict, mtx_t *restrict, const struct timespec *restrict); + +int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct timespec *restrict ts) +{ + int ret = __pthread_cond_timedwait(c, m, ts); + switch (ret) { + /* May also return EINVAL or EPERM. */ + default: return thrd_error; + case 0: return thrd_success; + case ETIMEDOUT: return thrd_timedout; + } +} diff --git a/src/thread/cnd_wait.c b/src/thread/cnd_wait.c new file mode 100644 index 00000000..602796f8 --- /dev/null +++ b/src/thread/cnd_wait.c @@ -0,0 +1,9 @@ +#include <threads.h> + +int cnd_wait(cnd_t *c, mtx_t *m) +{ + /* Calling cnd_timedwait with a null pointer is an extension. + * It is convenient here to avoid duplication of the logic + * for return values. */ + return cnd_timedwait(c, m, 0); +} |