Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PTL::TaskSubQueue Class Reference

#include <TaskSubQueue.hh>

Public Types

template<typename Tp >
using container = std::list< Tp >
 
using task_pointer = std::shared_ptr< VTask >
 
using container_type = container< task_pointer >
 
using size_type = container_type::size_type
 

Public Member Functions

 TaskSubQueue (std::atomic_uintmax_t *_ntasks)
 
 TaskSubQueue (const TaskSubQueue &)
 
 ~TaskSubQueue ()=default
 
TaskSubQueueoperator= (const TaskSubQueue &)=delete
 
int GetId () const
 
bool AcquireClaim ()
 
void ReleaseClaim ()
 
void PushTask (task_pointer &&) PTL_NO_SANITIZE_THREAD
 
task_pointer PopTask (bool front=true) PTL_NO_SANITIZE_THREAD
 
size_type size () const
 
bool empty () const
 

Detailed Description

Definition at line 37 of file TaskSubQueue.hh.

Member Typedef Documentation

◆ container

template<typename Tp >
using PTL::TaskSubQueue::container = std::list<Tp>

Definition at line 41 of file TaskSubQueue.hh.

◆ container_type

◆ size_type

using PTL::TaskSubQueue::size_type = container_type::size_type

Definition at line 45 of file TaskSubQueue.hh.

◆ task_pointer

using PTL::TaskSubQueue::task_pointer = std::shared_ptr<VTask>

Definition at line 43 of file TaskSubQueue.hh.

Constructor & Destructor Documentation

◆ TaskSubQueue() [1/2]

PTL::TaskSubQueue::TaskSubQueue ( std::atomic_uintmax_t *  _ntasks)
inline

Definition at line 83 of file TaskSubQueue.hh.

84: m_ntasks(0)
85, m_available(true)
86, m_all_tasks(_ntasks)
87{}

◆ TaskSubQueue() [2/2]

PTL::TaskSubQueue::TaskSubQueue ( const TaskSubQueue rhs)
inline

Definition at line 91 of file TaskSubQueue.hh.

92: m_ntasks(0)
93, m_available(true)
94, m_all_tasks(rhs.m_all_tasks)
95{}

◆ ~TaskSubQueue()

PTL::TaskSubQueue::~TaskSubQueue ( )
default

Member Function Documentation

◆ AcquireClaim()

bool PTL::TaskSubQueue::AcquireClaim ( )
inline

Definition at line 100 of file TaskSubQueue.hh.

101{
102 bool is_avail = m_available.load(std::memory_order_relaxed);
103 if(!is_avail)
104 return false;
105 return m_available.compare_exchange_strong(is_avail, false,
106 std::memory_order_relaxed);
107}

Referenced by PTL::UserTaskQueue::GetTask(), PTL::UserTaskQueue::GetThreadBinTask(), and PTL::UserTaskQueue::InsertTask().

◆ empty()

bool PTL::TaskSubQueue::empty ( ) const
inline

Definition at line 130 of file TaskSubQueue.hh.

131{
132 return (m_ntasks.load() == 0);
133}

Referenced by PTL::UserTaskQueue::GetTask(), and PTL::UserTaskQueue::GetThreadBinTask().

◆ GetId()

int PTL::TaskSubQueue::GetId ( ) const

◆ operator=()

TaskSubQueue & PTL::TaskSubQueue::operator= ( const TaskSubQueue )
delete

◆ PopTask()

TaskSubQueue::task_pointer PTL::TaskSubQueue::PopTask ( bool  front = true)
inline

Definition at line 152 of file TaskSubQueue.hh.

153{
154 // no need to lock -- claim is acquired via atomic
155 assert(m_available.load(std::memory_order_relaxed) == false);
156 if(m_ntasks.load() == 0)
157 return nullptr;
158
159 task_pointer _task{ nullptr };
160 if(front)
161 {
162#if defined(PTL_USE_LOCKS)
163 AutoLock lk{ m_mutex };
164#endif
165 _task = std::move(m_task_queue.front());
166 m_task_queue.pop_front();
167 }
168 else
169 {
170#if defined(PTL_USE_LOCKS)
171 AutoLock lk{ m_mutex };
172#endif
173 _task = std::move(m_task_queue.back());
174 m_task_queue.pop_back();
175 }
176 --m_ntasks;
177
178 return _task;
179}
std::shared_ptr< VTask > task_pointer
Definition: TaskSubQueue.hh:43
TemplateAutoLock< Mutex > AutoLock
Definition: AutoLock.hh:479

Referenced by PTL::UserTaskQueue::GetTask(), and PTL::UserTaskQueue::GetThreadBinTask().

◆ PushTask()

void PTL::TaskSubQueue::PushTask ( task_pointer &&  task)
inline

Definition at line 138 of file TaskSubQueue.hh.

139{
140 // no need to lock these if claim is acquired via atomic
141 assert(m_available.load(std::memory_order_relaxed) == false);
142 ++m_ntasks;
143#if defined(PTL_USE_LOCKS)
144 AutoLock lk{ m_mutex };
145#endif
146 m_task_queue.emplace_front(std::move(task));
147}

Referenced by PTL::UserTaskQueue::InsertTask().

◆ ReleaseClaim()

void PTL::TaskSubQueue::ReleaseClaim ( )
inline

Definition at line 112 of file TaskSubQueue.hh.

113{
114 // if(m_available.load(std::memory_order_relaxed))
115 // return;
116 m_available.store(true, std::memory_order_release);
117}

Referenced by PTL::UserTaskQueue::GetTask(), PTL::UserTaskQueue::GetThreadBinTask(), and PTL::UserTaskQueue::InsertTask().

◆ size()

TaskSubQueue::size_type PTL::TaskSubQueue::size ( ) const
inline

Definition at line 122 of file TaskSubQueue.hh.

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

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