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);
72 #define G4MUTEXDESTROY(mutex) pthread_mutex_destroy( &mutex );
76 #define G4THREADCREATE( worker , func , arg ) { \
77 pthread_attr_t attr; \
78 pthread_attr_init(&attr); \
79 pthread_attr_setstacksize(&attr,16*1024*1024); \
80 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE); \
81 pthread_create( worker, &attr, func , arg ); \
85 #define G4THREADJOIN( worker ) pthread_join( worker , NULL)
88 #define G4THREADSELF pthread_self
107 #define G4CONDITION_INITIALIZER PTHREAD_COND_INITIALIZER
109 #define G4CONDITIONWAIT( cond, mutex ) pthread_cond_wait( cond , mutex );
110 #define G4CONDTIONBROADCAST( cond ) pthread_cond_broadcast( cond );
121 #define G4MUTEX_INITIALIZER CreateMutex(NULL,FALSE,NULL)
122 DWORD G4WaitForSingleObjectInf( __in
G4Mutex m );
123 #define G4MUTEXLOCK G4WaitForSingleObjectInf
126 #define G4MUTEXINIT(mutex);
127 #define G4MUTEXDESTROY(mutex);
131 BOOL G4ReleaseMutex( __in
G4Mutex m);
132 #define G4MUTEXUNLOCK G4ReleaseMutex
134 #define G4THREADCREATE( worker, func, arg ) { *worker = CreateThread( NULL, 16*1024*1024 , func , arg , 0 , NULL ); }
135 #define G4THREADJOIN( worker ) WaitForSingleObject( worker , INFINITE);
136 #define G4THREADSELF GetCurrentThreadId
137 #define G4ThreadFunReturnType DWORD WINAPI
146 #define G4CONDITION_INITIALIZER CONDITION_VARIABLE_INIT
148 #define G4CONDITIONWAIT( cond , criticalsectionmutex ) SleepConditionVariableCS( cond, criticalsectionmutex , INFINITE );
149 #define G4CONDTIONBROADCAST( cond ) WakeAllConditionVariable( cond );
153 #error "No Threading model technology supported for this platform. Use sequential build !"
163 #define G4MUTEX_INITIALIZER 1
165 #define G4MUTEXINIT(mutex) ;;
166 #define G4MUTEXDESTROY(mutex) ;;
167 #define G4MUTEXLOCK fake_mutex_lock_unlock
168 #define G4MUTEXUNLOCK fake_mutex_lock_unlock
169 #define G4THREADCREATE( worker , func , arg ) ;;
170 #define G4THREADJOIN( worker ) ;;
171 #define G4THREADSELF( nothing ) G4Thread(nothing);
178 #define G4CONDITION_INITIALIZER 1
179 #define G4CONDITIONWAIT( cond, mutex ) ;;
180 #define G4CONDTIONBROADCAST( cond ) ;;
182 #endif //G4MULTITHREADING
202 #endif //G4Threading_hh
G4bool G4SetPinAffinity(G4int idx, G4Thread &at)
G4int(* thread_lock)(G4Mutex *)
void SetMultithreadedApplication(G4bool value)
void G4SetThreadId(G4int aNewValue)
G4int G4GetNumberOfCores()
G4bool IsMultithreadedApplication()
G4int(* thread_unlock)(G4Mutex *)
G4int fake_mutex_lock_unlock(G4Mutex *)
void * G4ThreadFunArgType
void * G4ThreadFunReturnType