diff options
| -rw-r--r-- | src/threads/cnd_broadcast.c | 2 | ||||
| -rw-r--r-- | src/threads/cnd_init.c | 14 | ||||
| -rw-r--r-- | src/threads/cnd_signal.c | 2 | ||||
| -rw-r--r-- | src/threads/cnd_timedwait.c | 14 | ||||
| -rw-r--r-- | src/threads/cnd_wait.c | 2 | ||||
| -rw-r--r-- | src/threads/mtx_init.c | 3 | ||||
| -rw-r--r-- | src/threads/mtx_timedlock.c | 14 | ||||
| -rw-r--r-- | src/threads/mtx_trylock.c | 14 | ||||
| -rw-r--r-- | src/threads/mtx_unlock.c | 2 | ||||
| -rw-r--r-- | src/threads/thrd_create.c | 14 | ||||
| -rw-r--r-- | src/threads/thrd_detach.c | 2 | ||||
| -rw-r--r-- | src/threads/thrd_join.c | 2 | ||||
| -rw-r--r-- | src/threads/tss_create.c | 2 | ||||
| -rw-r--r-- | src/threads/tss_set.c | 2 |
14 files changed, 75 insertions, 14 deletions
diff --git a/src/threads/cnd_broadcast.c b/src/threads/cnd_broadcast.c index 863ed380..4735b97e 100644 --- a/src/threads/cnd_broadcast.c +++ b/src/threads/cnd_broadcast.c @@ -3,5 +3,5 @@ int cnd_broadcast(cnd_t *cond) { - return pthread_cond_broadcast(cond); + return pthread_cond_broadcast(cond) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/cnd_init.c b/src/threads/cnd_init.c index 822076e5..96fc0490 100644 --- a/src/threads/cnd_init.c +++ b/src/threads/cnd_init.c @@ -1,7 +1,19 @@ #include <threads.h> #include <pthread.h> +#include <errno.h> int cnd_init(cnd_t *cond) { - return pthread_cond_init(cond, 0); + switch (pthread_cond_init(cond, 0)) { + case 0: + return thrd_success; + + case ENOMEM: + return thrd_nomem; + + default: + break; + } + + return thrd_error; } diff --git a/src/threads/cnd_signal.c b/src/threads/cnd_signal.c index fa881c26..0a00d095 100644 --- a/src/threads/cnd_signal.c +++ b/src/threads/cnd_signal.c @@ -3,5 +3,5 @@ int cnd_signal(cnd_t *cond) { - return pthread_cond_signal(cond); + return pthread_cond_signal(cond) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/cnd_timedwait.c b/src/threads/cnd_timedwait.c index 9a68db72..d3421cff 100644 --- a/src/threads/cnd_timedwait.c +++ b/src/threads/cnd_timedwait.c @@ -1,7 +1,19 @@ #include <threads.h> #include <pthread.h> +#include <errno.h> int cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx, const struct timespec *restrict ts) { - return pthread_cond_timedwait(cond, mtx, ts); + switch (pthread_cond_timedwait(cond, mtx, ts)) { + case 0: + return thrd_success; + + case ETIMEDOUT: + return thrd_timedout; + + default: + break; + } + + return thrd_error; } diff --git a/src/threads/cnd_wait.c b/src/threads/cnd_wait.c index 4c1152f6..41d77c01 100644 --- a/src/threads/cnd_wait.c +++ b/src/threads/cnd_wait.c @@ -3,5 +3,5 @@ int cnd_wait(cnd_t *cond, mtx_t *mtx) { - return pthread_cond_wait(cond, mtx); + return pthread_cond_wait(cond, mtx) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/mtx_init.c b/src/threads/mtx_init.c index f3db0ed8..5615736b 100644 --- a/src/threads/mtx_init.c +++ b/src/threads/mtx_init.c @@ -1,5 +1,6 @@ #include <threads.h> #include <pthread.h> +#include <errno.h> int mtx_init(mtx_t *mtx, int type) { @@ -10,5 +11,5 @@ int mtx_init(mtx_t *mtx, int type) } else { pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); } - return pthread_mutex_init(mtx, &attr); + return pthread_mutex_init(mtx, &attr) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/mtx_timedlock.c b/src/threads/mtx_timedlock.c index a24c213d..1e8ec23b 100644 --- a/src/threads/mtx_timedlock.c +++ b/src/threads/mtx_timedlock.c @@ -1,7 +1,19 @@ #include <threads.h> #include <pthread.h> +#include <errno.h> int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts) { - return pthread_mutex_timedlock(mtx, ts); + switch (pthread_mutex_timedlock(mtx, ts)) { + case 0: + return thrd_success; + + case ETIMEDOUT: + return thrd_timedout; + + default: + break; + } + + return thrd_error; } diff --git a/src/threads/mtx_trylock.c b/src/threads/mtx_trylock.c index c04741d6..cf2b6005 100644 --- a/src/threads/mtx_trylock.c +++ b/src/threads/mtx_trylock.c @@ -1,7 +1,19 @@ #include <threads.h> #include <pthread.h> +#include <errno.h> int mtx_trylock(mtx_t *mtx) { - return pthread_mutex_trylock(mtx); + switch (pthread_mutex_trylock(mtx)) { + case 0: + return thrd_success; + + case EBUSY: + return thrd_busy; + + default: + break; + } + + return thrd_error; } diff --git a/src/threads/mtx_unlock.c b/src/threads/mtx_unlock.c index 5998f8c9..0e4abfab 100644 --- a/src/threads/mtx_unlock.c +++ b/src/threads/mtx_unlock.c @@ -3,5 +3,5 @@ int mtx_unlock(mtx_t *mtx) { - return mtx_unlock(mtx); + return mtx_unlock(mtx) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/thrd_create.c b/src/threads/thrd_create.c index 516c0c66..100d16cc 100644 --- a/src/threads/thrd_create.c +++ b/src/threads/thrd_create.c @@ -1,8 +1,20 @@ #include <threads.h> #include <pthread.h> +#include <errno.h> int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { typedef void *(*pthread_start_fn)(void*); - return pthread_create(thr, 0, (pthread_start_fn)func, arg); + switch (pthread_create(thr, 0, (pthread_start_fn)func, arg)) { + case 0: + return thrd_success; + + case ENOMEM: + return thrd_nomem; + + default: + break; + } + + return thrd_error; } diff --git a/src/threads/thrd_detach.c b/src/threads/thrd_detach.c index 73de91c5..2e178bc3 100644 --- a/src/threads/thrd_detach.c +++ b/src/threads/thrd_detach.c @@ -3,5 +3,5 @@ int thrd_detach(thrd_t thr) { - return pthread_detach(thr); + return pthread_detach(thr) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/thrd_join.c b/src/threads/thrd_join.c index f85d7a71..a44e4021 100644 --- a/src/threads/thrd_join.c +++ b/src/threads/thrd_join.c @@ -3,5 +3,5 @@ int thrd_join(thrd_t thr, int *res) { - return pthread_join(thr, (void**)&res); + return pthread_join(thr, (void**)&res) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/tss_create.c b/src/threads/tss_create.c index 47b1d5d4..97803893 100644 --- a/src/threads/tss_create.c +++ b/src/threads/tss_create.c @@ -3,5 +3,5 @@ int tss_create(tss_t *key, tss_dtor_t dtor) { - return pthread_key_create(key, dtor); + return pthread_key_create(key, dtor) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/tss_set.c b/src/threads/tss_set.c index b9c39c75..899bd071 100644 --- a/src/threads/tss_set.c +++ b/src/threads/tss_set.c @@ -3,5 +3,5 @@ int tss_set(tss_t key, void *val) { - return pthread_setspecific(key, val); + return pthread_setspecific(key, val) == 0 ? thrd_success : thrd_error; } |
