19 #ifndef __STARPU_THREAD_UTIL_H__ 20 #define __STARPU_THREAD_UTIL_H__ 25 #if !(defined(_MSC_VER) && !defined(BUILDING_STARPU)) 30 #define STARPU_PTHREAD_CREATE_ON(name, thread, attr, routine, arg, where) do { \ 31 int p_ret = starpu_pthread_create_on((name), (thread), (attr), (routine), (arg), (where)); \ 32 if (STARPU_UNLIKELY(p_ret != 0)) { \ 34 "%s:%d starpu_pthread_create_on: %s\n", \ 35 __FILE__, __LINE__, strerror(p_ret)); \ 40 #define STARPU_PTHREAD_CREATE(thread, attr, routine, arg) do { \ 41 int p_ret = starpu_pthread_create((thread), (attr), (routine), (arg)); \ 42 if (STARPU_UNLIKELY(p_ret != 0)) { \ 44 "%s:%d starpu_pthread_create: %s\n", \ 45 __FILE__, __LINE__, strerror(p_ret)); \ 54 #define STARPU_PTHREAD_MUTEX_INIT(mutex, attr) do { \ 55 int p_ret = starpu_pthread_mutex_init((mutex), (attr)); \ 56 if (STARPU_UNLIKELY(p_ret)) { \ 58 "%s:%d starpu_pthread_mutex_init: %s\n", \ 59 __FILE__, __LINE__, strerror(p_ret)); \ 64 #define STARPU_PTHREAD_MUTEX_DESTROY(mutex) do { \ 65 int p_ret = starpu_pthread_mutex_destroy(mutex); \ 66 if (STARPU_UNLIKELY(p_ret)) { \ 68 "%s:%d starpu_pthread_mutex_destroy: %s\n", \ 69 __FILE__, __LINE__, strerror(p_ret)); \ 75 #define _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line) \ 76 starpu_pthread_mutex_check_sched((mutex), file, line) 78 #define _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line) 81 #define STARPU_PTHREAD_MUTEX_LOCK(mutex) do { \ 82 int p_ret = starpu_pthread_mutex_lock(mutex); \ 83 if (STARPU_UNLIKELY(p_ret)) { \ 85 "%s:%d starpu_pthread_mutex_lock: %s\n", \ 86 __FILE__, __LINE__, strerror(p_ret)); \ 89 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, __FILE__, __LINE__); \ 92 #define STARPU_PTHREAD_MUTEX_LOCK_SCHED(mutex) do { \ 93 int p_ret = starpu_pthread_mutex_lock_sched(mutex); \ 94 if (STARPU_UNLIKELY(p_ret)) { \ 96 "%s:%d starpu_pthread_mutex_lock_sched: %s\n", \ 97 __FILE__, __LINE__, strerror(p_ret)); \ 102 #define STARPU_PTHREAD_MUTEX_TRYLOCK(mutex) \ 103 _starpu_pthread_mutex_trylock(mutex, __FILE__, __LINE__) 105 int _starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex,
char *file,
int line)
110 "%s:%d starpu_pthread_mutex_trylock: %s\n",
111 file, line, strerror(p_ret));
114 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, file, line);
118 #define STARPU_PTHREAD_MUTEX_TRYLOCK_SCHED(mutex) \ 119 _starpu_pthread_mutex_trylock_sched(mutex, __FILE__, __LINE__) 121 int _starpu_pthread_mutex_trylock_sched(starpu_pthread_mutex_t *mutex,
char *file,
int line)
123 int p_ret = starpu_pthread_mutex_trylock_sched(mutex);
126 "%s:%d starpu_pthread_mutex_trylock_sched: %s\n",
127 file, line, strerror(p_ret));
133 #define STARPU_PTHREAD_MUTEX_UNLOCK(mutex) do { \ 134 _STARPU_CHECK_NOT_SCHED_MUTEX(mutex, __FILE__, __LINE__); \ 135 int p_ret = starpu_pthread_mutex_unlock(mutex); \ 136 if (STARPU_UNLIKELY(p_ret)) { \ 138 "%s:%d starpu_pthread_mutex_unlock: %s\n", \ 139 __FILE__, __LINE__, strerror(p_ret)); \ 144 #define STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(mutex) do { \ 145 int p_ret = starpu_pthread_mutex_unlock_sched(mutex); \ 146 if (STARPU_UNLIKELY(p_ret)) { \ 148 "%s:%d starpu_pthread_mutex_unlock_sched: %s\n", \ 149 __FILE__, __LINE__, strerror(p_ret)); \ 157 #define STARPU_PTHREAD_KEY_CREATE(key, destr) do { \ 158 int p_ret = starpu_pthread_key_create((key), (destr)); \ 159 if (STARPU_UNLIKELY(p_ret != 0)) { \ 161 "%s:%d starpu_pthread_key_create: %s\n", \ 162 __FILE__, __LINE__, strerror(p_ret)); \ 166 #define STARPU_PTHREAD_KEY_DELETE(key) do { \ 167 int p_ret = starpu_pthread_key_delete((key)); \ 168 if (STARPU_UNLIKELY(p_ret != 0)) { \ 170 "%s:%d starpu_pthread_key_delete: %s\n", \ 171 __FILE__, __LINE__, strerror(p_ret)); \ 175 #define STARPU_PTHREAD_SETSPECIFIC(key, ptr) do { \ 176 int p_ret = starpu_pthread_setspecific((key), (ptr)); \ 177 if (STARPU_UNLIKELY(p_ret != 0)) { \ 179 "%s:%d starpu_pthread_setspecific: %s\n", \ 180 __FILE__, __LINE__, strerror(p_ret)); \ 184 #define STARPU_PTHREAD_GETSPECIFIC(key) starpu_pthread_getspecific((key)) 189 #define STARPU_PTHREAD_RWLOCK_INIT(rwlock, attr) do { \ 190 int p_ret = starpu_pthread_rwlock_init((rwlock), (attr)); \ 191 if (STARPU_UNLIKELY(p_ret)) { \ 193 "%s:%d starpu_pthread_rwlock_init: %s\n", \ 194 __FILE__, __LINE__, strerror(p_ret)); \ 199 #define STARPU_PTHREAD_RWLOCK_RDLOCK(rwlock) do { \ 200 int p_ret = starpu_pthread_rwlock_rdlock(rwlock); \ 201 if (STARPU_UNLIKELY(p_ret)) { \ 203 "%s:%d starpu_pthread_rwlock_rdlock: %s\n", \ 204 __FILE__, __LINE__, strerror(p_ret)); \ 209 #define STARPU_PTHREAD_RWLOCK_TRYRDLOCK(rwlock) \ 210 _starpu_pthread_rwlock_tryrdlock(rwlock, __FILE__, __LINE__) 212 int _starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
217 "%s:%d starpu_pthread_rwlock_tryrdlock: %s\n",
218 file, line, strerror(p_ret));
224 #define STARPU_PTHREAD_RWLOCK_WRLOCK(rwlock) do { \ 225 int p_ret = starpu_pthread_rwlock_wrlock(rwlock); \ 226 if (STARPU_UNLIKELY(p_ret)) { \ 228 "%s:%d starpu_pthread_rwlock_wrlock: %s\n", \ 229 __FILE__, __LINE__, strerror(p_ret)); \ 234 #define STARPU_PTHREAD_RWLOCK_TRYWRLOCK(rwlock) \ 235 _starpu_pthread_rwlock_trywrlock(rwlock, __FILE__, __LINE__) 237 int _starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
242 "%s:%d starpu_pthread_rwlock_trywrlock: %s\n",
243 file, line, strerror(p_ret));
249 #define STARPU_PTHREAD_RWLOCK_UNLOCK(rwlock) do { \ 250 int p_ret = starpu_pthread_rwlock_unlock(rwlock); \ 251 if (STARPU_UNLIKELY(p_ret)) { \ 253 "%s:%d starpu_pthread_rwlock_unlock: %s\n", \ 254 __FILE__, __LINE__, strerror(p_ret)); \ 259 #define STARPU_PTHREAD_RWLOCK_DESTROY(rwlock) do { \ 260 int p_ret = starpu_pthread_rwlock_destroy(rwlock); \ 261 if (STARPU_UNLIKELY(p_ret)) { \ 263 "%s:%d starpu_pthread_rwlock_destroy: %s\n", \ 264 __FILE__, __LINE__, strerror(p_ret)); \ 272 #define STARPU_PTHREAD_COND_INIT(cond, attr) do { \ 273 int p_ret = starpu_pthread_cond_init((cond), (attr)); \ 274 if (STARPU_UNLIKELY(p_ret)) { \ 276 "%s:%d starpu_pthread_cond_init: %s\n", \ 277 __FILE__, __LINE__, strerror(p_ret)); \ 282 #define STARPU_PTHREAD_COND_DESTROY(cond) do { \ 283 int p_ret = starpu_pthread_cond_destroy(cond); \ 284 if (STARPU_UNLIKELY(p_ret)) { \ 286 "%s:%d starpu_pthread_cond_destroy: %s\n", \ 287 __FILE__, __LINE__, strerror(p_ret)); \ 292 #define STARPU_PTHREAD_COND_SIGNAL(cond) do { \ 293 int p_ret = starpu_pthread_cond_signal(cond); \ 294 if (STARPU_UNLIKELY(p_ret)) { \ 296 "%s:%d starpu_pthread_cond_signal: %s\n", \ 297 __FILE__, __LINE__, strerror(p_ret)); \ 302 #define STARPU_PTHREAD_COND_BROADCAST(cond) do { \ 303 int p_ret = starpu_pthread_cond_broadcast(cond); \ 304 if (STARPU_UNLIKELY(p_ret)) { \ 306 "%s:%d starpu_pthread_cond_broadcast: %s\n", \ 307 __FILE__, __LINE__, strerror(p_ret)); \ 312 #define STARPU_PTHREAD_COND_WAIT(cond, mutex) do { \ 313 int p_ret = starpu_pthread_cond_wait((cond), (mutex)); \ 314 if (STARPU_UNLIKELY(p_ret)) { \ 316 "%s:%d starpu_pthread_cond_wait: %s\n", \ 317 __FILE__, __LINE__, strerror(p_ret)); \ 326 #define STARPU_PTHREAD_BARRIER_INIT(barrier, attr, count) do { \ 327 int p_ret = starpu_pthread_barrier_init((barrier), (attr), (count)); \ 328 if (STARPU_UNLIKELY(p_ret)) { \ 330 "%s:%d starpu_pthread_barrier_init: %s\n", \ 331 __FILE__, __LINE__, strerror(p_ret)); \ 336 #define STARPU_PTHREAD_BARRIER_DESTROY(barrier) do { \ 337 int p_ret = starpu_pthread_barrier_destroy((barrier)); \ 338 if (STARPU_UNLIKELY(p_ret)) { \ 340 "%s:%d starpu_pthread_barrier_destroy: %s\n", \ 341 __FILE__, __LINE__, strerror(p_ret)); \ 346 #define STARPU_PTHREAD_BARRIER_WAIT(barrier) do { \ 347 int p_ret = starpu_pthread_barrier_wait((barrier)); \ 348 if (STARPU_UNLIKELY(!((p_ret == 0) || (p_ret == STARPU_PTHREAD_BARRIER_SERIAL_THREAD)))) { \ 350 "%s:%d starpu_pthread_barrier_wait: %s\n", \ 351 __FILE__, __LINE__, strerror(p_ret)); \
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)