diff options
| author | Brent Cook <busterb@gmail.com> | 2018-03-18 10:36:51 -0500 |
|---|---|---|
| committer | Brent Cook <busterb@gmail.com> | 2018-03-18 10:36:51 -0500 |
| commit | 0e46c1e8ba9eca009173d2dc0c3084b322088eaf (patch) | |
| tree | 62acb2883e04627956266dfdd0824fc69e051fc7 /include | |
| parent | 1b84f79f4cce8ece632e8f51fae6b842dcae00d8 (diff) | |
| download | portable-0e46c1e8ba9eca009173d2dc0c3084b322088eaf.tar.gz portable-0e46c1e8ba9eca009173d2dc0c3084b322088eaf.tar.bz2 portable-0e46c1e8ba9eca009173d2dc0c3084b322088eaf.zip | |
add pthread_self/pthread_equal for win32
Diffstat (limited to 'include')
| -rw-r--r-- | include/compat/pthread.h | 26 |
1 files 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 @@ | |||
| 18 | struct pthread_once { | 18 | struct pthread_once { |
| 19 | INIT_ONCE once; | 19 | INIT_ONCE once; |
| 20 | }; | 20 | }; |
| 21 | |||
| 22 | typedef struct pthread_once pthread_once_t; | 21 | typedef struct pthread_once pthread_once_t; |
| 23 | 22 | ||
| 24 | static BOOL CALLBACK _pthread_once_win32_cb(PINIT_ONCE once, PVOID param, PVOID *context) | 23 | static inline BOOL CALLBACK |
| 24 | _pthread_once_win32_cb(PINIT_ONCE once, PVOID param, PVOID *context) | ||
| 25 | { | 25 | { |
| 26 | void (*cb) (void) = param; | 26 | void (*cb) (void) = param; |
| 27 | cb(); | 27 | cb(); |
| 28 | return TRUE; | 28 | return TRUE; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | static int pthread_once(pthread_once_t *once, void (*cb) (void)) | 31 | static inline int |
| 32 | pthread_once(pthread_once_t *once, void (*cb) (void)) | ||
| 32 | { | 33 | { |
| 33 | BOOL rc = InitOnceExecuteOnce(&once->once, _pthread_once_win32_cb, cb, NULL); | 34 | BOOL rc = InitOnceExecuteOnce(&once->once, _pthread_once_win32_cb, cb, NULL); |
| 34 | if (rc == 0) | 35 | if (rc == 0) |
| @@ -37,6 +38,25 @@ static int pthread_once(pthread_once_t *once, void (*cb) (void)) | |||
| 37 | return 0; | 38 | return 0; |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 41 | struct pthread { | ||
| 42 | HANDLE handle; | ||
| 43 | }; | ||
| 44 | typedef struct pthread pthread_t; | ||
| 45 | |||
| 46 | static inline pthread_t | ||
| 47 | pthread_self(void) | ||
| 48 | { | ||
| 49 | pthread_t self; | ||
| 50 | self.handle = GetCurrentThread(); | ||
| 51 | return self; | ||
| 52 | } | ||
| 53 | |||
| 54 | static inline int | ||
| 55 | pthread_equal(pthread_t t1, pthread_t t2) | ||
| 56 | { | ||
| 57 | return t1.handle == t2.handle; | ||
| 58 | } | ||
| 59 | |||
| 40 | #else | 60 | #else |
| 41 | #include_next <pthread.h> | 61 | #include_next <pthread.h> |
| 42 | #endif | 62 | #endif |
