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>
137template <
typename _Tp>
144#if defined(G4MULTITHREADED)
154# define G4MUTEXLOCK(mutex) \
158# define G4MUTEXUNLOCK(mutex) \
164# define G4THREADJOIN(worker) (worker).join()
167using G4Pid_t = std::thread::id;
171template <
typename _Worker,
typename _Func,
typename... _Args>
174 *worker =
G4Thread(func, std::forward<_Args>(args)...);
182# define G4CONDITION_INITIALIZER \
184# define G4CONDITIONWAIT(cond, lock) (cond)->wait(*lock);
185# define G4CONDITIONWAITLAMBDA(cond, lock, lambda) (cond)->wait(*lock, lambda);
186# define G4CONDITIONNOTIFY(cond) (cond)->notify_one();
187# define G4CONDITIONBROADCAST(cond) (cond)->notify_all();
203 using id = std::thread::id;
209 template <
typename _Func,
typename... _Args>
212 func(std::forward<_Args>(_args)...);
218 id get_id() const noexcept {
return std::this_thread::get_id(); }
226 return std::thread::hardware_concurrency();
235# define G4MUTEXLOCK(mutex) \
238# define G4MUTEXUNLOCK(mutex) \
243# define G4THREADJOIN(worker) \
251template <
typename _Worker,
typename _Func,
typename... _Args>
254 *worker =
G4Thread(func, std::forward<_Args>(args)...);
258# define G4CONDITION_INITIALIZER 1
259# define G4CONDITIONWAIT(cond, mutex) G4ConsumeParameters(cond, mutex);
260# define G4CONDITIONWAITLAMBDA(cond, mutex, lambda) \
261 G4ConsumeParameters(cond, mutex, lambda);
262# define G4CONDITIONNOTIFY(cond) G4ConsumeParameters(cond);
263# define G4CONDITIONBROADCAST(cond) G4ConsumeParameters(cond);
std::future< _Tp > G4Future
G4int(*)(G4Mutex *) thread_unlock
void G4THREADCREATE(_Worker *&worker, _Func func, _Args... args)
G4RecursiveMutex & G4TypeRecursiveMutex()
std::recursive_mutex G4RecursiveMutex
std::shared_future< _Tp > G4SharedFuture
G4DummyThread::native_handle_type G4NativeThread
std::promise< _Tp > G4Promise
void * G4ThreadFunReturnType
void * G4ThreadFunArgType
G4int(*)(G4Mutex *) thread_lock
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)