diff options
Diffstat (limited to 'xthread.h')
-rw-r--r-- | xthread.h | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -29,6 +29,7 @@ typedef int ssize_t; #include <windows.h> #include <pthread.h> #define sigset_t int +#define sigfillset(a) #define pthread_sigmask(a,b,c) #define sigaddset(a,b) #define sigemptyset(s) @@ -36,11 +37,13 @@ typedef int ssize_t; typedef pthread_mutex_t xmutex_t; #define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER +#define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0) #define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) #define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) typedef pthread_cond_t xcond_t; #define X_COND_INIT PTHREAD_COND_INITIALIZER +#define X_COND_CREATE(cond) pthread_cond_init (&(cond), 0) #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) @@ -95,18 +98,27 @@ thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) typedef pthread_mutex_t xmutex_t; #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) -# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP +# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP +# define X_MUTEX_CREATE(mutex) \ + do { \ + pthread_mutexattr_t attr; \ + pthread_mutexattr_init (&attr); \ + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP); \ + pthread_mutex_init (&(mutex), &attr); \ + } while (0) #else -# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER +# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER +# define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0) #endif -#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) -#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) +#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) +#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) typedef pthread_cond_t xcond_t; -#define X_COND_INIT PTHREAD_COND_INITIALIZER -#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) -#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) -#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) +#define X_COND_INIT PTHREAD_COND_INITIALIZER +#define X_COND_CREATE(cond) pthread_cond_init (&(cond), 0) +#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) +#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) +#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) typedef pthread_t xthread_t; #define X_THREAD_PROC(name) static void *name (void *thr_arg) |