From 82e8594087c93c84f27ad4508520db82289bb8fe Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 30 Jan 2024 15:33:21 -0500 Subject: update standards and safety checks --- src/threads/call_once.c | 1 + src/threads/cnd_broadcast.c | 1 + src/threads/cnd_destroy.c | 1 + src/threads/cnd_init.c | 1 + src/threads/cnd_signal.c | 1 + src/threads/cnd_timedwait.c | 1 + src/threads/cnd_wait.c | 1 + src/threads/mtx_destroy.c | 1 + src/threads/mtx_init.c | 1 + src/threads/mtx_lock.c | 1 + src/threads/mtx_timedlock.c | 1 + src/threads/mtx_trylock.c | 1 + src/threads/mtx_unlock.c | 1 + src/threads/once_flag.c | 10 ---------- src/threads/once_flag.h | 10 ++++++++++ src/threads/thrd_create.c | 1 + src/threads/thrd_current.c | 1 + src/threads/thrd_detach.c | 1 + src/threads/thrd_equal.c | 1 + src/threads/thrd_exit.c | 1 + src/threads/thrd_join.c | 1 + src/threads/thrd_sleep.c | 1 + src/threads/thrd_yield.c | 1 + src/threads/thread_local.c | 10 ---------- src/threads/thread_local.h | 10 ++++++++++ src/threads/tss_create.c | 1 + src/threads/tss_delete.c | 1 + src/threads/tss_get.c | 1 + src/threads/tss_set.c | 1 + 29 files changed, 45 insertions(+), 20 deletions(-) delete mode 100644 src/threads/once_flag.c create mode 100644 src/threads/once_flag.h delete mode 100644 src/threads/thread_local.c create mode 100644 src/threads/thread_local.h (limited to 'src') diff --git a/src/threads/call_once.c b/src/threads/call_once.c index a4418b85..c09886ec 100644 --- a/src/threads/call_once.c +++ b/src/threads/call_once.c @@ -5,6 +5,7 @@ void call_once(once_flag *flag, void (*func)(void)) { + SIGNAL_SAFE(0); pthread_once(flag, func); } diff --git a/src/threads/cnd_broadcast.c b/src/threads/cnd_broadcast.c index 75fb529c..58a6a199 100644 --- a/src/threads/cnd_broadcast.c +++ b/src/threads/cnd_broadcast.c @@ -5,6 +5,7 @@ int cnd_broadcast(cnd_t *cond) { + SIGNAL_SAFE(0); return pthread_cond_broadcast(cond) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/cnd_destroy.c b/src/threads/cnd_destroy.c index 9153cab4..07cee092 100644 --- a/src/threads/cnd_destroy.c +++ b/src/threads/cnd_destroy.c @@ -5,6 +5,7 @@ void cnd_destroy(cnd_t *cond) { + SIGNAL_SAFE(0); pthread_cond_destroy(cond); } diff --git a/src/threads/cnd_init.c b/src/threads/cnd_init.c index de1fda24..e44abe21 100644 --- a/src/threads/cnd_init.c +++ b/src/threads/cnd_init.c @@ -6,6 +6,7 @@ int cnd_init(cnd_t *cond) { + SIGNAL_SAFE(0); switch (pthread_cond_init(cond, 0)) { case 0: return thrd_success; diff --git a/src/threads/cnd_signal.c b/src/threads/cnd_signal.c index a23cd969..5d22c656 100644 --- a/src/threads/cnd_signal.c +++ b/src/threads/cnd_signal.c @@ -5,6 +5,7 @@ int cnd_signal(cnd_t *cond) { + SIGNAL_SAFE(0); 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 0086f2c0..5758183e 100644 --- a/src/threads/cnd_timedwait.c +++ b/src/threads/cnd_timedwait.c @@ -6,6 +6,7 @@ int cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx, const struct timespec *restrict ts) { + SIGNAL_SAFE(0); switch (pthread_cond_timedwait(cond, mtx, ts)) { case 0: return thrd_success; diff --git a/src/threads/cnd_wait.c b/src/threads/cnd_wait.c index 213b94ac..577ffa5f 100644 --- a/src/threads/cnd_wait.c +++ b/src/threads/cnd_wait.c @@ -5,6 +5,7 @@ int cnd_wait(cnd_t *cond, mtx_t *mtx) { + SIGNAL_SAFE(0); return pthread_cond_wait(cond, mtx) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/mtx_destroy.c b/src/threads/mtx_destroy.c index 4d8a54ce..93a8e0f5 100644 --- a/src/threads/mtx_destroy.c +++ b/src/threads/mtx_destroy.c @@ -5,6 +5,7 @@ void mtx_destroy(mtx_t *mtx) { + SIGNAL_SAFE(0); pthread_mutex_destroy(mtx); } diff --git a/src/threads/mtx_init.c b/src/threads/mtx_init.c index dbe58812..56e5196a 100644 --- a/src/threads/mtx_init.c +++ b/src/threads/mtx_init.c @@ -6,6 +6,7 @@ int mtx_init(mtx_t *mtx, int type) { + SIGNAL_SAFE(0); pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); if (type & mtx_recursive) { diff --git a/src/threads/mtx_lock.c b/src/threads/mtx_lock.c index fe1dfeb0..da97db79 100644 --- a/src/threads/mtx_lock.c +++ b/src/threads/mtx_lock.c @@ -5,6 +5,7 @@ int mtx_lock(mtx_t *mtx) { + SIGNAL_SAFE(0); return pthread_mutex_lock(mtx); } diff --git a/src/threads/mtx_timedlock.c b/src/threads/mtx_timedlock.c index 77054eec..f0681abf 100644 --- a/src/threads/mtx_timedlock.c +++ b/src/threads/mtx_timedlock.c @@ -6,6 +6,7 @@ int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts) { + SIGNAL_SAFE(0); switch (pthread_mutex_timedlock(mtx, ts)) { case 0: return thrd_success; diff --git a/src/threads/mtx_trylock.c b/src/threads/mtx_trylock.c index c11f8db5..2188c934 100644 --- a/src/threads/mtx_trylock.c +++ b/src/threads/mtx_trylock.c @@ -6,6 +6,7 @@ int mtx_trylock(mtx_t *mtx) { + SIGNAL_SAFE(0); switch (pthread_mutex_trylock(mtx)) { case 0: return thrd_success; diff --git a/src/threads/mtx_unlock.c b/src/threads/mtx_unlock.c index e7fa8f30..0b2b5fec 100644 --- a/src/threads/mtx_unlock.c +++ b/src/threads/mtx_unlock.c @@ -5,6 +5,7 @@ int mtx_unlock(mtx_t *mtx) { + SIGNAL_SAFE(0); return pthread_mutex_unlock(mtx) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/once_flag.c b/src/threads/once_flag.c deleted file mode 100644 index 7fee57a4..00000000 --- a/src/threads/once_flag.c +++ /dev/null @@ -1,10 +0,0 @@ -#if 0 - -typedef /* same as pthread_once_t */ once_flag; - -/* -STDC(201112) -*/ - - -#endif diff --git a/src/threads/once_flag.h b/src/threads/once_flag.h new file mode 100644 index 00000000..7fee57a4 --- /dev/null +++ b/src/threads/once_flag.h @@ -0,0 +1,10 @@ +#if 0 + +typedef /* same as pthread_once_t */ once_flag; + +/* +STDC(201112) +*/ + + +#endif diff --git a/src/threads/thrd_create.c b/src/threads/thrd_create.c index 7e1a1552..e09bf682 100644 --- a/src/threads/thrd_create.c +++ b/src/threads/thrd_create.c @@ -6,6 +6,7 @@ int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { + SIGNAL_SAFE(0); typedef void *(*pthread_start_fn)(void*); switch (pthread_create(thr, 0, (pthread_start_fn)func, arg)) { case 0: diff --git a/src/threads/thrd_current.c b/src/threads/thrd_current.c index 92e3d3f3..7562a95a 100644 --- a/src/threads/thrd_current.c +++ b/src/threads/thrd_current.c @@ -5,6 +5,7 @@ thrd_t thrd_current(void) { + SIGNAL_SAFE(0); return pthread_self(); } diff --git a/src/threads/thrd_detach.c b/src/threads/thrd_detach.c index 3aa1ee29..03ccb774 100644 --- a/src/threads/thrd_detach.c +++ b/src/threads/thrd_detach.c @@ -5,6 +5,7 @@ int thrd_detach(thrd_t thr) { + SIGNAL_SAFE(0); return pthread_detach(thr) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/thrd_equal.c b/src/threads/thrd_equal.c index 0bf5fc0b..cf2a64b1 100644 --- a/src/threads/thrd_equal.c +++ b/src/threads/thrd_equal.c @@ -5,6 +5,7 @@ int thrd_equal(thrd_t thr0, thrd_t thr1) { + SIGNAL_SAFE(0); return pthread_equal(thr0, thr1); } diff --git a/src/threads/thrd_exit.c b/src/threads/thrd_exit.c index 1258bbf7..117b63c2 100644 --- a/src/threads/thrd_exit.c +++ b/src/threads/thrd_exit.c @@ -5,6 +5,7 @@ _Noreturn void thrd_exit(int res) { + SIGNAL_SAFE(0); pthread_exit(&res); } diff --git a/src/threads/thrd_join.c b/src/threads/thrd_join.c index 588062f5..24001f60 100644 --- a/src/threads/thrd_join.c +++ b/src/threads/thrd_join.c @@ -5,6 +5,7 @@ int thrd_join(thrd_t thr, int *res) { + SIGNAL_SAFE(0); return pthread_join(thr, (void**)&res) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/thrd_sleep.c b/src/threads/thrd_sleep.c index d4b78d9d..7347d02c 100644 --- a/src/threads/thrd_sleep.c +++ b/src/threads/thrd_sleep.c @@ -5,6 +5,7 @@ int thrd_sleep(const struct timespec *duration, struct timespec *remaining) { + SIGNAL_SAFE(0); return nanosleep(duration, remaining); } diff --git a/src/threads/thrd_yield.c b/src/threads/thrd_yield.c index 0d2595ce..b6bc0f93 100644 --- a/src/threads/thrd_yield.c +++ b/src/threads/thrd_yield.c @@ -5,6 +5,7 @@ void thrd_yield(void) { + SIGNAL_SAFE(0); sched_yield(); } diff --git a/src/threads/thread_local.c b/src/threads/thread_local.c deleted file mode 100644 index 8014592b..00000000 --- a/src/threads/thread_local.c +++ /dev/null @@ -1,10 +0,0 @@ -#if 0 - -#define thread_local _Thread_local - -/* -STDC(201112) -*/ - - -#endif diff --git a/src/threads/thread_local.h b/src/threads/thread_local.h new file mode 100644 index 00000000..8014592b --- /dev/null +++ b/src/threads/thread_local.h @@ -0,0 +1,10 @@ +#if 0 + +#define thread_local _Thread_local + +/* +STDC(201112) +*/ + + +#endif diff --git a/src/threads/tss_create.c b/src/threads/tss_create.c index ff30995b..71a6e68a 100644 --- a/src/threads/tss_create.c +++ b/src/threads/tss_create.c @@ -5,6 +5,7 @@ int tss_create(tss_t *key, tss_dtor_t dtor) { + SIGNAL_SAFE(0); return pthread_key_create(key, dtor) == 0 ? thrd_success : thrd_error; } diff --git a/src/threads/tss_delete.c b/src/threads/tss_delete.c index eb527fd2..a76c47aa 100644 --- a/src/threads/tss_delete.c +++ b/src/threads/tss_delete.c @@ -5,6 +5,7 @@ void tss_delete(tss_t key) { + SIGNAL_SAFE(0); pthread_key_delete(key); } diff --git a/src/threads/tss_get.c b/src/threads/tss_get.c index 56e1c7ba..03c96419 100644 --- a/src/threads/tss_get.c +++ b/src/threads/tss_get.c @@ -5,6 +5,7 @@ void *tss_get(tss_t key) { + SIGNAL_SAFE(0); return pthread_getspecific(key); } diff --git a/src/threads/tss_set.c b/src/threads/tss_set.c index 17e8187a..0e0a7b3c 100644 --- a/src/threads/tss_set.c +++ b/src/threads/tss_set.c @@ -5,6 +5,7 @@ int tss_set(tss_t key, void *val) { + SIGNAL_SAFE(0); return pthread_setspecific(key, val) == 0 ? thrd_success : thrd_error; } -- cgit v1.2.1