21 #ifndef __STARPU_THREAD_UTIL_H__ 22 #define __STARPU_THREAD_UTIL_H__ 28 #if !(defined(_MSC_VER) && !defined(BUILDING_STARPU)) 33 #define STARPU_PTHREAD_CREATE_ON(name, thread, attr, routine, arg, where) do { \ 34 int p_ret = starpu_pthread_create_on((name), (thread), (attr), (routine), (arg), (where)); \ 35 if (STARPU_UNLIKELY(p_ret != 0)) { \ 37 "%s:%d starpu_pthread_create_on: %s\n", \ 38 __FILE__, __LINE__, strerror(p_ret)); \ 43 #define STARPU_PTHREAD_CREATE(thread, attr, routine, arg) do { \ 44 int p_ret = starpu_pthread_create((thread), (attr), (routine), (arg)); \ 45 if (STARPU_UNLIKELY(p_ret != 0)) { \ 47 "%s:%d starpu_pthread_create: %s\n", \ 48 __FILE__, __LINE__, strerror(p_ret)); \ 53 #define STARPU_PTHREAD_JOIN(thread, retval) do { \ 54 int p_ret = starpu_pthread_join((thread), (retval)); \ 55 if (STARPU_UNLIKELY(p_ret != 0)) { \ 57 "%s:%d starpu_pthread_join: %s\n", \ 58 __FILE__, __LINE__, strerror(p_ret)); \ 67 #define STARPU_PTHREAD_MUTEX_INIT(mutex, attr) do { \ 68 int p_ret = starpu_pthread_mutex_init((mutex), (attr)); \ 69 if (STARPU_UNLIKELY(p_ret)) { \ 71 "%s:%d starpu_pthread_mutex_init: %s\n", \ 72 __FILE__, __LINE__, strerror(p_ret)); \ 77 #define STARPU_PTHREAD_MUTEX_DESTROY(mutex) do { \ 78 int p_ret = starpu_pthread_mutex_destroy(mutex); \ 79 if (STARPU_UNLIKELY(p_ret)) { \ 81 "%s:%d starpu_pthread_mutex_destroy: %s\n", \ 82 __FILE__, __LINE__, strerror(p_ret)); \ 88 #define _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line) \ 89 starpu_pthread_mutex_check_sched((mutex), file, line) 91 #define _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line) 94 #define STARPU_PTHREAD_MUTEX_LOCK(mutex) do { \ 95 int p_ret = starpu_pthread_mutex_lock(mutex); \ 96 if (STARPU_UNLIKELY(p_ret)) { \ 98 "%s:%d starpu_pthread_mutex_lock: %s\n", \ 99 __FILE__, __LINE__, strerror(p_ret)); \ 102 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, __FILE__, __LINE__); \ 105 #define STARPU_PTHREAD_MUTEX_LOCK_SCHED(mutex) do { \ 106 int p_ret = starpu_pthread_mutex_lock_sched(mutex); \ 107 if (STARPU_UNLIKELY(p_ret)) { \ 109 "%s:%d starpu_pthread_mutex_lock_sched: %s\n", \ 110 __FILE__, __LINE__, strerror(p_ret)); \ 115 #define STARPU_PTHREAD_MUTEX_TRYLOCK(mutex) \ 116 _starpu_pthread_mutex_trylock(mutex, __FILE__, __LINE__) 118 int _starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex,
char *file,
int line)
123 "%s:%d starpu_pthread_mutex_trylock: %s\n",
124 file, line, strerror(p_ret));
127 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line);
131 #define STARPU_PTHREAD_MUTEX_TRYLOCK_SCHED(mutex) \ 132 _starpu_pthread_mutex_trylock_sched(mutex, __FILE__, __LINE__) 134 int _starpu_pthread_mutex_trylock_sched(starpu_pthread_mutex_t *mutex,
char *file,
int line)
136 int p_ret = starpu_pthread_mutex_trylock_sched(mutex);
139 "%s:%d starpu_pthread_mutex_trylock_sched: %s\n",
140 file, line, strerror(p_ret));
146 #define STARPU_PTHREAD_MUTEX_UNLOCK(mutex) do { \ 147 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, __FILE__, __LINE__); \ 148 int p_ret = starpu_pthread_mutex_unlock(mutex); \ 149 if (STARPU_UNLIKELY(p_ret)) { \ 151 "%s:%d starpu_pthread_mutex_unlock: %s\n", \ 152 __FILE__, __LINE__, strerror(p_ret)); \ 157 #define STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(mutex) do { \ 158 int p_ret = starpu_pthread_mutex_unlock_sched(mutex); \ 159 if (STARPU_UNLIKELY(p_ret)) { \ 161 "%s:%d starpu_pthread_mutex_unlock_sched: %s\n", \ 162 __FILE__, __LINE__, strerror(p_ret)); \ 170 #define STARPU_PTHREAD_KEY_CREATE(key, destr) do { \ 171 int p_ret = starpu_pthread_key_create((key), (destr)); \ 172 if (STARPU_UNLIKELY(p_ret != 0)) { \ 174 "%s:%d starpu_pthread_key_create: %s\n", \ 175 __FILE__, __LINE__, strerror(p_ret)); \ 179 #define STARPU_PTHREAD_KEY_DELETE(key) do { \ 180 int p_ret = starpu_pthread_key_delete((key)); \ 181 if (STARPU_UNLIKELY(p_ret != 0)) { \ 183 "%s:%d starpu_pthread_key_delete: %s\n", \ 184 __FILE__, __LINE__, strerror(p_ret)); \ 188 #define STARPU_PTHREAD_SETSPECIFIC(key, ptr) do { \ 189 int p_ret = starpu_pthread_setspecific((key), (ptr)); \ 190 if (STARPU_UNLIKELY(p_ret != 0)) { \ 192 "%s:%d starpu_pthread_setspecific: %s\n", \ 193 __FILE__, __LINE__, strerror(p_ret)); \ 197 #define STARPU_PTHREAD_GETSPECIFIC(key) starpu_pthread_getspecific((key)) 202 #define STARPU_PTHREAD_RWLOCK_INIT(rwlock, attr) do { \ 203 int p_ret = starpu_pthread_rwlock_init((rwlock), (attr)); \ 204 if (STARPU_UNLIKELY(p_ret)) { \ 206 "%s:%d starpu_pthread_rwlock_init: %s\n", \ 207 __FILE__, __LINE__, strerror(p_ret)); \ 212 #define STARPU_PTHREAD_RWLOCK_RDLOCK(rwlock) do { \ 213 int p_ret = starpu_pthread_rwlock_rdlock(rwlock); \ 214 if (STARPU_UNLIKELY(p_ret)) { \ 216 "%s:%d starpu_pthread_rwlock_rdlock: %s\n", \ 217 __FILE__, __LINE__, strerror(p_ret)); \ 222 #define STARPU_PTHREAD_RWLOCK_TRYRDLOCK(rwlock) \ 223 _starpu_pthread_rwlock_tryrdlock(rwlock, __FILE__, __LINE__) 225 int _starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
230 "%s:%d starpu_pthread_rwlock_tryrdlock: %s\n",
231 file, line, strerror(p_ret));
237 #define STARPU_PTHREAD_RWLOCK_WRLOCK(rwlock) do { \ 238 int p_ret = starpu_pthread_rwlock_wrlock(rwlock); \ 239 if (STARPU_UNLIKELY(p_ret)) { \ 241 "%s:%d starpu_pthread_rwlock_wrlock: %s\n", \ 242 __FILE__, __LINE__, strerror(p_ret)); \ 247 #define STARPU_PTHREAD_RWLOCK_TRYWRLOCK(rwlock) \ 248 _starpu_pthread_rwlock_trywrlock(rwlock, __FILE__, __LINE__) 250 int _starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
255 "%s:%d starpu_pthread_rwlock_trywrlock: %s\n",
256 file, line, strerror(p_ret));
262 #define STARPU_PTHREAD_RWLOCK_UNLOCK(rwlock) do { \ 263 int p_ret = starpu_pthread_rwlock_unlock(rwlock); \ 264 if (STARPU_UNLIKELY(p_ret)) { \ 266 "%s:%d starpu_pthread_rwlock_unlock: %s\n", \ 267 __FILE__, __LINE__, strerror(p_ret)); \ 272 #define STARPU_PTHREAD_RWLOCK_DESTROY(rwlock) do { \ 273 int p_ret = starpu_pthread_rwlock_destroy(rwlock); \ 274 if (STARPU_UNLIKELY(p_ret)) { \ 276 "%s:%d starpu_pthread_rwlock_destroy: %s\n", \ 277 __FILE__, __LINE__, strerror(p_ret)); \ 285 #define STARPU_PTHREAD_COND_INIT(cond, attr) do { \ 286 int p_ret = starpu_pthread_cond_init((cond), (attr)); \ 287 if (STARPU_UNLIKELY(p_ret)) { \ 289 "%s:%d starpu_pthread_cond_init: %s\n", \ 290 __FILE__, __LINE__, strerror(p_ret)); \ 295 #define STARPU_PTHREAD_COND_DESTROY(cond) do { \ 296 int p_ret = starpu_pthread_cond_destroy(cond); \ 297 if (STARPU_UNLIKELY(p_ret)) { \ 299 "%s:%d starpu_pthread_cond_destroy: %s\n", \ 300 __FILE__, __LINE__, strerror(p_ret)); \ 305 #define STARPU_PTHREAD_COND_SIGNAL(cond) do { \ 306 int p_ret = starpu_pthread_cond_signal(cond); \ 307 if (STARPU_UNLIKELY(p_ret)) { \ 309 "%s:%d starpu_pthread_cond_signal: %s\n", \ 310 __FILE__, __LINE__, strerror(p_ret)); \ 315 #define STARPU_PTHREAD_COND_BROADCAST(cond) do { \ 316 int p_ret = starpu_pthread_cond_broadcast(cond); \ 317 if (STARPU_UNLIKELY(p_ret)) { \ 319 "%s:%d starpu_pthread_cond_broadcast: %s\n", \ 320 __FILE__, __LINE__, strerror(p_ret)); \ 325 #define STARPU_PTHREAD_COND_WAIT(cond, mutex) do { \ 326 int p_ret = starpu_pthread_cond_wait((cond), (mutex)); \ 327 if (STARPU_UNLIKELY(p_ret)) { \ 329 "%s:%d starpu_pthread_cond_wait: %s\n", \ 330 __FILE__, __LINE__, strerror(p_ret)); \ 336 #ifdef STARPU_SIMGRID 337 #define STARPU_PTHREAD_COND_TIMEDWAIT(cond, mutex, abstime) \ 338 _starpu_pthread_cond_timedwait(cond, mutex, abstime, __FILE__, __LINE__) 340 int _starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex,
const struct timespec *abstime,
char *file,
int line)
345 "%s:%d starpu_pthread_cond_timedwait: %s\n",
346 file, line, strerror(p_ret));
357 #define STARPU_PTHREAD_BARRIER_INIT(barrier, attr, count) do { \ 358 int p_ret = starpu_pthread_barrier_init((barrier), (attr), (count)); \ 359 if (STARPU_UNLIKELY(p_ret)) { \ 361 "%s:%d starpu_pthread_barrier_init: %s\n", \ 362 __FILE__, __LINE__, strerror(p_ret)); \ 367 #define STARPU_PTHREAD_BARRIER_DESTROY(barrier) do { \ 368 int p_ret = starpu_pthread_barrier_destroy((barrier)); \ 369 if (STARPU_UNLIKELY(p_ret)) { \ 371 "%s:%d starpu_pthread_barrier_destroy: %s\n", \ 372 __FILE__, __LINE__, strerror(p_ret)); \ 377 #define STARPU_PTHREAD_BARRIER_WAIT(barrier) do { \ 378 int p_ret = starpu_pthread_barrier_wait((barrier)); \ 379 if (STARPU_UNLIKELY(!((p_ret == 0) || (p_ret == STARPU_PTHREAD_BARRIER_SERIAL_THREAD)))) { \ 381 "%s:%d starpu_pthread_barrier_wait: %s\n", \ 382 __FILE__, __LINE__, strerror(p_ret)); \
int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime)
int starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock)
int starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock)
int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)