diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/kit/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/kit/threads.h | 10 | ||||
-rw-r--r-- | source/kit/threads.posix.c | 24 | ||||
-rw-r--r-- | source/kit/threads.win32.c | 38 | ||||
-rw-r--r-- | source/kit/threads.win32.h | 25 | ||||
-rw-r--r-- | source/kit/threads_tls_callback.win32.cpp | 21 | ||||
-rw-r--r-- | source/test/unittests/condition_variable.test.c | 2 |
7 files changed, 4 insertions, 119 deletions
diff --git a/source/kit/CMakeLists.txt b/source/kit/CMakeLists.txt index 86c39dc..b5fe0f6 100644 --- a/source/kit/CMakeLists.txt +++ b/source/kit/CMakeLists.txt @@ -4,7 +4,7 @@ target_sources( atomic.c input_buffer.c threads.win32.c time.c threads.posix.c input_stream.c lower_bound.c string_ref.c async_function.c allocator.c array_ref.c dynamic_array.c - mersenne_twister_64.c threads_tls_callback.win32.cpp + mersenne_twister_64.c PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/time.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/atomic.h> @@ -13,7 +13,6 @@ target_sources( $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/threads.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/dynamic_array.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/async_function.h> - $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/threads.win32.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/input_stream.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/input_buffer.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/lower_bound.h> diff --git a/source/kit/threads.h b/source/kit/threads.h index 197f34f..5cfb5d3 100644 --- a/source/kit/threads.h +++ b/source/kit/threads.h @@ -184,13 +184,9 @@ int thrd_equal(thrd_t, thrd_t); _Noreturn # endif void thrd_exit(int); -int thrd_join(thrd_t, int *); -int thrd_sleep(const struct timespec *, struct timespec *); -void thrd_yield(void); -int tss_create(tss_t *, tss_dtor_t); -void tss_delete(tss_t); -void *tss_get(tss_t); -int tss_set(tss_t, void *); +int thrd_join(thrd_t, int *); +int thrd_sleep(const struct timespec *, struct timespec *); +void thrd_yield(void); # ifdef __cplusplus } diff --git a/source/kit/threads.posix.c b/source/kit/threads.posix.c index c9a9094..efedbaa 100644 --- a/source/kit/threads.posix.c +++ b/source/kit/threads.posix.c @@ -318,29 +318,5 @@ void thrd_yield(void) { sched_yield(); } -/*----------- 7.25.6 Thread-specific storage functions -----------*/ -// 7.25.6.1 -int tss_create(tss_t *key, tss_dtor_t dtor) { - assert(key != NULL); - return (pthread_key_create(key, dtor) == 0) ? thrd_success - : thrd_error; -} - -// 7.25.6.2 -void tss_delete(tss_t key) { - pthread_key_delete(key); -} - -// 7.25.6.3 -void *tss_get(tss_t key) { - return pthread_getspecific(key); -} - -// 7.25.6.4 -int tss_set(tss_t key, void *val) { - return (pthread_setspecific(key, val) == 0) ? thrd_success - : thrd_error; -} - # endif #endif diff --git a/source/kit/threads.win32.c b/source/kit/threads.win32.c index b8ca7ae..4fe19b6 100644 --- a/source/kit/threads.win32.c +++ b/source/kit/threads.win32.c @@ -311,15 +311,6 @@ int mtx_unlock(mtx_t *mtx) { return thrd_success; } -void __threads_win32_tls_callback(void) { - struct thrd_state *state = &impl_current_thread; - impl_tss_dtor_invoke(); - if (state->handle_need_close) { - state->handle_need_close = false; - CloseHandle(state->thrd.handle); - } -} - /*------------------- 7.25.5 Thread functions -------------------*/ // 7.25.5.1 int thrd_create_with_stack(thrd_t *thr, thrd_start_t func, void *arg, @@ -440,34 +431,5 @@ void thrd_yield(void) { SwitchToThread(); } -/*----------- 7.25.6 Thread-specific storage functions -----------*/ -// 7.25.6.1 -int tss_create(tss_t *key, tss_dtor_t dtor) { - assert(key != NULL); - *key = TlsAlloc(); - if (dtor) { - if (impl_tss_dtor_register(*key, dtor)) { - TlsFree(*key); - return thrd_error; - } - } - return (*key != 0xFFFFFFFF) ? thrd_success : thrd_error; -} - -// 7.25.6.2 -void tss_delete(tss_t key) { - TlsFree(key); -} - -// 7.25.6.3 -void *tss_get(tss_t key) { - return TlsGetValue(key); -} - -// 7.25.6.4 -int tss_set(tss_t key, void *val) { - return TlsSetValue(key, val) ? thrd_success : thrd_error; -} - # endif #endif /* KIT_DISABLE_SYSTEM_THREADS */ diff --git a/source/kit/threads.win32.h b/source/kit/threads.win32.h deleted file mode 100644 index e8e9abf..0000000 --- a/source/kit/threads.win32.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2022 Yonggang Luo - * SPDX-License-Identifier: MIT - */ - -#ifndef KIT_THREADS_WIN32_H -#define KIT_THREADS_WIN32_H - -#ifndef KIT_DISABLE_SYSTEM_THREADS - -# ifdef __cplusplus -extern "C" { -# endif - -# if defined(_WIN32) && !defined(__CYGWIN__) -void __threads_win32_tls_callback(void); -# endif - -# ifdef __cplusplus -} -# endif - -#endif - -#endif diff --git a/source/kit/threads_tls_callback.win32.cpp b/source/kit/threads_tls_callback.win32.cpp deleted file mode 100644 index 3cc3cc6..0000000 --- a/source/kit/threads_tls_callback.win32.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2022 Yonggang Luo - * SPDX-License-Identifier: MIT - */ - -#ifndef KIT_DISABLE_SYSTEM_THREADS -# if defined(_WIN32) && !defined(__CYGWIN__) - -# include "threads.win32.h" - -struct tls_callback { - tls_callback() { } - ~tls_callback() { - __threads_win32_tls_callback(); - } -}; - -static thread_local tls_callback tls_callback_instance; - -# endif -#endif diff --git a/source/test/unittests/condition_variable.test.c b/source/test/unittests/condition_variable.test.c index b7fc7db..93389e9 100644 --- a/source/test/unittests/condition_variable.test.c +++ b/source/test/unittests/condition_variable.test.c @@ -3,8 +3,6 @@ #define KIT_TEST_FILE condition_variable #include "../../kit_test/test.h" -#include <stdio.h> - typedef struct { mtx_t m; int in; |