38 #ifndef G4Threading_hh
39 #define G4Threading_hh
43 #if defined(G4MULTITHREADED)
47 #if ( defined(__MACH__) && defined(__clang__) && defined(__x86_64__) ) || \
48 ( defined(__MACH__) && defined(__GNUC__) && __GNUC__>=4 && __GNUC_MINOR__>=7 ) || \
49 defined(__linux__) || defined(_AIX)
54 #if defined(__MACH__) // needed only for MacOSX for definition of pid_t
55 #include <sys/types.h>
58 typedef pthread_mutex_t
G4Mutex;
63 #define G4MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
67 #define G4MUTEXLOCK pthread_mutex_lock
68 #define G4MUTEXUNLOCK pthread_mutex_unlock
71 #define G4MUTEXINIT(mutex) pthread_mutex_init( &mutex , NULL);
75 #define G4THREADCREATE( worker , func , arg ) { \
76 pthread_attr_t attr; \
77 pthread_attr_init(&attr); \
78 pthread_attr_setstacksize(&attr,16*1024*1024); \
79 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE); \
80 pthread_create( worker, &attr, func , arg ); \
85 #define G4THREADJOIN( worker ) pthread_join( worker , NULL)
104 #define G4CONDITION_INITIALIZER PTHREAD_COND_INITIALIZER
106 #define G4CONDITIONWAIT( cond, mutex ) pthread_cond_wait( cond , mutex );
107 #define G4CONDTIONBROADCAST( cond ) pthread_cond_broadcast( cond );
118 #define G4MUTEX_INITIALIZER CreateMutex(NULL,FALSE,NULL)
119 DWORD G4WaitForSingleObjectInf( __in
G4Mutex m );
120 #define G4MUTEXLOCK G4WaitForSingleObjectInf
123 #define G4MUTEXINIT(mutex);
127 BOOL G4ReleaseMutex( __in
G4Mutex m);
128 #define G4MUTEXUNLOCK G4ReleaseMutex
130 #define G4THREADCREATE( worker, func, arg ) { *worker = CreateThread( NULL, 16*1024*1024 , func , arg , 0 , NULL ); }
131 #define G4THREADJOIN( worker ) WaitForSingleObject( worker , INFINITE);
132 #define G4ThreadFunReturnType DWORD WINAPI
141 #define G4CONDITION_INITIALIZER CONDITION_VARIABLE_INIT
143 #define G4CONDITIONWAIT( cond , criticalsectionmutex ) SleepConditionVariableCS( cond, criticalsectionmutex , INFINITE );
144 #define G4CONDTIONBROADCAST( cond ) WakeAllConditionVariable( cond );
148 #error "No Threading model technology supported for this platform. Use sequential build !"
158 #define G4MUTEX_INITIALIZER 1
160 #define G4MUTEXINIT(mutex) ;;
161 #define G4MUTEXLOCK fake_mutex_lock_unlock
162 #define G4MUTEXUNLOCK fake_mutex_lock_unlock
163 #define G4THREADCREATE( worker , func , arg ) ;;
164 #define G4THREADJOIN( worker ) ;;
171 #define G4CONDITION_INITIALIZER 1
172 #define G4CONDITIONWAIT( cond, mutex ) ;;
173 #define G4CONDTIONBROADCAST( cond ) ;;
175 #endif //G4MULTITHREADING
177 namespace G4Threading {
184 #endif //G4Threading_hh
G4int(* thread_lock)(G4Mutex *)
void G4SetThreadId(G4int aNewValue)
G4int G4GetNumberOfCores()
G4int(* thread_unlock)(G4Mutex *)
G4int fake_mutex_lock_unlock(G4Mutex *)
void * G4ThreadFunArgType
void * G4ThreadFunReturnType