Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PTL::VTask Class Referenceabstract

VTask is the abstract class stored in thread_pool. More...

#include <VTask.hh>

+ Inheritance diagram for PTL::VTask:

Public Types

typedef std::thread::id tid_type
 
typedef size_t size_type
 
typedef VTask this_type
 
typedef std::atomic_uintmax_t count_t
 
typedef VTaskiterator
 
typedef const VTaskconst_iterator
 
typedef std::function< void()> void_func_t
 

Public Member Functions

 VTask ()
 
 VTask (VTaskGroup *task_group)
 
 VTask (ThreadPool *pool)
 
virtual ~VTask ()
 
virtual void operator() ()=0
 
void operator-- ()
 
virtual bool is_native_task () const
 
virtual ThreadPoolpool () const
 
VTaskGroupgroup () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
intmax_t & depth ()
 
const intmax_t & depth () const
 

Static Protected Member Functions

static tid_type this_tid ()
 

Protected Attributes

intmax_t m_depth
 
VTaskGroupm_group
 
ThreadPoolm_pool
 
void_func_t m_func = []() {}
 

Detailed Description

VTask is the abstract class stored in thread_pool.

Definition at line 54 of file VTask.hh.

Member Typedef Documentation

◆ const_iterator

Definition at line 62 of file VTask.hh.

◆ count_t

typedef std::atomic_uintmax_t PTL::VTask::count_t

Definition at line 60 of file VTask.hh.

◆ iterator

Definition at line 61 of file VTask.hh.

◆ size_type

typedef size_t PTL::VTask::size_type

Definition at line 58 of file VTask.hh.

◆ this_type

Definition at line 59 of file VTask.hh.

◆ tid_type

typedef std::thread::id PTL::VTask::tid_type

Definition at line 57 of file VTask.hh.

◆ void_func_t

typedef std::function<void()> PTL::VTask::void_func_t

Definition at line 63 of file VTask.hh.

Constructor & Destructor Documentation

◆ VTask() [1/3]

VTask::VTask ( )

Definition at line 40 of file VTask.cc.

41: m_depth(0)
42, m_group(nullptr)
43, m_pool(nullptr)
44{}
VTaskGroup * m_group
Definition: VTask.hh:101
ThreadPool * m_pool
Definition: VTask.hh:102
intmax_t m_depth
Definition: VTask.hh:100

◆ VTask() [2/3]

VTask::VTask ( VTaskGroup task_group)
explicit

Definition at line 48 of file VTask.cc.

49: m_depth(0)
50, m_group(task_group)
51, m_pool((m_group) ? task_group->pool() : nullptr)
52{}
ThreadPool *& pool()
Definition: VTaskGroup.hh:110

◆ VTask() [3/3]

VTask::VTask ( ThreadPool pool)
explicit

Definition at line 56 of file VTask.cc.

57: m_depth(0)
58, m_group(nullptr)
59, m_pool(tp)
60{}

◆ ~VTask()

VTask::~VTask ( )
virtual

Definition at line 64 of file VTask.cc.

64{}

Member Function Documentation

◆ begin() [1/2]

iterator PTL::VTask::begin ( )
inline

Definition at line 84 of file VTask.hh.

84{ return this; }

◆ begin() [2/2]

const_iterator PTL::VTask::begin ( ) const
inline

Definition at line 87 of file VTask.hh.

87{ return this; }

◆ cbegin()

const_iterator PTL::VTask::cbegin ( ) const
inline

Definition at line 90 of file VTask.hh.

90{ return this; }

◆ cend()

const_iterator PTL::VTask::cend ( ) const
inline

Definition at line 91 of file VTask.hh.

91{ return this + 1; }

◆ depth() [1/2]

intmax_t & PTL::VTask::depth ( )
inline

Definition at line 93 of file VTask.hh.

93{ return m_depth; }

◆ depth() [2/2]

const intmax_t & PTL::VTask::depth ( ) const
inline

Definition at line 94 of file VTask.hh.

94{ return m_depth; }

◆ end() [1/2]

iterator PTL::VTask::end ( )
inline

Definition at line 85 of file VTask.hh.

85{ return this + 1; }

◆ end() [2/2]

const_iterator PTL::VTask::end ( ) const
inline

Definition at line 88 of file VTask.hh.

88{ return this + 1; }

◆ group()

VTaskGroup * PTL::VTask::group ( ) const
inline

Definition at line 80 of file VTask.hh.

80{ return m_group; }

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

◆ is_native_task()

bool VTask::is_native_task ( ) const
virtual

Reimplemented in PTL::PackagedTask< RetT, Args >, PTL::Task< RetT, Args >, PTL::Task< RetT, void >, and PTL::Task< void, void >.

Definition at line 95 of file VTask.cc.

96{
97 return (m_group) ? m_group->is_native_task_group() : false;
98}
virtual bool is_native_task_group() const
Definition: VTaskGroup.hh:114

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

◆ operator()()

virtual void PTL::VTask::operator() ( )
pure virtual

◆ operator--()

void VTask::operator-- ( )

Definition at line 69 of file VTask.cc.

70{
71 if(m_group)
72 {
73 intmax_t _count = --(*m_group);
74 if(_count < 2)
75 {
76 try
77 {
78 m_group->task_cond()->notify_all();
79 } catch(std::system_error& e)
80 {
82 AutoLock l(TypeMutex<decltype(std::cerr)>(), std::defer_lock);
83 if(!l.owns_lock())
84 l.lock();
85 std::cerr << "[" << tid << "] Caught system error: " << e.what()
86 << std::endl;
87 }
88 }
89 }
90}
static uintmax_t get_this_thread_id()
Definition: ThreadPool.cc:120
std::shared_ptr< condition_t > task_cond()
Definition: VTaskGroup.hh:103
Mutex & TypeMutex(const unsigned int &_n=0)
Definition: Threading.hh:118

Referenced by PTL::Task< RetT, Args >::operator()(), PTL::Task< RetT, void >::operator()(), and PTL::Task< void, void >::operator()().

◆ pool()

ThreadPool * VTask::pool ( ) const
virtual

Definition at line 103 of file VTask.cc.

104{
105 return (!m_pool && m_group) ? m_group->pool() : m_pool;
106}

◆ this_tid()

static tid_type PTL::VTask::this_tid ( )
inlinestaticprotected

Definition at line 97 of file VTask.hh.

97{ return std::this_thread::get_id(); }

Member Data Documentation

◆ m_depth

intmax_t PTL::VTask::m_depth
protected

Definition at line 100 of file VTask.hh.

Referenced by depth().

◆ m_func

void_func_t PTL::VTask::m_func = []() {}
protected

Definition at line 103 of file VTask.hh.

◆ m_group

VTaskGroup* PTL::VTask::m_group
protected

Definition at line 101 of file VTask.hh.

Referenced by group(), is_native_task(), operator--(), and pool().

◆ m_pool

ThreadPool* PTL::VTask::m_pool
protected

Definition at line 102 of file VTask.hh.

Referenced by pool().


The documentation for this class was generated from the following files: