18 #ifndef __STARPU_THREAD_UTIL_H__
19 #define __STARPU_THREAD_UTIL_H__
24 #if !(defined(_MSC_VER) && !defined(BUILDING_STARPU))
29 #define STARPU_PTHREAD_CREATE_ON(name, thread, attr, routine, arg, where) do { \
30 int p_ret = starpu_pthread_create_on((name), (thread), (attr), (routine), (arg), (where)); \
31 if (STARPU_UNLIKELY(p_ret != 0)) { \
33 "%s:%d starpu_pthread_create_on: %s\n", \
34 __FILE__, __LINE__, strerror(p_ret)); \
39 #define STARPU_PTHREAD_CREATE(thread, attr, routine, arg) do { \
40 int p_ret = starpu_pthread_create((thread), (attr), (routine), (arg)); \
41 if (STARPU_UNLIKELY(p_ret != 0)) { \
43 "%s:%d starpu_pthread_create: %s\n", \
44 __FILE__, __LINE__, strerror(p_ret)); \
53 #define STARPU_PTHREAD_MUTEX_INIT(mutex, attr) do { \
54 int p_ret = starpu_pthread_mutex_init((mutex), (attr)); \
55 if (STARPU_UNLIKELY(p_ret)) { \
57 "%s:%d starpu_pthread_mutex_init: %s\n", \
58 __FILE__, __LINE__, strerror(p_ret)); \
63 #define STARPU_PTHREAD_MUTEX_DESTROY(mutex) do { \
64 int p_ret = starpu_pthread_mutex_destroy(mutex); \
65 if (STARPU_UNLIKELY(p_ret)) { \
67 "%s:%d starpu_pthread_mutex_destroy: %s\n", \
68 __FILE__, __LINE__, strerror(p_ret)); \
73 #define STARPU_PTHREAD_MUTEX_LOCK(mutex) do { \
74 int p_ret = starpu_pthread_mutex_lock(mutex); \
75 if (STARPU_UNLIKELY(p_ret)) { \
77 "%s:%d starpu_pthread_mutex_lock: %s\n", \
78 __FILE__, __LINE__, strerror(p_ret)); \
83 #define STARPU_PTHREAD_MUTEX_TRYLOCK(mutex) \
84 _starpu_pthread_mutex_trylock(mutex, __FILE__, __LINE__)
86 int _starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex,
char *file,
int line)
91 "%s:%d starpu_pthread_mutex_trylock: %s\n",
92 file, line, strerror(p_ret));
98 #define STARPU_PTHREAD_MUTEX_UNLOCK(mutex) do { \
99 int p_ret = starpu_pthread_mutex_unlock(mutex); \
100 if (STARPU_UNLIKELY(p_ret)) { \
102 "%s:%d starpu_pthread_mutex_unlock: %s\n", \
103 __FILE__, __LINE__, strerror(p_ret)); \
111 #define STARPU_PTHREAD_KEY_CREATE(key, destr) do { \
112 int p_ret = starpu_pthread_key_create((key), (destr)); \
113 if (STARPU_UNLIKELY(p_ret != 0)) { \
115 "%s:%d starpu_pthread_key_create: %s\n", \
116 __FILE__, __LINE__, strerror(p_ret)); \
120 #define STARPU_PTHREAD_KEY_DELETE(key) do { \
121 int p_ret = starpu_pthread_key_delete((key)); \
122 if (STARPU_UNLIKELY(p_ret != 0)) { \
124 "%s:%d starpu_pthread_key_delete: %s\n", \
125 __FILE__, __LINE__, strerror(p_ret)); \
129 #define STARPU_PTHREAD_SETSPECIFIC(key, ptr) do { \
130 int p_ret = starpu_pthread_setspecific((key), (ptr)); \
131 if (STARPU_UNLIKELY(p_ret != 0)) { \
133 "%s:%d starpu_pthread_setspecific: %s\n", \
134 __FILE__, __LINE__, strerror(p_ret)); \
138 #define STARPU_PTHREAD_GETSPECIFIC(key) starpu_pthread_getspecific((key))
143 #define STARPU_PTHREAD_RWLOCK_INIT(rwlock, attr) do { \
144 int p_ret = starpu_pthread_rwlock_init((rwlock), (attr)); \
145 if (STARPU_UNLIKELY(p_ret)) { \
147 "%s:%d starpu_pthread_rwlock_init: %s\n", \
148 __FILE__, __LINE__, strerror(p_ret)); \
153 #define STARPU_PTHREAD_RWLOCK_RDLOCK(rwlock) do { \
154 int p_ret = starpu_pthread_rwlock_rdlock(rwlock); \
155 if (STARPU_UNLIKELY(p_ret)) { \
157 "%s:%d starpu_pthread_rwlock_rdlock: %s\n", \
158 __FILE__, __LINE__, strerror(p_ret)); \
163 #define STARPU_PTHREAD_RWLOCK_TRYRDLOCK(rwlock) \
164 _starpu_pthread_rwlock_tryrdlock(rwlock, __FILE__, __LINE__)
166 int _starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
168 int p_ret = starpu_pthread_rwlock_tryrdlock(rwlock);
171 "%s:%d starpu_pthread_rwlock_tryrdlock: %s\n",
172 file, line, strerror(p_ret));
178 #define STARPU_PTHREAD_RWLOCK_WRLOCK(rwlock) do { \
179 int p_ret = starpu_pthread_rwlock_wrlock(rwlock); \
180 if (STARPU_UNLIKELY(p_ret)) { \
182 "%s:%d starpu_pthread_rwlock_wrlock: %s\n", \
183 __FILE__, __LINE__, strerror(p_ret)); \
188 #define STARPU_PTHREAD_RWLOCK_TRYWRLOCK(rwlock) \
189 _starpu_pthread_rwlock_trywrlock(rwlock, __FILE__, __LINE__)
191 int _starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock,
char *file,
int line)
193 int p_ret = starpu_pthread_rwlock_trywrlock(rwlock);
196 "%s:%d starpu_pthread_rwlock_trywrlock: %s\n",
197 file, line, strerror(p_ret));
203 #define STARPU_PTHREAD_RWLOCK_UNLOCK(rwlock) do { \
204 int p_ret = starpu_pthread_rwlock_unlock(rwlock); \
205 if (STARPU_UNLIKELY(p_ret)) { \
207 "%s:%d starpu_pthread_rwlock_unlock: %s\n", \
208 __FILE__, __LINE__, strerror(p_ret)); \
213 #define STARPU_PTHREAD_RWLOCK_DESTROY(rwlock) do { \
214 int p_ret = starpu_pthread_rwlock_destroy(rwlock); \
215 if (STARPU_UNLIKELY(p_ret)) { \
217 "%s:%d starpu_pthread_rwlock_destroy: %s\n", \
218 __FILE__, __LINE__, strerror(p_ret)); \
226 #define STARPU_PTHREAD_COND_INIT(cond, attr) do { \
227 int p_ret = starpu_pthread_cond_init((cond), (attr)); \
228 if (STARPU_UNLIKELY(p_ret)) { \
230 "%s:%d starpu_pthread_cond_init: %s\n", \
231 __FILE__, __LINE__, strerror(p_ret)); \
236 #define STARPU_PTHREAD_COND_DESTROY(cond) do { \
237 int p_ret = starpu_pthread_cond_destroy(cond); \
238 if (STARPU_UNLIKELY(p_ret)) { \
240 "%s:%d starpu_pthread_cond_destroy: %s\n", \
241 __FILE__, __LINE__, strerror(p_ret)); \
246 #define STARPU_PTHREAD_COND_SIGNAL(cond) do { \
247 int p_ret = starpu_pthread_cond_signal(cond); \
248 if (STARPU_UNLIKELY(p_ret)) { \
250 "%s:%d starpu_pthread_cond_signal: %s\n", \
251 __FILE__, __LINE__, strerror(p_ret)); \
256 #define STARPU_PTHREAD_COND_BROADCAST(cond) do { \
257 int p_ret = starpu_pthread_cond_broadcast(cond); \
258 if (STARPU_UNLIKELY(p_ret)) { \
260 "%s:%d starpu_pthread_cond_broadcast: %s\n", \
261 __FILE__, __LINE__, strerror(p_ret)); \
266 #define STARPU_PTHREAD_COND_WAIT(cond, mutex) do { \
267 int p_ret = starpu_pthread_cond_wait((cond), (mutex)); \
268 if (STARPU_UNLIKELY(p_ret)) { \
270 "%s:%d starpu_pthread_cond_wait: %s\n", \
271 __FILE__, __LINE__, strerror(p_ret)); \
280 #define STARPU_PTHREAD_BARRIER_INIT(barrier, attr, count) do { \
281 int p_ret = starpu_pthread_barrier_init((barrier), (attr), (count)); \
282 if (STARPU_UNLIKELY(p_ret)) { \
284 "%s:%d starpu_pthread_barrier_init: %s\n", \
285 __FILE__, __LINE__, strerror(p_ret)); \
290 #define STARPU_PTHREAD_BARRIER_DESTROY(barrier) do { \
291 int p_ret = starpu_pthread_barrier_destroy((barrier)); \
292 if (STARPU_UNLIKELY(p_ret)) { \
294 "%s:%d starpu_pthread_barrier_destroy: %s\n", \
295 __FILE__, __LINE__, strerror(p_ret)); \
300 #define STARPU_PTHREAD_BARRIER_WAIT(barrier) do { \
301 int p_ret = starpu_pthread_barrier_wait((barrier)); \
302 if (STARPU_UNLIKELY(!((p_ret == 0) || (p_ret == STARPU_PTHREAD_BARRIER_SERIAL_THREAD)))) { \
304 "%s:%d starpu_pthread_barrier_wait: %s\n", \
305 __FILE__, __LINE__, strerror(p_ret)); \
int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)