diff options
author | Cy Schubert <cy@FreeBSD.org> | 2023-11-14 23:02:42 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2023-11-14 23:02:42 +0000 |
commit | 5223d1d95fddcef6f9a36e264a5800bd907ade8b (patch) | |
tree | 818b1eba912c588e39058586485699385c3179fe /test/regress_thread.h | |
parent | cbc620a473ce23d882ba3e9f91ec0c6c12dcd239 (diff) |
Diffstat (limited to 'test/regress_thread.h')
-rw-r--r-- | test/regress_thread.h | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/test/regress_thread.h b/test/regress_thread.h index 831b51e50739..a954fefa5611 100644 --- a/test/regress_thread.h +++ b/test/regress_thread.h @@ -27,22 +27,30 @@ #ifndef REGRESS_THREAD_H_INCLUDED_ #define REGRESS_THREAD_H_INCLUDED_ -#ifdef EVENT__HAVE_PTHREADS +#if defined(_WIN32) /** _WIN32 */ +#define THREAD_T void * /* HANDLE */ +#define THREAD_FN unsigned __stdcall +#define THREAD_RETURN() return (0) +#define THREAD_SELF() GetCurrentThreadId() +#define THREAD_START(threadvar, fn, arg) do { \ + uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ + (threadvar) = (THREAD_T)threadhandle; \ + thread_setup(threadvar); \ +} while (0) +#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) +#else /* !_WIN32 */ +#include <pthread.h> #define THREAD_T pthread_t #define THREAD_FN void * #define THREAD_RETURN() return (NULL) -#define THREAD_START(threadvar, fn, arg) \ - pthread_create(&(threadvar), NULL, fn, arg) +#define THREAD_SELF() pthread_self() +#define THREAD_START(threadvar, fn, arg) do { \ + if (!pthread_create(&(threadvar), NULL, fn, arg)) \ + thread_setup(threadvar); \ +} while (0) #define THREAD_JOIN(th) pthread_join(th, NULL) -#else -#define THREAD_T HANDLE -#define THREAD_FN unsigned __stdcall -#define THREAD_RETURN() return (0) -#define THREAD_START(threadvar, fn, arg) do { \ - uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ - (threadvar) = (HANDLE) threadhandle; \ - } while (0) -#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) -#endif +#endif /* \!_WIN32 */ + +void thread_setup(THREAD_T pthread); #endif |