diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-31 22:02:42 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-31 22:02:42 +0200 |
commit | 41cb2efe1bceb9eef88f0010358b7712c1ad7c59 (patch) | |
tree | 2824923804841d87a66be4e6398a4bd89921b524 /src/threads | |
parent | 0ff770d78ea31b332bde745404e29db71ab8d18c (diff) | |
download | wolfbones-41cb2efe1bceb9eef88f0010358b7712c1ad7c59.tar.gz wolfbones-41cb2efe1bceb9eef88f0010358b7712c1ad7c59.tar.bz2 |
fixed threading on native Windows
Diffstat (limited to 'src/threads')
-rw-r--r-- | src/threads/threads.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/threads/threads.c b/src/threads/threads.c index 79cf4ba..0c99697 100644 --- a/src/threads/threads.c +++ b/src/threads/threads.c @@ -66,4 +66,44 @@ wolf_error_t wolf_thread_join( wolf_thread_t *thread ) { #if defined _WIN32 +#include <errno.h> /* for errno and EXXX values */ + +wolf_error_t wolf_thread_create( wolf_thread_t *thread, wolf_thread_func_t func ) { + /* _beginthread doesn't signal termination. Unusable!, + * CreateThread is for DLLs and surpasses CRT code, not good, + * so we use _beginthreadex (this must be adapted if somebody + * wants to write a DLL with these functions.. (see also POCO) + */ + *thread = _beginthreadex( NULL, 0, func, NULL, 0, NULL ); + if( thread < 0 ) { + switch( errno ) { + case EINVAL: + return WOLF_ERR_INVALID_VALUE; + + default: + return WOLF_ERR_INTERNAL; + } + } + + return WOLF_OK; +} + +wolf_error_t wolf_thread_join( wolf_thread_t *thread ) { + DWORD res; + + res = WaitForSingleObject( (HANDLE)(*thread), INFINITE ); + switch( res ) { + case WAIT_OBJECT_0: + /* the handle is neither cleaned up by the thread + * exit code nor the _endthreadex function, so + * we do it here! + */ + CloseHandle( (HANDLE)(*thread) ); + return WOLF_OK; + + default: + return WOLF_ERR_INTERNAL; + } +} + #endif /* defined _WIN32 */ |