>>>>>>> Convert sthread.c to C++.:src/sthread/sthread.cpp
}
-static bool sthread_inside_simgrid = true;
-void sthread_enable(void)
-{ // Start intercepting all pthread calls
- sthread_inside_simgrid = false;
-}
-void sthread_disable(void)
-{ // Stop intercepting all pthread calls
- sthread_inside_simgrid = true;
-}
<<<<<<< HEAD:src/sthread/sthread.c
#define _STHREAD_CONCAT(a, b) a##b
if (not raw_pthread_create)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_pthread_create(thread, attr, start_routine, arg);
sthread_disable();
{
if (not raw_pthread_join)
intercepter_init();
- if (sthread_inside_simgrid)
+
+ if (sthread_inside_simgrid())
return raw_pthread_join(thread, retval);
sthread_disable();
if (not raw_mutex_init)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_mutex_init(mutex, attr);
sthread_disable();
if (not raw_mutex_lock)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_mutex_lock(mutex);
sthread_disable();
if (not raw_mutex_trylock)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_mutex_trylock(mutex);
sthread_disable();
if (not raw_mutex_unlock)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_mutex_unlock(mutex);
sthread_disable();
if (not raw_mutex_destroy)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_mutex_destroy(mutex);
sthread_disable();
if (not raw_sem_init)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_sem_init(sem, pshared, value);
sthread_disable();
if (not raw_sem_destroy)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_sem_destroy(sem);
sthread_disable();
if (not raw_sem_post)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_sem_post(sem);
sthread_disable();
if (not raw_sem_wait)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_sem_wait(sem);
sthread_disable();
if (not raw_sem_trywait)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_sem_trywait(sem);
sthread_disable();
if (not raw_sem_timedwait)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_sem_timedwait(sem, abs_timeout);
sthread_disable();
if (not raw_gettimeofday)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_gettimeofday(tv, tz);
sthread_disable();
if (not raw_sleep)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_sleep(seconds);
sthread_disable();
if (not raw_usleep)
intercepter_init();
- if (sthread_inside_simgrid)
+ if (sthread_inside_simgrid())
return raw_usleep(usec);
sthread_disable();
#include <sys/time.h>
#if defined(__cplusplus)
+
+inline bool& sthread_inside_simgrid()
+{
+ static bool value = true;
+ return value;
+}
+
+inline void sthread_enable(void)
+{ // Start intercepting all pthread calls
+ sthread_inside_simgrid() = false;
+}
+
+inline void sthread_disable(void)
+{ // Stop intercepting all pthread calls
+ sthread_inside_simgrid() = true;
+}
+
extern "C" {
#endif
// Launch the simulation. The old main function (passed as a parameter) is launched as an actor
int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**, char**));
-XBT_PUBLIC void sthread_enable(void); // Start intercepting all pthread calls
-XBT_PUBLIC void sthread_disable(void); // Stop intercepting all pthread calls
typedef unsigned long int sthread_t;
int sthread_create(sthread_t* thread, const /*pthread_attr_t*/ void* attr, void* (*start_routine)(void*), void* arg);