| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef __PTHREAD_SHIM_H |
| 9 |
#define __PTHREAD_SHIM_H |
| 10 |
|
| 11 |
#include "common/attributes.h" |
| 12 |
#include "config.h" |
| 13 |
|
| 14 |
#ifdef _WIN32 |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 |
| 20 |
# undef _WIN32_WINNT |
| 21 |
# define _WIN32_WINNT 0x0600 |
| 22 |
#endif |
| 23 |
# include <stdbool.h> |
| 24 |
# include <stdint.h> |
| 25 |
#include <winsock2.h> |
| 26 |
#define _WINSOCKAPI_ |
| 27 |
# include <windows.h> |
| 28 |
#if HAVE_PTHREADS |
| 29 |
#include <pthread.h> |
| 30 |
# define PTHREAD_START_FUNC(fname,aname) void *fname(void *aname) |
| 31 |
typedef void *(*pthread_start_func_t)(void *aname); |
| 32 |
RIST_PRIV int pthread_cond_timedwait_ms(pthread_cond_t *cond, pthread_mutex_t *mutex, uint32_t ms); |
| 33 |
#else |
| 34 |
typedef CRITICAL_SECTION pthread_mutex_t; |
| 35 |
typedef void pthread_mutexattr_t; |
| 36 |
typedef void pthread_condattr_t; |
| 37 |
typedef void pthread_rwlockattr_t; |
| 38 |
typedef HANDLE pthread_t; |
| 39 |
typedef int pthread_attr_t; |
| 40 |
typedef CONDITION_VARIABLE pthread_cond_t; |
| 41 |
typedef LPVOID thread_arg_t; |
| 42 |
typedef DWORD thread_return_t; |
| 43 |
|
| 44 |
typedef struct { |
| 45 |
SRWLOCK lock; |
| 46 |
bool exclusive; |
| 47 |
} pthread_rwlock_t; |
| 48 |
|
| 49 |
# define PTHREAD_START_FUNC(fname,aname) DWORD __stdcall fname(LPVOID aname) |
| 50 |
typedef DWORD (__stdcall *pthread_start_func_t)(LPVOID aname); |
| 51 |
RIST_PRIV int init_mutex_once(pthread_mutex_t *mutex, PINIT_ONCE once_var); |
| 52 |
|
| 53 |
RIST_PRIV int pthread_create(pthread_t *thread, pthread_attr_t *attr, DWORD (__stdcall *start_routine)(LPVOID), void *arg); |
| 54 |
RIST_PRIV int pthread_join(pthread_t thread, void **value_ptr); |
| 55 |
RIST_PRIV int pthread_detach(pthread_t); |
| 56 |
|
| 57 |
RIST_PRIV int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr); |
| 58 |
RIST_PRIV int pthread_mutex_destroy(pthread_mutex_t *mutex); |
| 59 |
RIST_PRIV int pthread_mutex_lock(pthread_mutex_t *mutex); |
| 60 |
RIST_PRIV int pthread_mutex_unlock(pthread_mutex_t *mutex); |
| 61 |
|
| 62 |
RIST_PRIV int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr); |
| 63 |
RIST_PRIV int pthread_cond_destroy(pthread_cond_t *cond); |
| 64 |
RIST_PRIV int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); |
| 65 |
RIST_PRIV int pthread_cond_timedwait_ms(pthread_cond_t *cond, pthread_mutex_t *mutex, uint32_t reltime_ms); |
| 66 |
|
| 67 |
RIST_PRIV int pthread_cond_signal(pthread_cond_t *cond); |
| 68 |
RIST_PRIV int pthread_cond_broadcast(pthread_cond_t *cond); |
| 69 |
|
| 70 |
RIST_PRIV int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); |
| 71 |
RIST_PRIV int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); |
| 72 |
RIST_PRIV int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); |
| 73 |
RIST_PRIV int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); |
| 74 |
RIST_PRIV int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); |
| 75 |
RIST_PRIV int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); |
| 76 |
RIST_PRIV int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); |
| 77 |
|
| 78 |
|
| 79 |
typedef HANDLE sem_t; |
| 80 |
RIST_PRIV int sem_init(sem_t *sem, int pshared, unsigned value); |
| 81 |
RIST_PRIV int sem_post(sem_t *sem); |
| 82 |
RIST_PRIV int sem_wait(sem_t *sem); |
| 83 |
#endif |
| 84 |
#else |
| 85 |
# include <pthread.h> |
| 86 |
# include <sys/types.h> |
| 87 |
# include <semaphore.h> |
| 88 |
# include <stdint.h> |
| 89 |
# define PTHREAD_START_FUNC(fname,aname) void *fname(void *aname) |
| 90 |
typedef void *(*pthread_start_func_t)(void *aname); |
| 91 |
RIST_PRIV int pthread_cond_timedwait_ms(pthread_cond_t *cond, pthread_mutex_t *mutex, uint32_t ms); |
| 92 |
#endif |
| 93 |
|
| 94 |
#endif |