From e883ea50dd1154294e21e946e391dd38e04d6527 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 23 Oct 2022 12:55:40 -0400 Subject: 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. --- src/posix/thread_posix.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/posix/thread_posix.c (limited to 'src/posix/thread_posix.c') diff --git a/src/posix/thread_posix.c b/src/posix/thread_posix.c new file mode 100644 index 0000000..2073448 --- /dev/null +++ b/src/posix/thread_posix.c @@ -0,0 +1,34 @@ +// Copyright 2012-2020 David Robillard +// SPDX-License-Identifier: ISC + +#include "zix/thread.h" + +#include "../errno_status.h" + +#include "zix/status.h" + +#include + +#include + +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; +} -- cgit v1.2.1