diff options
author | David Robillard <d@drobilla.net> | 2022-10-23 12:55:40 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-10-23 13:26:00 -0400 |
commit | e883ea50dd1154294e21e946e391dd38e04d6527 (patch) | |
tree | 2019aecf50e1eb2f73a2aaf567d0f4573d9efc31 /src/thread.c | |
parent | 07b1289cd4907aa3defe3fc600f3db1dcefcb719 (diff) | |
download | zix-e883ea50dd1154294e21e946e391dd38e04d6527.tar.gz zix-e883ea50dd1154294e21e946e391dd38e04d6527.tar.bz2 zix-e883ea50dd1154294e21e946e391dd38e04d6527.zip |
Split up platform sources
This puts more onus on the build system to do things properly, but it's still
easy enough to build, even manually: all the files in the appropriate system
subdirectory just need to be included in the build.
Otherwise, the several nested levels of preprocessor conditionals get
confusing, and clang-format doesn't format code properly.
Diffstat (limited to 'src/thread.c')
-rw-r--r-- | src/thread.c | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/src/thread.c b/src/thread.c deleted file mode 100644 index 9b8af20..0000000 --- a/src/thread.c +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2012-2020 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -#include "zix/thread.h" - -#include "errno_status.h" - -#include "zix/status.h" - -#ifdef _WIN32 -# include <windows.h> -#else -# include <pthread.h> -#endif - -#include <stddef.h> - -#ifdef _WIN32 - -ZixStatus -zix_thread_create(ZixThread* thread, - size_t stack_size, - ZixThreadFunc function, - void* arg) -{ - *thread = CreateThread(NULL, stack_size, function, arg, 0, NULL); - return *thread ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR; -} - -ZixStatus -zix_thread_join(ZixThread thread) -{ - return (WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0) - ? ZIX_STATUS_SUCCESS - : ZIX_STATUS_ERROR; -} - -#else // !defined(_WIN32) - -ZixStatus -zix_thread_create(ZixThread* thread, - size_t stack_size, - ZixThreadFunc function, - void* arg) -{ - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, stack_size); - - const int ret = pthread_create(thread, NULL, function, arg); - - pthread_attr_destroy(&attr); - return zix_errno_status(ret); -} - -ZixStatus -zix_thread_join(ZixThread thread) -{ - return pthread_join(thread, NULL) ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS; -} - -#endif |