Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Threading.hh File Reference
#include "G4Types.hh"
#include "globals.hh"
#include <chrono>
#include <condition_variable>
#include <future>
#include <mutex>
#include <thread>
#include <vector>

Go to the source code of this file.

Classes

class  G4DummyThread
 

Namespaces

namespace  G4ThisThread
 
namespace  G4Threading
 

Macros

#define G4THREADSLEEP(tick)    std::this_thread::sleep_for(std::chrono::seconds(tick))
 
#define G4MUTEX_INITIALIZER    {}
 
#define G4MUTEXINIT(mutex)
 
#define G4MUTEXDESTROY(mutex)
 
#define G4MUTEXLOCK(mutex)
 
#define G4MUTEXUNLOCK(mutex)
 
#define G4THREADJOIN(worker)
 
#define G4CONDITION_INITIALIZER   1
 
#define G4CONDITIONWAIT(cond, mutex)   G4ConsumeParameters(cond, mutex);
 
#define G4CONDITIONWAITLAMBDA(cond, mutex, lambda)    G4ConsumeParameters(cond, mutex, lambda);
 
#define G4CONDITIONNOTIFY(cond)   G4ConsumeParameters(cond);
 
#define G4CONDITIONBROADCAST(cond)   G4ConsumeParameters(cond);
 

Typedefs

template<typename _Tp >
using G4Future = std::future< _Tp >
 
template<typename _Tp >
using G4SharedFuture = std::shared_future< _Tp >
 
template<typename _Tp >
using G4Promise = std::promise< _Tp >
 
using G4Mutex = std::mutex
 
using G4RecursiveMutex = std::recursive_mutex
 
using G4ThreadFunReturnType = void *
 
using G4ThreadFunArgType = void *
 
using thread_lock = G4int(*)(G4Mutex *)
 
using thread_unlock = G4int(*)(G4Mutex *)
 
using G4Thread = G4DummyThread
 
using G4NativeThread = G4DummyThread::native_handle_type
 
using G4Pid_t = G4int
 
using G4Condition = G4int
 
using G4ThreadId = G4Thread::id
 

Enumerations

enum  { G4Threading::SEQUENTIAL_ID = -2 , G4Threading::MASTER_ID = -1 , G4Threading::WORKER_ID = 0 , G4Threading::GENERICTHREAD_ID = -1000 }
 

Functions

template<typename _Tp >
G4MutexG4TypeMutex (const unsigned int &_n=0)
 
template<typename _Tp >
G4RecursiveMutexG4TypeRecursiveMutex (const unsigned int &_n=0)
 
template<typename _Worker , typename _Func , typename... _Args>
void G4THREADCREATE (_Worker *&worker, _Func func, _Args... args)
 
G4Pid_t G4Threading::G4GetPidId ()
 
G4int G4Threading::G4GetNumberOfCores ()
 
G4int G4Threading::G4GetThreadId ()
 
G4bool G4Threading::IsWorkerThread ()
 
G4bool G4Threading::IsMasterThread ()
 
void G4Threading::G4SetThreadId (G4int aNewValue)
 
G4bool G4Threading::G4SetPinAffinity (G4int idx, G4NativeThread &at)
 
void G4Threading::SetMultithreadedApplication (G4bool value)
 
G4bool G4Threading::IsMultithreadedApplication ()
 
G4int G4Threading::WorkerThreadLeavesPool ()
 
G4int G4Threading::WorkerThreadJoinsPool ()
 
G4int G4Threading::GetNumberOfRunningWorkerThreads ()
 

Macro Definition Documentation

◆ G4CONDITION_INITIALIZER

#define G4CONDITION_INITIALIZER   1

Definition at line 274 of file G4Threading.hh.

◆ G4CONDITIONBROADCAST

#define G4CONDITIONBROADCAST (   cond)    G4ConsumeParameters(cond);

Definition at line 279 of file G4Threading.hh.

◆ G4CONDITIONNOTIFY

#define G4CONDITIONNOTIFY (   cond)    G4ConsumeParameters(cond);

Definition at line 278 of file G4Threading.hh.

◆ G4CONDITIONWAIT

#define G4CONDITIONWAIT (   cond,
  mutex 
)    G4ConsumeParameters(cond, mutex);

Definition at line 275 of file G4Threading.hh.

◆ G4CONDITIONWAITLAMBDA

#define G4CONDITIONWAITLAMBDA (   cond,
  mutex,
  lambda 
)     G4ConsumeParameters(cond, mutex, lambda);

Definition at line 276 of file G4Threading.hh.

◆ G4MUTEX_INITIALIZER

#define G4MUTEX_INITIALIZER    {}

Definition at line 85 of file G4Threading.hh.

◆ G4MUTEXDESTROY

#define G4MUTEXDESTROY (   mutex)
Value:
; \
;

Definition at line 90 of file G4Threading.hh.

◆ G4MUTEXINIT

#define G4MUTEXINIT (   mutex)
Value:
; \
;

Definition at line 87 of file G4Threading.hh.

◆ G4MUTEXLOCK

#define G4MUTEXLOCK (   mutex)
Value:
; \
;

Definition at line 251 of file G4Threading.hh.

◆ G4MUTEXUNLOCK

#define G4MUTEXUNLOCK (   mutex)
Value:
; \
;

Definition at line 254 of file G4Threading.hh.

◆ G4THREADJOIN

#define G4THREADJOIN (   worker)
Value:
; \
;

Definition at line 259 of file G4Threading.hh.

◆ G4THREADSLEEP

#define G4THREADSLEEP (   tick)     std::this_thread::sleep_for(std::chrono::seconds(tick))

Definition at line 50 of file G4Threading.hh.

Typedef Documentation

◆ G4Condition

using G4Condition = G4int

Definition at line 273 of file G4Threading.hh.

◆ G4Future

template<typename _Tp >
using G4Future = std::future<_Tp>

Definition at line 55 of file G4Threading.hh.

◆ G4Mutex

using G4Mutex = std::mutex

Definition at line 81 of file G4Threading.hh.

◆ G4NativeThread

◆ G4Pid_t

using G4Pid_t = G4int

Definition at line 263 of file G4Threading.hh.

◆ G4Promise

template<typename _Tp >
using G4Promise = std::promise<_Tp>

Definition at line 59 of file G4Threading.hh.

◆ G4RecursiveMutex

using G4RecursiveMutex = std::recursive_mutex

Definition at line 82 of file G4Threading.hh.

◆ G4SharedFuture

template<typename _Tp >
using G4SharedFuture = std::shared_future<_Tp>

Definition at line 57 of file G4Threading.hh.

◆ G4Thread

Definition at line 247 of file G4Threading.hh.

◆ G4ThreadFunArgType

using G4ThreadFunArgType = void*

Definition at line 111 of file G4Threading.hh.

◆ G4ThreadFunReturnType

using G4ThreadFunReturnType = void*

Definition at line 110 of file G4Threading.hh.

◆ G4ThreadId

Definition at line 286 of file G4Threading.hh.

◆ thread_lock

using thread_lock = G4int (*)(G4Mutex*)

Definition at line 112 of file G4Threading.hh.

◆ thread_unlock

using thread_unlock = G4int (*)(G4Mutex*)

Definition at line 114 of file G4Threading.hh.

Function Documentation

◆ G4THREADCREATE()

template<typename _Worker , typename _Func , typename... _Args>
void G4THREADCREATE ( _Worker *&  worker,
_Func  func,
_Args...  args 
)

Definition at line 268 of file G4Threading.hh.

269{
270 *worker = G4Thread(func, std::forward<_Args>(args)...);
271}
G4DummyThread G4Thread
Definition: G4Threading.hh:247

◆ G4TypeMutex()

template<typename _Tp >
G4Mutex & G4TypeMutex ( const unsigned int &  _n = 0)

Definition at line 124 of file G4Threading.hh.

125{
126 static G4Mutex* _mutex = new G4Mutex();
127 if(_n == 0)
128 return *_mutex;
129
130 static std::vector<G4Mutex*> _mutexes;
131 if(_n > _mutexes.size())
132 _mutexes.resize(_n, nullptr);
133 if(!_mutexes[_n])
134 _mutexes[_n] = new G4Mutex();
135 return *(_mutexes[_n - 1]);
136}
std::mutex G4Mutex
Definition: G4Threading.hh:81

Referenced by G4Cache< VALTYPE >::G4Cache(), and G4Cache< VALTYPE >::~G4Cache().

◆ G4TypeRecursiveMutex()

template<typename _Tp >
G4RecursiveMutex & G4TypeRecursiveMutex ( const unsigned int &  _n = 0)

Definition at line 146 of file G4Threading.hh.

147{
148 static auto* _mutex = new G4RecursiveMutex();
149 if(_n == 0)
150 return *(_mutex);
151
152 static std::vector<G4RecursiveMutex*> _mutexes;
153 if(_n > _mutexes.size())
154 _mutexes.resize(_n, nullptr);
155 if(!_mutexes[_n])
156 _mutexes[_n] = new G4RecursiveMutex();
157 return *(_mutexes[_n - 1]);
158}
std::recursive_mutex G4RecursiveMutex
Definition: G4Threading.hh:82