- if (sthread_inside_simgrid)
- return raw_pthread_create(thread, attr, start_routine, arg);
-
- sthread_disable();
- int res = sthread_create((sthread_t*)thread, attr, start_routine, arg);
- sthread_enable();
- return res;
-}
-int pthread_join(pthread_t thread, void** retval)
-{
- if (raw_pthread_join == NULL)
- intercepter_init();
- if (sthread_inside_simgrid)
- return raw_pthread_join(thread, retval);
-
- sthread_disable();
- int res = sthread_join((sthread_t)thread, retval);
- sthread_enable();
- return res;
-}
-
-int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr)
-{
- if (raw_mutex_init == NULL)
- intercepter_init();
-
- if (sthread_inside_simgrid)
- return raw_mutex_init(mutex, attr);
-
- sthread_disable();
- int res = sthread_mutex_init((sthread_mutex_t*)mutex, attr);
- sthread_enable();
- return res;
-}
-
-int pthread_mutex_lock(pthread_mutex_t* mutex)
-{
- if (raw_mutex_lock == NULL)
- intercepter_init();
-
- if (sthread_inside_simgrid)
- return raw_mutex_lock(mutex);
-
- sthread_disable();
- int res = sthread_mutex_lock((sthread_mutex_t*)mutex);
- sthread_enable();
- return res;
-}
-
-int pthread_mutex_trylock(pthread_mutex_t* mutex)
-{
- if (raw_mutex_trylock == NULL)
- intercepter_init();
-
- if (sthread_inside_simgrid)
- return raw_mutex_trylock(mutex);
-
- sthread_disable();
- int res = sthread_mutex_trylock((sthread_mutex_t*)mutex);
- sthread_enable();
- return res;
-}
-
-int pthread_mutex_unlock(pthread_mutex_t* mutex)
-{
- if (raw_mutex_unlock == NULL)
- intercepter_init();
-
- if (sthread_inside_simgrid)
- return raw_mutex_unlock(mutex);
-
- sthread_disable();
- int res = sthread_mutex_unlock((sthread_mutex_t*)mutex);
- sthread_enable();
- return res;
-}
-int pthread_mutex_destroy(pthread_mutex_t* mutex)
-{
- if (raw_mutex_destroy == NULL)
- intercepter_init();
-
- if (sthread_inside_simgrid)
- return raw_mutex_destroy(mutex);
-
- sthread_disable();
- int res = sthread_mutex_destroy((sthread_mutex_t*)mutex);
- sthread_enable();
- return res;
-}
+#define _STHREAD_CONCAT(a, b) a##b
+#define intercepted_pthcall(name, raw_params, call_params, sim_params) \
+ int _STHREAD_CONCAT(pthread_, name) raw_params \
+ { \
+ if (_STHREAD_CONCAT(raw_pthread_, name) == NULL) \
+ intercepter_init(); \
+ if (sthread_inside_simgrid) \
+ return _STHREAD_CONCAT(raw_pthread_, name) call_params; \
+ \
+ sthread_disable(); \
+ int res = _STHREAD_CONCAT(sthread_, name) sim_params; \
+ sthread_enable(); \
+ return res; \
+ }
+
+intercepted_pthcall(mutexattr_init, (pthread_mutexattr_t * attr), (attr), ((sthread_mutexattr_t*)attr));
+intercepted_pthcall(mutexattr_settype, (pthread_mutexattr_t * attr, int type), (attr, type),
+ ((sthread_mutexattr_t*)attr, type));
+intercepted_pthcall(mutexattr_gettype, (const pthread_mutexattr_t* restrict attr, int* type), (attr, type),
+ ((sthread_mutexattr_t*)attr, type));
+intercepted_pthcall(mutexattr_setrobust, (pthread_mutexattr_t* restrict attr, int robustness), (attr, robustness),
+ ((sthread_mutexattr_t*)attr, robustness));
+intercepted_pthcall(mutexattr_getrobust, (const pthread_mutexattr_t* restrict attr, int* restrict robustness),
+ (attr, robustness), ((sthread_mutexattr_t*)attr, robustness));
+
+intercepted_pthcall(create, (pthread_t * thread, const pthread_attr_t* attr, void* (*start_routine)(void*), void* arg),
+ (thread, attr, start_routine, arg), ((sthread_t*)thread, attr, start_routine, arg));
+intercepted_pthcall(join, (pthread_t thread, void** retval), (thread, retval), ((sthread_t)thread, retval));
+
+intercepted_pthcall(mutex_init, (pthread_mutex_t * mutex, const pthread_mutexattr_t* attr), (mutex, attr),
+ ((sthread_mutex_t*)mutex, (sthread_mutexattr_t*)attr));
+intercepted_pthcall(mutex_lock, (pthread_mutex_t * mutex), (mutex), ((sthread_mutex_t*)mutex));
+intercepted_pthcall(mutex_trylock, (pthread_mutex_t * mutex), (mutex), ((sthread_mutex_t*)mutex));
+intercepted_pthcall(mutex_unlock, (pthread_mutex_t * mutex), (mutex), ((sthread_mutex_t*)mutex));
+intercepted_pthcall(mutex_destroy, (pthread_mutex_t * mutex), (mutex), ((sthread_mutex_t*)mutex));
+
+intercepted_pthcall(barrier_init, (pthread_barrier_t * barrier, const pthread_barrierattr_t* attr, unsigned count),
+ (barrier, attr, count), ((sthread_barrier_t*)barrier, (const sthread_barrierattr_t*)attr, count));
+intercepted_pthcall(barrier_wait, (pthread_barrier_t* barrier),( barrier),((sthread_barrier_t*) barrier));
+intercepted_pthcall(barrier_destroy, (pthread_barrier_t* barrier),( barrier),((sthread_barrier_t*) barrier));
+
+intercepted_pthcall(cond_init, (pthread_cond_t * cond, const pthread_condattr_t* attr), (cond, attr),
+ ((sthread_cond_t*)cond, (sthread_condattr_t*)attr));
+intercepted_pthcall(cond_signal, (pthread_cond_t * cond), (cond), ((sthread_cond_t*)cond));
+intercepted_pthcall(cond_broadcast, (pthread_cond_t * cond), (cond), ((sthread_cond_t*)cond));
+intercepted_pthcall(cond_wait, (pthread_cond_t * cond, pthread_mutex_t* mutex), (cond, mutex),
+ ((sthread_cond_t*)cond, (sthread_mutex_t*)mutex));
+intercepted_pthcall(cond_timedwait, (pthread_cond_t * cond, pthread_mutex_t* mutex, const struct timespec* abstime),
+ (cond, mutex, abstime), ((sthread_cond_t*)cond, (sthread_mutex_t*)mutex, abstime));
+intercepted_pthcall(cond_destroy, (pthread_cond_t * cond), (cond), ((sthread_cond_t*)cond));
+
+#define intercepted_call(rettype, name, raw_params, call_params, sim_params) \
+ rettype name raw_params \
+ { \
+ if (_STHREAD_CONCAT(raw_, name) == NULL) \
+ intercepter_init(); \
+ if (sthread_inside_simgrid) \
+ return _STHREAD_CONCAT(raw_, name) call_params; \
+ \
+ sthread_disable(); \
+ rettype res = _STHREAD_CONCAT(sthread_, name) sim_params; \
+ sthread_enable(); \
+ return res; \
+ }
+
+intercepted_call(int, sem_init, (sem_t * sem, int pshared, unsigned int value), (sem, pshared, value),
+ ((sthread_sem_t*)sem, pshared, value));
+intercepted_call(int, sem_destroy, (sem_t * sem), (sem), ((sthread_sem_t*)sem));
+intercepted_call(int, sem_post, (sem_t * sem), (sem), ((sthread_sem_t*)sem));
+intercepted_call(int, sem_wait, (sem_t * sem), (sem), ((sthread_sem_t*)sem));
+intercepted_call(int, sem_trywait, (sem_t * sem), (sem), ((sthread_sem_t*)sem));
+intercepted_call(int, sem_timedwait, (sem_t * sem, const struct timespec* abs_timeout), (sem, abs_timeout),
+ ((sthread_sem_t*)sem, abs_timeout));