diff options
author | David Robillard <d@drobilla.net> | 2012-02-01 01:40:05 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-02-01 01:40:05 +0000 |
commit | 5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf (patch) | |
tree | 6b2d088aef4ed5099fbbc140c594a0ee1b7e67fa /zix/thread.h | |
parent | dc7628a8eec281add045eb123ae06dbc94c1b950 (diff) | |
download | zix-5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf.tar.gz zix-5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf.tar.bz2 zix-5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf.zip |
Windows portability fixes.
git-svn-id: http://svn.drobilla.net/zix/trunk@58 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
Diffstat (limited to 'zix/thread.h')
-rw-r--r-- | zix/thread.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/zix/thread.h b/zix/thread.h index b1fcf97..ff5a727 100644 --- a/zix/thread.h +++ b/zix/thread.h @@ -17,8 +17,12 @@ #ifndef ZIX_THREAD_H #define ZIX_THREAD_H -#include <errno.h> -#include <pthread.h> +#ifdef _WIN32 +# include <windows.h> +#else +# include <errno.h> +# include <pthread.h> +#endif #include "zix/common.h" @@ -35,7 +39,11 @@ extern "C" { @{ */ +#ifdef _WIN32 +typedef HANDLE ZixThread; +#else typedef pthread_t ZixThread; +#endif /** Initialize @c thread to a new thread. @@ -55,6 +63,29 @@ zix_thread_create(ZixThread* thread, static inline ZixStatus zix_thread_join(ZixThread thread, void** retval); +#ifdef _WIN32 + +static inline ZixStatus +zix_thread_create(ZixThread* thread, + size_t stack_size, + 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; +} + +static inline ZixStatus +zix_thread_join(ZixThread thread, void** retval) +{ + return WaitForSingleObject(thread, INFINITE) + ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR; +} + +#else /* !defined(_WIN32) */ + static inline ZixStatus zix_thread_create(ZixThread* thread, size_t stack_size, @@ -88,6 +119,8 @@ zix_thread_join(ZixThread thread, void** retval) ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS; } +#endif + /** @} @} |