1 /*
2 * Copyright (c) 2023, Meta
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <errno.h>
8 #include <threads.h>
9
10 #include <zephyr/posix/pthread.h>
11
cnd_broadcast(cnd_t * cond)12 int cnd_broadcast(cnd_t *cond)
13 {
14 switch (pthread_cond_broadcast(cond)) {
15 case 0:
16 return thrd_success;
17 default:
18 return thrd_error;
19 }
20 }
21
cnd_destroy(cnd_t * cond)22 void cnd_destroy(cnd_t *cond)
23 {
24 (void)pthread_cond_destroy(cond);
25 }
26
cnd_init(cnd_t * cond)27 int cnd_init(cnd_t *cond)
28 {
29 switch (pthread_cond_init(cond, NULL)) {
30 case 0:
31 return thrd_success;
32 case ENOMEM:
33 return thrd_nomem;
34 default:
35 return thrd_error;
36 }
37 }
38
cnd_signal(cnd_t * cond)39 int cnd_signal(cnd_t *cond)
40 {
41 switch (pthread_cond_signal(cond)) {
42 case 0:
43 return thrd_success;
44 case ENOMEM:
45 return thrd_nomem;
46 default:
47 return thrd_error;
48 }
49 }
50
cnd_timedwait(cnd_t * restrict cond,mtx_t * restrict mtx,const struct timespec * restrict ts)51 int cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx, const struct timespec *restrict ts)
52 {
53 switch (pthread_cond_timedwait(cond, mtx, ts)) {
54 case 0:
55 return thrd_success;
56 case ETIMEDOUT:
57 return thrd_timedout;
58 default:
59 return thrd_error;
60 }
61 }
62
cnd_wait(cnd_t * cond,mtx_t * mtx)63 int cnd_wait(cnd_t *cond, mtx_t *mtx)
64 {
65 switch (pthread_cond_wait(cond, mtx)) {
66 case 0:
67 return thrd_success;
68 default:
69 return thrd_error;
70 }
71 }
72