diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-08-20 12:54:51 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-08-20 12:54:51 -0400 |
commit | c9436d428586d501de341838b591bd59d29aa0d7 (patch) | |
tree | 816287ac4b8eeec93e463b0238e9fad934cedb57 /src | |
parent | 17c366e61acef079dd636a7280f46bab88d50a6f (diff) |
initial version
Diffstat (limited to 'src')
36 files changed, 209 insertions, 0 deletions
diff --git a/src/threads/ONCE_FLAG_INIT.c b/src/threads/ONCE_FLAG_INIT.c new file mode 100644 index 00000000..2337950e --- /dev/null +++ b/src/threads/ONCE_FLAG_INIT.c @@ -0,0 +1 @@ +#define ONCE_FLAG_INIT /* same as PTHREAD_ONCE_INIT */ diff --git a/src/threads/TSS_DTOR_ITERATIONS.c b/src/threads/TSS_DTOR_ITERATIONS.c new file mode 100644 index 00000000..557fb656 --- /dev/null +++ b/src/threads/TSS_DTOR_ITERATIONS.c @@ -0,0 +1 @@ +#define TSS_DTOR_ITERATIONS (64) diff --git a/src/threads/_enums.c b/src/threads/_enums.c new file mode 100644 index 00000000..6e099b0f --- /dev/null +++ b/src/threads/_enums.c @@ -0,0 +1,16 @@ +enum { + mtx_plain = 1 << 0, + mtx_recursive = 1 << 1, + mtx_timed = 1 << 2, +}; + +enum { + mtx_timedout = 1 << 3 +}; + +enum { + thrd_success = 0, + thrd_busy = 1, + thrd_error = 2, + thrd_nomem = 3, +}; diff --git a/src/threads/call_once.c b/src/threads/call_once.c new file mode 100644 index 00000000..14f4962d --- /dev/null +++ b/src/threads/call_once.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +void call_once(once_flag *flag, void (*func)(void)) +{ + pthread_once(flag, func); +} diff --git a/src/threads/cnd_broadcast.c b/src/threads/cnd_broadcast.c new file mode 100644 index 00000000..863ed380 --- /dev/null +++ b/src/threads/cnd_broadcast.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int cnd_broadcast(cnd_t *cond) +{ + return pthread_cond_broadcast(cond); +} diff --git a/src/threads/cnd_destroy.c b/src/threads/cnd_destroy.c new file mode 100644 index 00000000..7fda89bf --- /dev/null +++ b/src/threads/cnd_destroy.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +void cnd_destroy(cnd_t *cond) +{ + pthread_cond_destroy(cond); +} diff --git a/src/threads/cnd_init.c b/src/threads/cnd_init.c new file mode 100644 index 00000000..822076e5 --- /dev/null +++ b/src/threads/cnd_init.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int cnd_init(cnd_t *cond) +{ + return pthread_cond_init(cond, 0); +} diff --git a/src/threads/cnd_signal.c b/src/threads/cnd_signal.c new file mode 100644 index 00000000..fa881c26 --- /dev/null +++ b/src/threads/cnd_signal.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int cnd_signal(cnd_t *cond) +{ + return pthread_cond_signal(cond); +} diff --git a/src/threads/cnd_t.c b/src/threads/cnd_t.c new file mode 100644 index 00000000..8974db4c --- /dev/null +++ b/src/threads/cnd_t.c @@ -0,0 +1 @@ +typedef /* same as pthread_cond_t */ cnd_t; diff --git a/src/threads/cnd_timedwait.c b/src/threads/cnd_timedwait.c new file mode 100644 index 00000000..9a68db72 --- /dev/null +++ b/src/threads/cnd_timedwait.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx, const struct timespec *restrict ts) +{ + return pthread_cond_timedwait(cond, mtx, ts); +} diff --git a/src/threads/cnd_wait.c b/src/threads/cnd_wait.c new file mode 100644 index 00000000..4c1152f6 --- /dev/null +++ b/src/threads/cnd_wait.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int cnd_wait(cnd_t *cond, mtx_t *mtx) +{ + return pthread_cond_wait(cond, mtx); +} diff --git a/src/threads/mtx_destroy.c b/src/threads/mtx_destroy.c new file mode 100644 index 00000000..7693b018 --- /dev/null +++ b/src/threads/mtx_destroy.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +void mtx_destroy(mtx_t *mtx) +{ + pthread_mutex_destroy(mtx); +} diff --git a/src/threads/mtx_init.c b/src/threads/mtx_init.c new file mode 100644 index 00000000..f3db0ed8 --- /dev/null +++ b/src/threads/mtx_init.c @@ -0,0 +1,14 @@ +#include <threads.h> +#include <pthread.h> + +int mtx_init(mtx_t *mtx, int type) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + if (type & mtx_recursive) { + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + } else { + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); + } + return pthread_mutex_init(mtx, &attr); +} diff --git a/src/threads/mtx_lock.c b/src/threads/mtx_lock.c new file mode 100644 index 00000000..3ab52bff --- /dev/null +++ b/src/threads/mtx_lock.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int mtx_lock(mtx_t *mtx) +{ + return pthread_mutex_lock(mtx); +} diff --git a/src/threads/mtx_t.c b/src/threads/mtx_t.c new file mode 100644 index 00000000..aa761c1c --- /dev/null +++ b/src/threads/mtx_t.c @@ -0,0 +1 @@ +typedef /* same as pthread_mutex_t */ mtx_t; diff --git a/src/threads/mtx_timedlock.c b/src/threads/mtx_timedlock.c new file mode 100644 index 00000000..a24c213d --- /dev/null +++ b/src/threads/mtx_timedlock.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts) +{ + return pthread_mutex_timedlock(mtx, ts); +} diff --git a/src/threads/mtx_trylock.c b/src/threads/mtx_trylock.c new file mode 100644 index 00000000..c04741d6 --- /dev/null +++ b/src/threads/mtx_trylock.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int mtx_trylock(mtx_t *mtx) +{ + return pthread_mutex_trylock(mtx); +} diff --git a/src/threads/mtx_unlock.c b/src/threads/mtx_unlock.c new file mode 100644 index 00000000..5998f8c9 --- /dev/null +++ b/src/threads/mtx_unlock.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int mtx_unlock(mtx_t *mtx) +{ + return mtx_unlock(mtx); +} diff --git a/src/threads/once_flag.c b/src/threads/once_flag.c new file mode 100644 index 00000000..989bb1a7 --- /dev/null +++ b/src/threads/once_flag.c @@ -0,0 +1 @@ +typedef /* same as pthread_once_t */ once_flag; diff --git a/src/threads/thrd_create.c b/src/threads/thrd_create.c new file mode 100644 index 00000000..516c0c66 --- /dev/null +++ b/src/threads/thrd_create.c @@ -0,0 +1,8 @@ +#include <threads.h> +#include <pthread.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); +} diff --git a/src/threads/thrd_current.c b/src/threads/thrd_current.c new file mode 100644 index 00000000..34333fdd --- /dev/null +++ b/src/threads/thrd_current.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +thrd_t thrd_current(void) +{ + return pthread_self(); +} diff --git a/src/threads/thrd_detach.c b/src/threads/thrd_detach.c new file mode 100644 index 00000000..73de91c5 --- /dev/null +++ b/src/threads/thrd_detach.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int thrd_detach(thrd_t thr) +{ + return pthread_detach(thr); +} diff --git a/src/threads/thrd_equal.c b/src/threads/thrd_equal.c new file mode 100644 index 00000000..7e582310 --- /dev/null +++ b/src/threads/thrd_equal.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int thrd_equal(thrd_t thr0, thrd_t thr1) +{ + return pthread_equal(thr0, thr1); +} diff --git a/src/threads/thrd_exit.c b/src/threads/thrd_exit.c new file mode 100644 index 00000000..4b393d06 --- /dev/null +++ b/src/threads/thrd_exit.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +_Noreturn void thrd_exit(int res) +{ + pthread_exit(&res); +} diff --git a/src/threads/thrd_join.c b/src/threads/thrd_join.c new file mode 100644 index 00000000..f85d7a71 --- /dev/null +++ b/src/threads/thrd_join.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int thrd_join(thrd_t thr, int *res) +{ + return pthread_join(thr, (void**)&res); +} diff --git a/src/threads/thrd_sleep.c b/src/threads/thrd_sleep.c new file mode 100644 index 00000000..49c5522c --- /dev/null +++ b/src/threads/thrd_sleep.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <time.h> + +int thrd_sleep(const struct timespec *duration, struct timespec *remaining) +{ + return nanosleep(duration, remaining); +} diff --git a/src/threads/thrd_start_t.c b/src/threads/thrd_start_t.c new file mode 100644 index 00000000..2dc640c8 --- /dev/null +++ b/src/threads/thrd_start_t.c @@ -0,0 +1 @@ +typedef int (*thrd_start_t)(void *); diff --git a/src/threads/thrd_t.c b/src/threads/thrd_t.c new file mode 100644 index 00000000..d996cd60 --- /dev/null +++ b/src/threads/thrd_t.c @@ -0,0 +1 @@ +typedef /* same as pthread_t */ thrd_t; diff --git a/src/threads/thrd_yield.c b/src/threads/thrd_yield.c new file mode 100644 index 00000000..5b969f4e --- /dev/null +++ b/src/threads/thrd_yield.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <sched.h> + +void thrd_yield(void) +{ + sched_yield(); +} diff --git a/src/threads/thread_local.c b/src/threads/thread_local.c new file mode 100644 index 00000000..b9250131 --- /dev/null +++ b/src/threads/thread_local.c @@ -0,0 +1 @@ +#define thread_local _Thread_local diff --git a/src/threads/tss_create.c b/src/threads/tss_create.c new file mode 100644 index 00000000..47b1d5d4 --- /dev/null +++ b/src/threads/tss_create.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int tss_create(tss_t *key, tss_dtor_t dtor) +{ + return pthread_key_create(key, dtor); +} diff --git a/src/threads/tss_delete.c b/src/threads/tss_delete.c new file mode 100644 index 00000000..b64f279d --- /dev/null +++ b/src/threads/tss_delete.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +void tss_delete(tss_t key) +{ + pthread_key_delete(key); +} diff --git a/src/threads/tss_dtor_t.c b/src/threads/tss_dtor_t.c new file mode 100644 index 00000000..f36e3298 --- /dev/null +++ b/src/threads/tss_dtor_t.c @@ -0,0 +1 @@ +typedef void (*tss_dtor_t)(void*); diff --git a/src/threads/tss_get.c b/src/threads/tss_get.c new file mode 100644 index 00000000..68484fbe --- /dev/null +++ b/src/threads/tss_get.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +void *tss_get(tss_t key) +{ + return pthread_getspecific(key); +} diff --git a/src/threads/tss_set.c b/src/threads/tss_set.c new file mode 100644 index 00000000..b9c39c75 --- /dev/null +++ b/src/threads/tss_set.c @@ -0,0 +1,7 @@ +#include <threads.h> +#include <pthread.h> + +int tss_set(tss_t key, void *val) +{ + return pthread_setspecific(key, val); +} diff --git a/src/threads/tss_t.c b/src/threads/tss_t.c new file mode 100644 index 00000000..8d7ea994 --- /dev/null +++ b/src/threads/tss_t.c @@ -0,0 +1 @@ +typedef /* same as pthread_key_t */ tss_t; |