36#define G4Threading_hh 1
42#include <condition_variable>
50#define G4THREADSLEEP(tick) \
51 std::this_thread::sleep_for(std::chrono::seconds(tick))
54template <
typename _Tp>
56template <
typename _Tp>
58template <
typename _Tp>
85#define G4MUTEX_INITIALIZER \
87#define G4MUTEXINIT(mutex) \
90#define G4MUTEXDESTROY(mutex) \
97 using namespace std::this_thread;
102template <
typename _Tp>
104template <
typename _Tp>
106template <
typename _Tp>
123template <
typename _Tp>
130 static std::vector<G4Mutex*> _mutexes;
131 if(_n > _mutexes.size())
132 _mutexes.resize(_n,
nullptr);
135 return *(_mutexes[_n - 1]);
145template <
typename _Tp>
152 static std::vector<G4RecursiveMutex*> _mutexes;
153 if(_n > _mutexes.size())
154 _mutexes.resize(_n,
nullptr);
157 return *(_mutexes[_n - 1]);
160#if defined(G4MULTITHREADED)
170# define G4MUTEXLOCK(mutex) \
174# define G4MUTEXUNLOCK(mutex) \
180# define G4THREADJOIN(worker) (worker).join()
183using G4Pid_t = std::thread::id;
187template <
typename _Worker,
typename _Func,
typename... _Args>
190 *worker =
G4Thread(func, std::forward<_Args>(args)...);
198# define G4CONDITION_INITIALIZER \
200# define G4CONDITIONWAIT(cond, lock) (cond)->wait(*lock);
201# define G4CONDITIONWAITLAMBDA(cond, lock, lambda) (cond)->wait(*lock, lambda);
202# define G4CONDITIONNOTIFY(cond) (cond)->notify_one();
203# define G4CONDITIONBROADCAST(cond) (cond)->notify_all();
219 using id = std::thread::id;
225 template <
typename _Func,
typename... _Args>
228 func(std::forward<_Args>(_args)...);
234 id get_id() const noexcept {
return std::this_thread::get_id(); }
242 return std::thread::hardware_concurrency();
251# define G4MUTEXLOCK(mutex) \
254# define G4MUTEXUNLOCK(mutex) \
259# define G4THREADJOIN(worker) \
267template <
typename _Worker,
typename _Func,
typename... _Args>
270 *worker =
G4Thread(func, std::forward<_Args>(args)...);
274# define G4CONDITION_INITIALIZER 1
275# define G4CONDITIONWAIT(cond, mutex) G4ConsumeParameters(cond, mutex);
276# define G4CONDITIONWAITLAMBDA(cond, mutex, lambda) \
277 G4ConsumeParameters(cond, mutex, lambda);
278# define G4CONDITIONNOTIFY(cond) G4ConsumeParameters(cond);
279# define G4CONDITIONBROADCAST(cond) G4ConsumeParameters(cond);
std::future< _Tp > G4Future
G4RecursiveMutex & G4TypeRecursiveMutex(const unsigned int &_n=0)
G4int(*)(G4Mutex *) thread_unlock
void G4THREADCREATE(_Worker *&worker, _Func func, _Args... args)
std::recursive_mutex G4RecursiveMutex
std::shared_future< _Tp > G4SharedFuture
G4Mutex & G4TypeMutex(const unsigned int &_n=0)
G4DummyThread::native_handle_type G4NativeThread
std::promise< _Tp > G4Promise
void * G4ThreadFunReturnType
G4int(*)(G4Mutex *) thread_lock
void * G4ThreadFunArgType
G4DummyThread(_Func func, _Args &&... _args)
static unsigned int hardware_concurrency() noexcept
void swap(G4DummyThread &)
id get_id() const noexcept
native_handle_type native_handle() const
G4int WorkerThreadJoinsPool()
G4bool G4SetPinAffinity(G4int idx, G4NativeThread &at)
G4int G4GetNumberOfCores()
G4int WorkerThreadLeavesPool()
G4bool IsMultithreadedApplication()
void SetMultithreadedApplication(G4bool value)
G4int GetNumberOfRunningWorkerThreads()
void G4SetThreadId(G4int aNewValue)