aboutsummaryrefslogtreecommitdiffstats
path: root/src/zix/thread.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-01-16 19:35:21 +0100
committerDavid Robillard <d@drobilla.net>2021-01-16 19:35:21 +0100
commit8952dde02d9d6761ae0cae033600f4a220c8e075 (patch)
tree5715888d4322daea9d29fc2f174d2a623d6085eb /src/zix/thread.h
parent9ab6e66c6ea7230f716b74d62c03fc5d19f56abe (diff)
downloadjalv-8952dde02d9d6761ae0cae033600f4a220c8e075.tar.gz
jalv-8952dde02d9d6761ae0cae033600f4a220c8e075.tar.bz2
jalv-8952dde02d9d6761ae0cae033600f4a220c8e075.zip
Update zix
Diffstat (limited to 'src/zix/thread.h')
-rw-r--r--src/zix/thread.h73
1 files changed, 37 insertions, 36 deletions
diff --git a/src/zix/thread.h b/src/zix/thread.h
index dbfdf36..77eeb1b 100644
--- a/src/zix/thread.h
+++ b/src/zix/thread.h
@@ -1,5 +1,5 @@
/*
- Copyright 2012-2014 David Robillard <d@drobilla.net>
+ Copyright 2012-2020 David Robillard <d@drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -20,10 +20,10 @@
#include "zix/common.h"
#ifdef _WIN32
-# include <windows.h>
+# include <windows.h>
#else
-# include <errno.h>
-# include <pthread.h>
+# include <errno.h>
+# include <pthread.h>
#endif
#include <stddef.h>
@@ -54,8 +54,8 @@ typedef pthread_t ZixThread;
static inline ZixStatus
zix_thread_create(ZixThread* thread,
size_t stack_size,
- void* (*function)(void*),
- void* arg);
+ void* (*function)(void*),
+ void* arg);
/**
Join `thread` (block until `thread` exits).
@@ -68,53 +68,54 @@ zix_thread_join(ZixThread thread, void** retval);
static inline ZixStatus
zix_thread_create(ZixThread* thread,
size_t stack_size,
- void* (*function)(void*),
- void* arg)
+ void* (*function)(void*),
+ void* arg)
{
- *thread = CreateThread(NULL, stack_size,
- (LPTHREAD_START_ROUTINE)function, arg,
- 0, NULL);
- return *thread ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR;
+ *thread = CreateThread(
+ NULL, stack_size, (LPTHREAD_START_ROUTINE)function, arg, 0, NULL);
+ return *thread ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR;
}
static inline ZixStatus
zix_thread_join(ZixThread thread, void** retval)
{
- (void)retval;
+ (void)retval;
- return WaitForSingleObject(thread, INFINITE)
- ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR;
+ return WaitForSingleObject(thread, INFINITE) ? ZIX_STATUS_SUCCESS
+ : ZIX_STATUS_ERROR;
}
-#else /* !defined(_WIN32) */
+#else /* !defined(_WIN32) */
static inline ZixStatus
zix_thread_create(ZixThread* thread,
size_t stack_size,
- void* (*function)(void*),
- void* arg)
+ void* (*function)(void*),
+ 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);
-
- switch (ret) {
- case EAGAIN: return ZIX_STATUS_NO_MEM;
- case EINVAL: return ZIX_STATUS_BAD_ARG;
- case EPERM: return ZIX_STATUS_BAD_PERMS;
- }
-
- return ret ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
+ 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);
+
+ switch (ret) {
+ case EAGAIN:
+ return ZIX_STATUS_NO_MEM;
+ case EINVAL:
+ return ZIX_STATUS_BAD_ARG;
+ case EPERM:
+ return ZIX_STATUS_BAD_PERMS;
+ }
+
+ return ret ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
}
static inline ZixStatus
zix_thread_join(ZixThread thread, void** retval)
{
- return pthread_join(thread, retval)
- ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
+ return pthread_join(thread, retval) ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
}
#endif
@@ -125,7 +126,7 @@ zix_thread_join(ZixThread thread, void** retval)
*/
#ifdef __cplusplus
-} /* extern "C" */
+} /* extern "C" */
#endif
-#endif /* ZIX_THREAD_H */
+#endif /* ZIX_THREAD_H */