38 #ifndef G4Threading_hh
39 #define G4Threading_hh
46 #define G4THREADSLEEP( tick ) { Sleep(tick); }
49 #define G4THREADSLEEP( tick ) { sleep(tick); }
52 #if defined(G4MULTITHREADED)
56 #if ( defined(__MACH__) && defined(__clang__) && defined(__x86_64__) ) || \
57 ( defined(__MACH__) && defined(__GNUC__) && (__GNUC__>=4 && __GNUC_MINOR__>=7 || __GNUC__>=5) ) || \
58 defined(__linux__) || defined(_AIX)
63 #if defined(__MACH__) // needed only for MacOSX for definition of pid_t
64 #include <sys/types.h>
67 typedef pthread_mutex_t
G4Mutex;
72 #define G4MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
76 #define G4MUTEXLOCK pthread_mutex_lock
77 #define G4MUTEXUNLOCK pthread_mutex_unlock
81 #define G4MUTEXINIT(mutex) pthread_mutex_init( &mutex , NULL);
82 #define G4MUTEXDESTROY(mutex) pthread_mutex_destroy( &mutex );
86 #define G4THREADCREATE( worker , func , arg ) { \
87 pthread_attr_t attr; \
88 pthread_attr_init(&attr); \
89 pthread_attr_setstacksize(&attr,16*1024*1024); \
90 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE); \
91 pthread_create( worker, &attr, func , arg ); \
96 #define G4THREADJOIN( worker ) pthread_join( worker , NULL)
100 #define G4THREADSELF pthread_self
119 #define G4CONDITION_INITIALIZER PTHREAD_COND_INITIALIZER
121 #define G4CONDITIONWAIT( cond, mutex ) pthread_cond_wait( cond , mutex );
122 #define G4CONDITIONBROADCAST( cond ) pthread_cond_broadcast( cond );
133 #define G4MUTEX_INITIALIZER CreateMutex(NULL,FALSE,NULL)
134 DWORD G4WaitForSingleObjectInf( __in
G4Mutex m );
135 #define G4MUTEXLOCK G4WaitForSingleObjectInf
138 #define G4MUTEXINIT(mutex);
139 #define G4MUTEXDESTROY(mutex);
143 BOOL G4ReleaseMutex( __in
G4Mutex m);
144 #define G4MUTEXUNLOCK G4ReleaseMutex
146 #define G4THREADCREATE( worker, func, arg ) { *worker = CreateThread( NULL, 16*1024*1024 , func , arg , 0 , NULL ); }
147 #define G4THREADJOIN( worker ) WaitForSingleObject( worker , INFINITE);
148 #define G4THREADSELF GetCurrentThreadId
149 #define G4ThreadFunReturnType DWORD WINAPI
158 #define G4CONDITION_INITIALIZER CONDITION_VARIABLE_INIT
160 #define G4CONDITIONWAIT( cond , criticalsectionmutex ) SleepConditionVariableCS( cond, criticalsectionmutex , INFINITE );
161 #define G4CONDITIONBROADCAST( cond ) WakeAllConditionVariable( cond );
165 #error "No Threading model technology supported for this platform. Use sequential build !"
175 #define G4MUTEX_INITIALIZER 1
177 #define G4MUTEXINIT(mutex) ;;
178 #define G4MUTEXDESTROY(mutex) ;;
179 #define G4MUTEXLOCK fake_mutex_lock_unlock
180 #define G4MUTEXUNLOCK fake_mutex_lock_unlock
181 #define G4THREADCREATE( worker , func , arg ) ;;
182 #define G4THREADJOIN( worker ) ;;
183 #define G4THREADSELF( nothing ) G4Thread(nothing);
190 #define G4CONDITION_INITIALIZER 1
191 #define G4CONDITIONWAIT( cond, mutex ) { ++(*cond); ++(*mutex); }
192 #define G4CONDITIONBROADCAST( cond ) { ++(*cond); }
194 #endif //G4MULTITHREADING
196 namespace G4Threading
218 #endif //G4Threading_hh
G4bool G4SetPinAffinity(G4int idx, G4Thread &at)
G4int(* thread_lock)(G4Mutex *)
void SetMultithreadedApplication(G4bool value)
G4int GetNumberOfRunningWorkerThreads()
int WorkerThreadLeavesPool()
void G4SetThreadId(G4int aNewValue)
static constexpr double m
const XML_Char int const XML_Char * value
G4int G4GetNumberOfCores()
int WorkerThreadJoinsPool()
G4bool IsMultithreadedApplication()
G4int(* thread_unlock)(G4Mutex *)
G4int fake_mutex_lock_unlock(G4Mutex *)
void * G4ThreadFunArgType
void * G4ThreadFunReturnType