From 0e46c1e8ba9eca009173d2dc0c3084b322088eaf Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sun, 18 Mar 2018 10:36:51 -0500 Subject: [PATCH] add pthread_self/pthread_equal for win32 --- include/compat/pthread.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/include/compat/pthread.h b/include/compat/pthread.h index 19eea13..b2db760 100644 --- a/include/compat/pthread.h +++ b/include/compat/pthread.h @@ -18,17 +18,18 @@ struct pthread_once { INIT_ONCE once; }; - typedef struct pthread_once pthread_once_t; -static BOOL CALLBACK _pthread_once_win32_cb(PINIT_ONCE once, PVOID param, PVOID *context) +static inline BOOL CALLBACK +_pthread_once_win32_cb(PINIT_ONCE once, PVOID param, PVOID *context) { void (*cb) (void) = param; cb(); return TRUE; } -static int pthread_once(pthread_once_t *once, void (*cb) (void)) +static inline int +pthread_once(pthread_once_t *once, void (*cb) (void)) { BOOL rc = InitOnceExecuteOnce(&once->once, _pthread_once_win32_cb, cb, NULL); if (rc == 0) @@ -37,6 +38,25 @@ static int pthread_once(pthread_once_t *once, void (*cb) (void)) return 0; } +struct pthread { + HANDLE handle; +}; +typedef struct pthread pthread_t; + +static inline pthread_t +pthread_self(void) +{ + pthread_t self; + self.handle = GetCurrentThread(); + return self; +} + +static inline int +pthread_equal(pthread_t t1, pthread_t t2) +{ + return t1.handle == t2.handle; +} + #else #include_next #endif