Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PTL::Threading Namespace Reference

Enumerations

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

Functions

Pid_t GetPidId ()
 
unsigned GetNumberOfCores ()
 
int GetThreadId ()
 
bool IsWorkerThread ()
 
bool IsMasterThread ()
 
void SetThreadId (int aNewValue)
 
bool SetPinAffinity (int idx, NativeThread &at)
 
int WorkerThreadLeavesPool ()
 
int WorkerThreadJoinsPool ()
 
int GetNumberOfRunningWorkerThreads ()
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SEQUENTIAL_ID 
MASTER_ID 
WORKER_ID 
GENERICTHREAD_ID 

Definition at line 207 of file Threading.hh.

208{
209 SEQUENTIAL_ID = -2,
210 MASTER_ID = -1,
211 WORKER_ID = 0,
212 GENERICTHREAD_ID = -1000
213};

Function Documentation

◆ GetNumberOfCores()

unsigned PTL::Threading::GetNumberOfCores ( )

Definition at line 64 of file Threading.cc.

65{
66 return std::thread::hardware_concurrency();
67}

Referenced by PTL::ThreadPool::execute_on_all_threads().

◆ GetNumberOfRunningWorkerThreads()

int PTL::Threading::GetNumberOfRunningWorkerThreads ( )

Definition at line 122 of file Threading.cc.

123{
124 return numActThreads.load();
125}

◆ GetPidId()

Pid_t PTL::Threading::GetPidId ( )

Definition at line 55 of file Threading.cc.

56{
57 // In multithreaded mode return Thread ID
58 return std::this_thread::get_id();
59}

◆ GetThreadId()

int PTL::Threading::GetThreadId ( )

Definition at line 77 of file Threading.cc.

78{
79 return ThreadID;
80}

◆ IsMasterThread()

bool PTL::Threading::IsMasterThread ( )

Definition at line 87 of file Threading.cc.

88{
89 return (ThreadID == MASTER_ID);
90}

◆ IsWorkerThread()

bool PTL::Threading::IsWorkerThread ( )

Definition at line 82 of file Threading.cc.

83{
84 return (ThreadID >= 0);
85}

◆ SetPinAffinity()

bool PTL::Threading::SetPinAffinity ( int  idx,
NativeThread at 
)

Definition at line 95 of file Threading.cc.

96{
97#if defined(__linux__) || defined(_AIX)
98 cpu_set_t* aset = new cpu_set_t;
99 CPU_ZERO(aset);
100 CPU_SET(cpu, aset);
101 pthread_t& _aT = static_cast<pthread_t&>(aT);
102 return (pthread_setaffinity_np(_aT, sizeof(cpu_set_t), aset) == 0);
103#else // Not available for Mac, WIN,...
104 ConsumeParameters(cpu, aT);
105 return true;
106#endif
107}
void ConsumeParameters(Args...)
Definition: Utility.hh:44

Referenced by PTL::ThreadPool::set_affinity().

◆ SetThreadId()

void PTL::Threading::SetThreadId ( int  aNewValue)

Definition at line 72 of file Threading.cc.

73{
74 ThreadID = value;
75}

◆ WorkerThreadJoinsPool()

int PTL::Threading::WorkerThreadJoinsPool ( )

Definition at line 117 of file Threading.cc.

118{
119 return numActThreads++;
120}

◆ WorkerThreadLeavesPool()

int PTL::Threading::WorkerThreadLeavesPool ( )

Definition at line 112 of file Threading.cc.

113{
114 return numActThreads--;
115}