add C11 condition variable functions
Because of the clear separation for private pthread_cond_t these interfaces are quite simple and direct.
This commit is contained in:
parent
8b0472932c
commit
14397cec2c
6 changed files with 57 additions and 0 deletions
10
src/thread/cnd_broadcast.c
Normal file
10
src/thread/cnd_broadcast.c
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
6
src/thread/cnd_destroy.c
Normal file
6
src/thread/cnd_destroy.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include <threads.h>
|
||||||
|
|
||||||
|
void cnd_destroy(cnd_t *c)
|
||||||
|
{
|
||||||
|
/* For private cv this is a no-op */
|
||||||
|
}
|
||||||
7
src/thread/cnd_init.c
Normal file
7
src/thread/cnd_init.c
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <threads.h>
|
||||||
|
|
||||||
|
int cnd_init(cnd_t *c)
|
||||||
|
{
|
||||||
|
*c = (cnd_t){ 0 };
|
||||||
|
return thrd_success;
|
||||||
|
}
|
||||||
10
src/thread/cnd_signal.c
Normal file
10
src/thread/cnd_signal.c
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
15
src/thread/cnd_timedwait.c
Normal file
15
src/thread/cnd_timedwait.c
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/thread/cnd_wait.c
Normal file
9
src/thread/cnd_wait.c
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue