88 #define THREAD_T pthread_t
89 #define THREAD_ATTR_T pthread_attr_t
91 #define THREAD_ATTR_INIT(attr) pthread_attr_init(&attr)
92 #define THREAD_JOIN(tid) pthread_join(tid, (void**)NULL)
93 #define THREAD_CREATE(tid, attr, fn, arg) pthread_create(&(tid), \
95 (void* (*)(void*))(fn), \
98 #define THREAD_LOCAL_T pthread_key_t
99 #define THREAD_LOCAL_INIT(key) pthread_key_create(&key, NULL)
100 #define THREAD_LOCAL_SET(key, val) pthread_setspecific(key, (void*)(val))
101 #define THREAD_LOCAL_GET(key) pthread_getspecific(key)
103 #define THREAD_MUTEX_T pthread_mutex_t
104 #define THREAD_MUTEX_INIT(lock) pthread_mutex_init(&(lock), NULL)
105 #define THREAD_MUTEX_LOCK(lock) pthread_mutex_lock(&(lock))
106 #define THREAD_MUTEX_UNLOCK(lock) pthread_mutex_unlock(&(lock))
108 #define THREAD_COND_T pthread_cond_t
109 #define THREAD_COND_INIT(cond) pthread_cond_init(&(cond), NULL)
110 #define THREAD_COND_SIGNAL(cond) pthread_cond_signal(&(cond))
111 #define THREAD_COND_BROADCAST(cond) pthread_cond_broadcast(&(cond))
112 #define THREAD_COND_WAIT(cond, lock) pthread_cond_wait(&(cond), &(lock))
115 # define THREAD_BARRIER_T pthread_barrier_t
116 # define THREAD_BARRIER_ALLOC(N) ((THREAD_BARRIER_T*)malloc(sizeof(THREAD_BARRIER_T)))
117 # define THREAD_BARRIER_INIT(bar, N) pthread_barrier_init(bar, 0, N)
118 # define THREAD_BARRIER(bar, tid) pthread_barrier_wait(bar)
119 # define THREAD_BARRIER_FREE(bar) free(bar)
123 # define THREAD_BARRIER_T thread_barrier_t
124 # define THREAD_BARRIER_ALLOC(N) thread_barrier_alloc(N)
125 # define THREAD_BARRIER_INIT(bar, N) thread_barrier_init(bar)
126 # define THREAD_BARRIER(bar, tid) thread_barrier(bar, tid)
127 # define THREAD_BARRIER_FREE(bar) thread_barrier_free(bar)
129 # define THREAD_BARRIER_T barrier_t
130 # define THREAD_BARRIER_ALLOC(N) barrier_alloc()
131 # define THREAD_BARRIER_INIT(bar, N) barrier_init(bar, N)
132 # define THREAD_BARRIER(bar, tid) barrier_cross(bar)
133 # define THREAD_BARRIER_FREE(bar) barrier_free(bar)
140 typedef struct thread_barrier {
199 thread_barrier_alloc (
long numThreads);
207 thread_barrier_free (thread_barrier_t* barrierPtr);
215 thread_barrier_init (thread_barrier_t* barrierPtr);
224 thread_barrier (thread_barrier_t* barrierPtr,
long threadId);
void thread_startup(long numThread)
Definition: thread.c:121
#define THREAD_MUTEX_T
Definition: thread.h:103
void barrier_cross(barrier_t *b)
Definition: thread.c:343
void thread_shutdown()
Definition: library.hpp:199
Definition: barrier.hpp:28
long thread_getId()
Definition: thread.c:382
long thread_getNumThread()
Definition: thread.c:394
void thread_barrier_wait()
Definition: thread.c:367
void thread_start(void(*funcPtr)(void *), void *argPtr)
Definition: thread.c:171
void barrier_init(barrier_t *b, int n)
Definition: thread.c:336
void barrier_free(barrier_t *b)
Definition: thread.c:332
#define THREAD_COND_T
Definition: thread.h:108
barrier_t * barrier_alloc()
Definition: thread.c:328
volatile unsigned long count
Definition: queues.cpp:53