CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::WaitingTaskWithArenaHolder Class Reference

#include <WaitingTaskWithArenaHolder.h>

Public Member Functions

void doneWaiting (std::exception_ptr iExcept)
 
tbb::task_group * group () const
 
bool hasTask () const noexcept
 
WaitingTaskHolder makeWaitingTaskHolderAndRelease ()
 
WaitingTaskWithArenaHolderoperator= (const WaitingTaskWithArenaHolder &iRHS)
 
WaitingTaskWithArenaHolderoperator= (WaitingTaskWithArenaHolder &&iRHS)
 
bool taskHasFailed () const noexcept
 
 WaitingTaskWithArenaHolder ()
 
 WaitingTaskWithArenaHolder (tbb::task_group &, WaitingTask *iTask)
 
 WaitingTaskWithArenaHolder (WaitingTaskHolder &&iTask)
 
 WaitingTaskWithArenaHolder (WaitingTaskWithArenaHolder &&iOther)
 
 WaitingTaskWithArenaHolder (WaitingTaskWithArenaHolder const &iHolder)
 
 ~WaitingTaskWithArenaHolder ()
 

Private Attributes

std::shared_ptr< tbb::task_arena > m_arena
 
tbb::task_group * m_group
 
WaitingTaskm_task
 

Detailed Description

Description: This holds a WaitingTask and can be passed to something the WaitingTask is waiting for. That allows that something to call doneWaiting to let the WaitingTask know it can run. The use of the arena allows one to call doneWaiting from a thread external to the arena where the task should run. The external thread might be a non-TBB thread.

Definition at line 34 of file WaitingTaskWithArenaHolder.h.

Constructor & Destructor Documentation

◆ WaitingTaskWithArenaHolder() [1/5]

edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( )

Definition at line 16 of file WaitingTaskWithArenaHolder.cc.

16 : m_task(nullptr) {}

◆ WaitingTaskWithArenaHolder() [2/5]

edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( tbb::task_group &  iGroup,
WaitingTask iTask 
)
explicit

Definition at line 21 of file WaitingTaskWithArenaHolder.cc.

22  : m_task(iTask), m_group(&iGroup), m_arena(std::make_shared<tbb::task_arena>(tbb::task_arena::attach())) {
24  }

References edm::TaskBase::increment_ref_count(), and m_task.

◆ WaitingTaskWithArenaHolder() [3/5]

edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( WaitingTaskHolder &&  iTask)
explicit

Definition at line 26 of file WaitingTaskWithArenaHolder.cc.

27  : m_task(iTask.release_no_decrement()),
28  m_group(iTask.group()),
29  m_arena(std::make_shared<tbb::task_arena>(tbb::task_arena::attach())) {}

◆ ~WaitingTaskWithArenaHolder()

edm::WaitingTaskWithArenaHolder::~WaitingTaskWithArenaHolder ( )

Definition at line 31 of file WaitingTaskWithArenaHolder.cc.

31  {
32  if (m_task) {
33  doneWaiting(std::exception_ptr{});
34  }
35  }

References doneWaiting(), and m_task.

◆ WaitingTaskWithArenaHolder() [4/5]

edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( WaitingTaskWithArenaHolder const &  iHolder)

Definition at line 37 of file WaitingTaskWithArenaHolder.cc.

38  : m_task(iHolder.m_task), m_group(iHolder.m_group), m_arena(iHolder.m_arena) {
39  if (LIKELY(m_task != nullptr)) {
41  }
42  }

References edm::TaskBase::increment_ref_count(), LIKELY, and m_task.

◆ WaitingTaskWithArenaHolder() [5/5]

edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( WaitingTaskWithArenaHolder &&  iOther)

Definition at line 44 of file WaitingTaskWithArenaHolder.cc.

45  : m_task(iOther.m_task), m_group(iOther.m_group), m_arena(std::move(iOther.m_arena)) {
46  iOther.m_task = nullptr;
47  }

Member Function Documentation

◆ doneWaiting()

void edm::WaitingTaskWithArenaHolder::doneWaiting ( std::exception_ptr  iExcept)

Definition at line 69 of file WaitingTaskWithArenaHolder.cc.

69  {
70  if (iExcept) {
71  m_task->dependentTaskFailed(iExcept);
72  }
73  //enqueue can run the task before we finish
74  // doneWaiting and some other thread might
75  // try to reuse this object. Resetting
76  // before enqueue avoids problems
77  auto task = m_task;
78  m_task = nullptr;
79  if (0 == task->decrement_ref_count()) {
80  // The enqueue call will cause a worker thread to be created in
81  // the arena if there is not one already.
82  m_arena->enqueue([task = task, group = m_group]() {
83  group->run([task]() {
84  TaskSentry s(task);
85  task->execute();
86  });
87  });
88  }
89  }

References edm::WaitingTask::dependentTaskFailed(), group(), m_arena, m_group, m_task, alignCSCRings::s, and TrackValidation_cff::task.

Referenced by edm::Worker::runAcquireAfterAsyncPrefetch(), and ~WaitingTaskWithArenaHolder().

◆ group()

tbb::task_group* edm::WaitingTaskWithArenaHolder::group ( ) const
inline

since tbb::task_group is thread safe, we can return it non-const from here since the object is not really part of the state of the holder

Definition at line 83 of file WaitingTaskWithArenaHolder.h.

83 { return m_group; }

References m_group.

Referenced by doneWaiting(), and cms::cuda::impl::ScopedContextHolderHelper::pushNextTask().

◆ hasTask()

bool edm::WaitingTaskWithArenaHolder::hasTask ( ) const
noexcept

Definition at line 112 of file WaitingTaskWithArenaHolder.cc.

112 { return m_task != nullptr; }

References m_task.

◆ makeWaitingTaskHolderAndRelease()

WaitingTaskHolder edm::WaitingTaskWithArenaHolder::makeWaitingTaskHolderAndRelease ( )

Definition at line 103 of file WaitingTaskWithArenaHolder.cc.

103  {
104  WaitingTaskHolder holder(*m_group, m_task);
106  m_task = nullptr;
107  return holder;
108  }

References edm::TaskBase::decrement_ref_count(), m_group, and m_task.

Referenced by evf::GlobalEvFOutputModule::acquire().

◆ operator=() [1/2]

WaitingTaskWithArenaHolder & edm::WaitingTaskWithArenaHolder::operator= ( const WaitingTaskWithArenaHolder iRHS)

Definition at line 49 of file WaitingTaskWithArenaHolder.cc.

49  {
51  std::swap(m_task, tmp.m_task);
52  std::swap(m_group, tmp.m_group);
53  std::swap(m_arena, tmp.m_arena);
54  return *this;
55  }

References m_arena, m_group, m_task, std::swap(), and createJobs::tmp.

◆ operator=() [2/2]

WaitingTaskWithArenaHolder & edm::WaitingTaskWithArenaHolder::operator= ( WaitingTaskWithArenaHolder &&  iRHS)

Definition at line 57 of file WaitingTaskWithArenaHolder.cc.

57  {
59  std::swap(m_task, tmp.m_task);
60  std::swap(m_group, tmp.m_group);
61  std::swap(m_arena, tmp.m_arena);
62  return *this;
63  }

References m_arena, m_group, m_task, eostools::move(), std::swap(), and createJobs::tmp.

◆ taskHasFailed()

bool edm::WaitingTaskWithArenaHolder::taskHasFailed ( ) const
noexcept

Definition at line 110 of file WaitingTaskWithArenaHolder.cc.

110 { return m_task->exceptionPtr() != nullptr; }

References edm::WaitingTask::exceptionPtr(), and m_task.

Member Data Documentation

◆ m_arena

std::shared_ptr<tbb::task_arena> edm::WaitingTaskWithArenaHolder::m_arena
private

Definition at line 89 of file WaitingTaskWithArenaHolder.h.

Referenced by doneWaiting(), and operator=().

◆ m_group

tbb::task_group* edm::WaitingTaskWithArenaHolder::m_group
private

◆ m_task

WaitingTask* edm::WaitingTaskWithArenaHolder::m_task
private
edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder
WaitingTaskWithArenaHolder()
Definition: WaitingTaskWithArenaHolder.cc:16
edm::WaitingTaskWithArenaHolder::m_task
WaitingTask * m_task
Definition: WaitingTaskWithArenaHolder.h:87
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::WaitingTaskWithArenaHolder::group
tbb::task_group * group() const
Definition: WaitingTaskWithArenaHolder.h:83
edm::WaitingTaskWithArenaHolder::m_arena
std::shared_ptr< tbb::task_arena > m_arena
Definition: WaitingTaskWithArenaHolder.h:89
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::WaitingTask::exceptionPtr
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:253
WaitingTaskHolder
edm::WaitingTaskWithArenaHolder::m_group
tbb::task_group * m_group
Definition: WaitingTaskWithArenaHolder.h:88
edm::WaitingTask::dependentTaskFailed
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
edm::TaskBase::increment_ref_count
void increment_ref_count()
Definition: TaskBase.h:41
edm::TaskBase::decrement_ref_count
unsigned int decrement_ref_count()
Definition: TaskBase.h:42
eostools.move
def move(src, dest)
Definition: eostools.py:511
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
edm::WaitingTaskWithArenaHolder::doneWaiting
void doneWaiting(std::exception_ptr iExcept)
Definition: WaitingTaskWithArenaHolder.cc:69