19 #ifndef __STARPU_THREAD_UTIL_H__
20 #define __STARPU_THREAD_UTIL_H__
26 #if !(defined(_MSC_VER) && !defined(BUILDING_STARPU))
31 #define STARPU_PTHREAD_CREATE_ON(name, thread, attr, routine, arg, where) do { \
32 int p_ret = starpu_pthread_create_on((name), (thread), (attr), (routine), (arg), (where)); \
33 if (STARPU_UNLIKELY(p_ret != 0)) { \
35 "%s:%d starpu_pthread_create_on: %s\n", \
36 __FILE__, __LINE__, strerror(p_ret)); \
41 #define STARPU_PTHREAD_CREATE(thread, attr, routine, arg) do { \
42 int p_ret = starpu_pthread_create((thread), (attr), (routine), (arg)); \
43 if (STARPU_UNLIKELY(p_ret != 0)) { \
45 "%s:%d starpu_pthread_create: %s\n", \
46 __FILE__, __LINE__, strerror(p_ret)); \
51 #define STARPU_PTHREAD_JOIN(thread, retval) do { \
52 int p_ret = starpu_pthread_join((thread), (retval)); \
53 if (STARPU_UNLIKELY(p_ret != 0)) { \
55 "%s:%d starpu_pthread_join: %s\n", \
56 __FILE__, __LINE__, strerror(p_ret)); \
65 #define STARPU_PTHREAD_MUTEX_INIT(mutex, attr) do { \
66 int p_ret = starpu_pthread_mutex_init((mutex), (attr)); \
67 if (STARPU_UNLIKELY(p_ret)) { \
69 "%s:%d starpu_pthread_mutex_init: %s\n", \
70 __FILE__, __LINE__, strerror(p_ret)); \
75 #define STARPU_PTHREAD_MUTEX_DESTROY(mutex) do { \
76 int p_ret = starpu_pthread_mutex_destroy(mutex); \
77 if (STARPU_UNLIKELY(p_ret)) { \
79 "%s:%d starpu_pthread_mutex_destroy: %s\n", \
80 __FILE__, __LINE__, strerror(p_ret)); \
86 #define _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line) \
87 starpu_pthread_mutex_check_sched((mutex), file, line)
89 #define _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line)
92 #define STARPU_PTHREAD_MUTEX_LOCK(mutex) do { \
93 int p_ret = starpu_pthread_mutex_lock(mutex); \
94 if (STARPU_UNLIKELY(p_ret)) { \
96 "%s:%d starpu_pthread_mutex_lock: %s\n", \
97 __FILE__, __LINE__, strerror(p_ret)); \
100 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, __FILE__, __LINE__); \
103 #define STARPU_PTHREAD_MUTEX_LOCK_SCHED(mutex) do { \
104 int p_ret = starpu_pthread_mutex_lock_sched(mutex); \
105 if (STARPU_UNLIKELY(p_ret)) { \
107 "%s:%d starpu_pthread_mutex_lock_sched: %s\n", \
108 __FILE__, __LINE__, strerror(p_ret)); \
113 #define STARPU_PTHREAD_MUTEX_TRYLOCK(mutex) \
114 _starpu_pthread_mutex_trylock(mutex, __FILE__, __LINE__)
116 int _starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex,
char *file,
int line)
121 "%s:%d starpu_pthread_mutex_trylock: %s\n",
122 file, line, strerror(p_ret));
125 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line);
129 #define STARPU_PTHREAD_MUTEX_TRYLOCK_SCHED(mutex) \
130 _starpu_pthread_mutex_trylock_sched(mutex, __FILE__, __LINE__)
132 int _starpu_pthread_mutex_trylock_sched(starpu_pthread_mutex_t *mutex,
char *file,
int line)
134 int p_ret = starpu_pthread_mutex_trylock_sched(mutex);
137 "%s:%d starpu_pthread_mutex_trylock_sched: %s\n",
138 file, line, strerror(p_ret));
144 #define STARPU_PTHREAD_MUTEX_UNLOCK(mutex) do { \
145 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, __FILE__, __LINE__); \
146 int p_ret = starpu_pthread_mutex_unlock(mutex); \
147 if (STARPU_UNLIKELY(p_ret)) { \
149 "%s:%d starpu_pthread_mutex_unlock: %s\n", \
150 __FILE__, __LINE__, strerror(p_ret)); \
155 #define STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(mutex) do { \
156 int p_ret = starpu_pthread_mutex_unlock_sched(mutex); \
157 if (STARPU_UNLIKELY(p_ret)) { \
159 "%s:%d starpu_pthread_mutex_unlock_sched: %s\n", \
160 __FILE__, __LINE__, strerror(p_ret)); \
168 #define STARPU_PTHREAD_KEY_CREATE(key, destr) do { \
169 int p_ret = starpu_pthread_key_create((key), (destr)); \
170 if (STARPU_UNLIKELY(p_ret != 0)) { \
172 "%s:%d starpu_pthread_key_create: %s\n", \
173 __FILE__, __LINE__, strerror(p_ret)); \
177 #define STARPU_PTHREAD_KEY_DELETE(key) do { \
178 int p_ret = starpu_pthread_key_delete((key)); \
179 if (STARPU_UNLIKELY(p_ret != 0)) { \
181 "%s:%d starpu_pthread_key_delete: %s\n", \
182 __FILE__, __LINE__, strerror(p_ret)); \
186 #define STARPU_PTHREAD_SETSPECIFIC(key, ptr) do { \
187 int p_ret = starpu_pthread_setspecific((key), (ptr)); \
188 if (STARPU_UNLIKELY(p_ret != 0)) { \
190 "%s:%d starpu_pthread_setspecific: %s\n", \
191 __FILE__, __LINE__, strerror(p_ret)); \
195 #define STARPU_PTHREAD_GETSPECIFIC(key) starpu_pthread_getspecific((key))
200 #define STARPU_PTHREAD_RWLOCK_INIT(rwlock, attr) do { \
201 int p_ret = starpu_pthread_rwlock_init((rwlock), (attr)); \
202 if (STARPU_UNLIKELY(p_ret)) { \
204 "%s:%d starpu_pthread_rwlock_init: %s\n", \
205 __FILE__, __LINE__, strerror(p_ret)); \
210 #define STARPU_PTHREAD_RWLOCK_RDLOCK(rwlock) do { \
211 int p_ret = starpu_pthread_rwlock_rdlock(rwlock); \
212 if (STARPU_UNLIKELY(p_ret)) { \
214 "%s:%d starpu_pthread_rwlock_rdlock: %s\n", \
215 __FILE__, __LINE__, strerror(p_ret)); \
220 #define STARPU_PTHREAD_RWLOCK_TRYRDLOCK(rwlock) \
221 _starpu_pthread_rwlock_tryrdlock(rwlock, __FILE__, __LINE__)
223 int _starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
228 "%s:%d starpu_pthread_rwlock_tryrdlock: %s\n",
229 file, line, strerror(p_ret));
235 #define STARPU_PTHREAD_RWLOCK_WRLOCK(rwlock) do { \
236 int p_ret = starpu_pthread_rwlock_wrlock(rwlock); \
237 if (STARPU_UNLIKELY(p_ret)) { \
239 "%s:%d starpu_pthread_rwlock_wrlock: %s\n", \
240 __FILE__, __LINE__, strerror(p_ret)); \
245 #define STARPU_PTHREAD_RWLOCK_TRYWRLOCK(rwlock) \
246 _starpu_pthread_rwlock_trywrlock(rwlock, __FILE__, __LINE__)
248 int _starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
253 "%s:%d starpu_pthread_rwlock_trywrlock: %s\n",
254 file, line, strerror(p_ret));
260 #define STARPU_PTHREAD_RWLOCK_UNLOCK(rwlock) do { \
261 int p_ret = starpu_pthread_rwlock_unlock(rwlock); \
262 if (STARPU_UNLIKELY(p_ret)) { \
264 "%s:%d starpu_pthread_rwlock_unlock: %s\n", \
265 __FILE__, __LINE__, strerror(p_ret)); \
270 #define STARPU_PTHREAD_RWLOCK_DESTROY(rwlock) do { \
271 int p_ret = starpu_pthread_rwlock_destroy(rwlock); \
272 if (STARPU_UNLIKELY(p_ret)) { \
274 "%s:%d starpu_pthread_rwlock_destroy: %s\n", \
275 __FILE__, __LINE__, strerror(p_ret)); \
283 #define STARPU_PTHREAD_COND_INIT(cond, attr) do { \
284 int p_ret = starpu_pthread_cond_init((cond), (attr)); \
285 if (STARPU_UNLIKELY(p_ret)) { \
287 "%s:%d starpu_pthread_cond_init: %s\n", \
288 __FILE__, __LINE__, strerror(p_ret)); \
293 #define STARPU_PTHREAD_COND_DESTROY(cond) do { \
294 int p_ret = starpu_pthread_cond_destroy(cond); \
295 if (STARPU_UNLIKELY(p_ret)) { \
297 "%s:%d starpu_pthread_cond_destroy: %s\n", \
298 __FILE__, __LINE__, strerror(p_ret)); \
303 #define STARPU_PTHREAD_COND_SIGNAL(cond) do { \
304 int p_ret = starpu_pthread_cond_signal(cond); \
305 if (STARPU_UNLIKELY(p_ret)) { \
307 "%s:%d starpu_pthread_cond_signal: %s\n", \
308 __FILE__, __LINE__, strerror(p_ret)); \
313 #define STARPU_PTHREAD_COND_BROADCAST(cond) do { \
314 int p_ret = starpu_pthread_cond_broadcast(cond); \
315 if (STARPU_UNLIKELY(p_ret)) { \
317 "%s:%d starpu_pthread_cond_broadcast: %s\n", \
318 __FILE__, __LINE__, strerror(p_ret)); \
323 #define STARPU_PTHREAD_COND_WAIT(cond, mutex) do { \
324 int p_ret = starpu_pthread_cond_wait((cond), (mutex)); \
325 if (STARPU_UNLIKELY(p_ret)) { \
327 "%s:%d starpu_pthread_cond_wait: %s\n", \
328 __FILE__, __LINE__, strerror(p_ret)); \
334 #ifdef STARPU_SIMGRID
335 #define STARPU_PTHREAD_COND_TIMEDWAIT(cond, mutex, abstime) \
336 _starpu_pthread_cond_timedwait(cond, mutex, abstime, __FILE__, __LINE__)
338 int _starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex,
const struct timespec *abstime,
char *file,
int line)
343 "%s:%d starpu_pthread_cond_timedwait: %s\n",
344 file, line, strerror(p_ret));
355 #define STARPU_PTHREAD_BARRIER_INIT(barrier, attr, count) do { \
356 int p_ret = starpu_pthread_barrier_init((barrier), (attr), (count)); \
357 if (STARPU_UNLIKELY(p_ret)) { \
359 "%s:%d starpu_pthread_barrier_init: %s\n", \
360 __FILE__, __LINE__, strerror(p_ret)); \
365 #define STARPU_PTHREAD_BARRIER_DESTROY(barrier) do { \
366 int p_ret = starpu_pthread_barrier_destroy((barrier)); \
367 if (STARPU_UNLIKELY(p_ret)) { \
369 "%s:%d starpu_pthread_barrier_destroy: %s\n", \
370 __FILE__, __LINE__, strerror(p_ret)); \
375 #define STARPU_PTHREAD_BARRIER_WAIT(barrier) do { \
376 int p_ret = starpu_pthread_barrier_wait((barrier)); \
377 if (STARPU_UNLIKELY(!((p_ret == 0) || (p_ret == STARPU_PTHREAD_BARRIER_SERIAL_THREAD)))) { \
379 "%s:%d starpu_pthread_barrier_wait: %s\n", \
380 __FILE__, __LINE__, strerror(p_ret)); \
int starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock)
int starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock)
int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)
int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime)