38 #ifndef G4Threading_hh
39 #define G4Threading_hh
46 #include <condition_variable>
52 #define G4THREADSLEEP(tick) \
53 std::this_thread::sleep_for(std::chrono::seconds( tick ))
88 #define G4MUTEX_INITIALIZER {}
89 #define G4MUTEXINIT(mutex) ;;
90 #define G4MUTEXDESTROY(mutex) ;;
93 namespace G4ThisThread {
using namespace std::this_thread; }
97 template <
typename _Tp>
using G4Promise = std::promise<_Tp>;
98 template <
typename _Tp>
using G4Future = std::future<_Tp>;
113 template <
typename _Tp>
120 static std::vector<G4Mutex*> _mutexes;
121 if(_n > _mutexes.size())
122 _mutexes.resize(_n,
nullptr);
125 return *(_mutexes[_n-1]);
134 template <
typename _Tp>
141 static std::vector<G4RecursiveMutex*> _mutexes;
142 if(_n > _mutexes.size())
143 _mutexes.resize(_n,
nullptr);
146 return *(_mutexes[_n-1]);
149 #if defined(G4MULTITHREADED)
159 #define G4MUTEXLOCK(mutex) { (mutex)->lock(); }
160 #define G4MUTEXUNLOCK(mutex) { (mutex)->unlock(); }
163 #define G4THREADJOIN(worker) (worker).join()
166 typedef std::thread::id
G4Pid_t;
170 template <
typename _Worker,
typename _Func,
typename... _Args>
173 *worker =
G4Thread(func, std::forward<_Args>(args)...);
181 #define G4CONDITION_INITIALIZER {}
182 #define G4CONDITIONWAIT(cond, lock) (cond)->wait(*lock);
183 #define G4CONDITIONWAITLAMBDA(cond, lock, lambda) (cond)->wait(*lock, lambda);
184 #define G4CONDITIONBROADCAST(cond) (cond)->notify_all();
200 typedef std::thread::id
id;
207 template <
typename _Func,
typename... _Args>
210 func(std::forward<_Args>(_args)...);
224 return std::thread::hardware_concurrency();
233 #define G4MUTEXLOCK(mutex) ;;
234 #define G4MUTEXUNLOCK(mutex) ;;
237 #define G4THREADJOIN(worker) ;;
243 template <
typename _Worker,
typename _Func,
typename... _Args>
246 *worker =
G4Thread(func, std::forward<_Args>(args)...);
250 #define G4CONDITION_INITIALIZER 1
251 #define G4CONDITIONWAIT( cond, mutex ) { (*cond)++; }
252 #define G4CONDITIONWAITLAMBDA( cond, mutex, lambda ) { (*cond)++; }
253 #define G4CONDITIONBROADCAST( cond ) { (*cond)++; }
255 #endif //G4MULTITHREADING
257 namespace G4Threading
281 #endif //G4Threading_hh
int WorkerThreadJoinsPool()
std::promise< _Tp > G4Promise
id get_id() const noexcept
static unsigned int hardware_concurrency() noexcept
native_handle_type native_handle() const
G4RecursiveMutex & G4TypeRecursiveMutex(const unsigned int &_n=0)
std::future< _Tp > G4Future
G4int G4GetNumberOfCores()
G4Mutex & G4TypeMutex(const unsigned int &_n=0)
int WorkerThreadLeavesPool()
G4int GetNumberOfRunningWorkerThreads()
const XML_Char int const XML_Char * value
G4bool G4SetPinAffinity(G4int idx, G4NativeThread &at)
void SetMultithreadedApplication(G4bool value)
const G4ThreeVector const G4double const
G4DummyThread::native_handle_type G4NativeThread
void G4SetThreadId(G4int aNewValue)
void * G4ThreadFunReturnType
std::shared_future< _Tp > G4SharedFuture
G4bool IsMultithreadedApplication()
void * G4ThreadFunArgType
void G4THREADCREATE(_Worker *&worker, _Func func, _Args...args)
G4DummyThread(_Func func, _Args &&..._args)
std::recursive_mutex G4RecursiveMutex
void swap(G4DummyThread &)
G4int(* thread_unlock)(G4Mutex *)
G4int(* thread_lock)(G4Mutex *)