CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 const &iHolder)
 
 WaitingTaskWithArenaHolder (WaitingTaskWithArenaHolder &&iOther)
 
 ~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

edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( )

Definition at line 16 of file WaitingTaskWithArenaHolder.cc.

16 : m_task(nullptr) {}
edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( tbb::task_group &  iGroup,
WaitingTask iTask 
)
explicit

Definition at line 21 of file WaitingTaskWithArenaHolder.cc.

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

22  : m_task(iTask), m_group(&iGroup), m_arena(std::make_shared<tbb::task_arena>(tbb::task_arena::attach())) {
24  }
std::shared_ptr< tbb::task_arena > m_arena
void increment_ref_count()
Definition: TaskBase.h:41
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())) {}
std::shared_ptr< tbb::task_arena > m_arena
edm::WaitingTaskWithArenaHolder::~WaitingTaskWithArenaHolder ( )

Definition at line 31 of file WaitingTaskWithArenaHolder.cc.

References doneWaiting(), and m_task.

31  {
32  if (m_task) {
33  doneWaiting(std::exception_ptr{});
34  }
35  }
void doneWaiting(std::exception_ptr iExcept)
edm::WaitingTaskWithArenaHolder::WaitingTaskWithArenaHolder ( WaitingTaskWithArenaHolder const &  iHolder)

Definition at line 37 of file WaitingTaskWithArenaHolder.cc.

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

38  : m_task(iHolder.m_task), m_group(iHolder.m_group), m_arena(iHolder.m_arena) {
39  if (LIKELY(m_task != nullptr)) {
41  }
42  }
#define LIKELY(x)
Definition: Likely.h:20
std::shared_ptr< tbb::task_arena > m_arena
void increment_ref_count()
Definition: TaskBase.h:41
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  }
def move
Definition: eostools.py:511
std::shared_ptr< tbb::task_arena > m_arena

Member Function Documentation

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

Definition at line 69 of file WaitingTaskWithArenaHolder.cc.

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

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

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  }
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:59
std::shared_ptr< tbb::task_arena > m_arena
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.

References m_group.

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

83 { return m_group; }
bool edm::WaitingTaskWithArenaHolder::hasTask ( ) const
noexcept

Definition at line 112 of file WaitingTaskWithArenaHolder.cc.

References m_task.

112 { return m_task != nullptr; }
WaitingTaskHolder edm::WaitingTaskWithArenaHolder::makeWaitingTaskHolderAndRelease ( )

Definition at line 103 of file WaitingTaskWithArenaHolder.cc.

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

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

103  {
104  WaitingTaskHolder holder(*m_group, m_task);
106  m_task = nullptr;
107  return holder;
108  }
unsigned int decrement_ref_count()
Definition: TaskBase.h:42
WaitingTaskWithArenaHolder & edm::WaitingTaskWithArenaHolder::operator= ( const WaitingTaskWithArenaHolder iRHS)

Definition at line 49 of file WaitingTaskWithArenaHolder.cc.

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

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  }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
tmp
align.sh
Definition: createJobs.py:716
std::shared_ptr< tbb::task_arena > m_arena
WaitingTaskWithArenaHolder & edm::WaitingTaskWithArenaHolder::operator= ( WaitingTaskWithArenaHolder &&  iRHS)

Definition at line 57 of file WaitingTaskWithArenaHolder.cc.

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

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  }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
def move
Definition: eostools.py:511
tmp
align.sh
Definition: createJobs.py:716
std::shared_ptr< tbb::task_arena > m_arena
bool edm::WaitingTaskWithArenaHolder::taskHasFailed ( ) const
noexcept

Definition at line 110 of file WaitingTaskWithArenaHolder.cc.

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

110 { return m_task->exceptionPtr() != nullptr; }
std::exception_ptr const * exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51

Member Data Documentation

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

Definition at line 89 of file WaitingTaskWithArenaHolder.h.

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

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