Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Help windows builds: do not redefine XBT_PUBLIC
[simgrid.git] / src / sthread / sthread.h
1 /* SimGrid's pthread interposer. Intercepts most of the pthread and semaphore calls to model-check them.
2  *
3  * Intercepting on pthread is somewhat complicated by the fact that pthread is used everywhere in the system headers.
4  * To reduce definition conflicts, our redefinitions of the pthread symbols (in sthread.c) load as little headers as
5  * possible. Thus, the actual implementations are separated in another file (sthread_impl.cpp) and are used as black
6  * boxes by our redefinitions.
7  *
8  * The sthread_* symbols are those actual implementations, used in the pthread_* redefinitions. */
9
10 #ifndef SIMGRID_STHREAD_H
11 #define SIMGRID_STHREAD_H
12
13 #include "xbt/base.h"
14 #include <sys/time.h>
15
16 #if defined(__cplusplus)
17 extern "C" {
18 #endif
19
20 // Launch the simulation. The old main function (passed as a parameter) is launched as an actor
21 int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**, char**));
22 XBT_PUBLIC void sthread_enable(void);  // Start intercepting all pthread calls
23 XBT_PUBLIC void sthread_disable(void); // Stop intercepting all pthread calls
24
25 typedef unsigned long int sthread_t;
26 int sthread_create(sthread_t* thread, const /*pthread_attr_t*/ void* attr, void* (*start_routine)(void*), void* arg);
27 int sthread_join(sthread_t thread, void** retval);
28
29 typedef struct {
30   void* mutex;
31 } sthread_mutex_t;
32 int sthread_mutex_init(sthread_mutex_t* mutex, const /*pthread_mutexattr_t*/ void* attr);
33 int sthread_mutex_lock(sthread_mutex_t* mutex);
34 int sthread_mutex_trylock(sthread_mutex_t* mutex);
35 int sthread_mutex_unlock(sthread_mutex_t* mutex);
36 int sthread_mutex_destroy(sthread_mutex_t* mutex);
37
38 int sthread_gettimeofday(struct timeval* tv);
39 void sthread_sleep(double seconds);
40
41 #if defined(__cplusplus)
42 }
43 #endif
44
45 #endif