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)
 
oneapi::tbb::task_group * group () const
 
bool hasTask () const noexcept
 
WaitingTaskHolder makeWaitingTaskHolderAndRelease ()
 
WaitingTaskWithArenaHolderoperator= (const WaitingTaskWithArenaHolder &iRHS)
 
WaitingTaskWithArenaHolderoperator= (WaitingTaskWithArenaHolder &&iRHS)
 
bool taskHasFailed () const noexcept
 
 WaitingTaskWithArenaHolder ()
 
 WaitingTaskWithArenaHolder (oneapi::tbb::task_group &, WaitingTask *iTask)
 
 WaitingTaskWithArenaHolder (WaitingTaskHolder &&iTask)
 
 WaitingTaskWithArenaHolder (WaitingTaskWithArenaHolder const &iHolder)
 
 WaitingTaskWithArenaHolder (WaitingTaskWithArenaHolder &&iOther)
 
 ~WaitingTaskWithArenaHolder ()
 

Private Attributes

std::shared_ptr< oneapi::tbb::task_arena > m_arena
 
oneapi::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 ( oneapi::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),
23  m_group(&iGroup),
24  m_arena(std::make_shared<oneapi::tbb::task_arena>(oneapi::tbb::task_arena::attach())) {
26  }
std::shared_ptr< oneapi::tbb::task_arena > m_arena
void increment_ref_count()
Definition: TaskBase.h:41

◆ WaitingTaskWithArenaHolder() [3/5]

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

Definition at line 28 of file WaitingTaskWithArenaHolder.cc.

29  : m_task(iTask.release_no_decrement()),
30  m_group(iTask.group()),
31  m_arena(std::make_shared<oneapi::tbb::task_arena>(oneapi::tbb::task_arena::attach())) {}
std::shared_ptr< oneapi::tbb::task_arena > m_arena

◆ ~WaitingTaskWithArenaHolder()

edm::WaitingTaskWithArenaHolder::~WaitingTaskWithArenaHolder ( )

Definition at line 33 of file WaitingTaskWithArenaHolder.cc.

References doneWaiting(), and m_task.

33  {
34  if (m_task) {
35  doneWaiting(std::exception_ptr{});
36  }
37  }
void doneWaiting(std::exception_ptr iExcept)

◆ WaitingTaskWithArenaHolder() [4/5]

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

Definition at line 39 of file WaitingTaskWithArenaHolder.cc.

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

40  : m_task(iHolder.m_task), m_group(iHolder.m_group), m_arena(iHolder.m_arena) {
41  if (LIKELY(m_task != nullptr)) {
43  }
44  }
#define LIKELY(x)
Definition: Likely.h:20
std::shared_ptr< oneapi::tbb::task_arena > m_arena
void increment_ref_count()
Definition: TaskBase.h:41

◆ WaitingTaskWithArenaHolder() [5/5]

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

Definition at line 46 of file WaitingTaskWithArenaHolder.cc.

47  : m_task(iOther.m_task), m_group(iOther.m_group), m_arena(std::move(iOther.m_arena)) {
48  iOther.m_task = nullptr;
49  }
std::shared_ptr< oneapi::tbb::task_arena > m_arena
def move(src, dest)
Definition: eostools.py:511

Member Function Documentation

◆ doneWaiting()

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

Definition at line 71 of file WaitingTaskWithArenaHolder.cc.

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

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

71  {
72  if (iExcept) {
73  m_task->dependentTaskFailed(iExcept);
74  }
75  //enqueue can run the task before we finish
76  // doneWaiting and some other thread might
77  // try to reuse this object. Resetting
78  // before enqueue avoids problems
79  auto task = m_task;
80  m_task = nullptr;
81  if (0 == task->decrement_ref_count()) {
82  // The enqueue call will cause a worker thread to be created in
83  // the arena if there is not one already.
84  m_arena->enqueue([task = task, group = m_group]() {
85  group->run([task]() {
86  TaskSentry s(task);
87  task->execute();
88  });
89  });
90  }
91  }
std::shared_ptr< oneapi::tbb::task_arena > m_arena
void dependentTaskFailed(std::exception_ptr iPtr)
Called if waited for task failed.
Definition: WaitingTask.h:68
oneapi::tbb::task_group * group() const

◆ group()

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

since oneapi::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; }

◆ hasTask()

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

Definition at line 114 of file WaitingTaskWithArenaHolder.cc.

References m_task.

114 { return m_task != nullptr; }

◆ makeWaitingTaskHolderAndRelease()

WaitingTaskHolder edm::WaitingTaskWithArenaHolder::makeWaitingTaskHolderAndRelease ( )

Definition at line 105 of file WaitingTaskWithArenaHolder.cc.

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

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

105  {
106  WaitingTaskHolder holder(*m_group, m_task);
108  m_task = nullptr;
109  return holder;
110  }
unsigned int decrement_ref_count()
Definition: TaskBase.h:42

◆ operator=() [1/2]

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

Definition at line 51 of file WaitingTaskWithArenaHolder.cc.

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

51  {
53  std::swap(m_task, tmp.m_task);
54  std::swap(m_group, tmp.m_group);
55  std::swap(m_arena, tmp.m_arena);
56  return *this;
57  }
std::shared_ptr< oneapi::tbb::task_arena > m_arena
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
tmp
align.sh
Definition: createJobs.py:716

◆ operator=() [2/2]

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

Definition at line 59 of file WaitingTaskWithArenaHolder.cc.

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

59  {
61  std::swap(m_task, tmp.m_task);
62  std::swap(m_group, tmp.m_group);
63  std::swap(m_arena, tmp.m_arena);
64  return *this;
65  }
std::shared_ptr< oneapi::tbb::task_arena > m_arena
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
tmp
align.sh
Definition: createJobs.py:716
def move(src, dest)
Definition: eostools.py:511

◆ taskHasFailed()

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

Definition at line 112 of file WaitingTaskWithArenaHolder.cc.

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

112 { return static_cast<bool>(m_task->exceptionPtr()); }
std::exception_ptr exceptionPtr() const
Returns exception thrown by dependent task.
Definition: WaitingTask.h:51

Member Data Documentation

◆ m_arena

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

Definition at line 89 of file WaitingTaskWithArenaHolder.h.

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

◆ m_group

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

◆ m_task

WaitingTask* edm::WaitingTaskWithArenaHolder::m_task
private