summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-08-20 13:14:01 -0400
committerJakob Kaivo <jkk@ung.org>2019-08-20 13:14:01 -0400
commit275c64a746a43fa1f8ee0b7b3a8ab37abab0d326 (patch)
tree8d4cb708cae93148864605e85c832f7fee98e952
parente8e4e90e3667efb174fbf2548c22cc6caaebfcf1 (diff)
return correct values
-rw-r--r--src/threads/cnd_broadcast.c2
-rw-r--r--src/threads/cnd_init.c14
-rw-r--r--src/threads/cnd_signal.c2
-rw-r--r--src/threads/cnd_timedwait.c14
-rw-r--r--src/threads/cnd_wait.c2
-rw-r--r--src/threads/mtx_init.c3
-rw-r--r--src/threads/mtx_timedlock.c14
-rw-r--r--src/threads/mtx_trylock.c14
-rw-r--r--src/threads/mtx_unlock.c2
-rw-r--r--src/threads/thrd_create.c14
-rw-r--r--src/threads/thrd_detach.c2
-rw-r--r--src/threads/thrd_join.c2
-rw-r--r--src/threads/tss_create.c2
-rw-r--r--src/threads/tss_set.c2
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;
}