CMS 3D CMS Logo

TaskBase.h
Go to the documentation of this file.
1 #ifndef FWCore_Concurrency_TaskBase_h
2 #define FWCore_Concurrency_TaskBase_h
3 // -*- C++ -*-
4 //
5 // Package: Concurrency
6 // Class : TaskBase
7 //
15 //
16 // Original Author: Chris Jones
17 // Created: Tue Jan 5 13:46:31 CST 2020
18 // $Id$
19 //
20 
21 // system include files
22 #include <atomic>
23 #include <exception>
24 #include <memory>
25 
26 // user include files
27 
28 // forward declarations
29 
30 namespace edm {
31  class TaskBase {
32  public:
33  friend class TaskSentry;
34 
36  TaskBase() noexcept : m_refCount{0} {}
37  virtual ~TaskBase() noexcept = default;
38 
39  virtual void execute() = 0;
40 
41  void increment_ref_count() noexcept { ++m_refCount; }
42  unsigned int decrement_ref_count() noexcept { return --m_refCount; }
43 
44  private:
45  virtual void recycle() { delete this; }
46 
47  std::atomic<unsigned int> m_refCount{0};
48  };
49 
50  class TaskSentry {
51  public:
52  TaskSentry(TaskBase* iTask) noexcept : m_task{iTask} {}
54  TaskSentry() = delete;
55  TaskSentry(TaskSentry const&) = delete;
56  TaskSentry(TaskSentry&&) = delete;
57  TaskSentry operator=(TaskSentry const&) = delete;
58  TaskSentry operator=(TaskSentry&&) = delete;
59 
60  private:
62  };
63 } // namespace edm
64 
65 #endif
void increment_ref_count() noexcept
Definition: TaskBase.h:41
virtual void execute()=0
TaskBase() noexcept
Constructor.
Definition: TaskBase.h:36
virtual ~TaskBase() noexcept=default
TaskSentry(TaskBase *iTask) noexcept
Definition: TaskBase.h:52
TaskBase * m_task
Definition: TaskBase.h:61
virtual void recycle()
Definition: TaskBase.h:45
TaskSentry()=delete
unsigned int decrement_ref_count() noexcept
Definition: TaskBase.h:42
std::atomic< unsigned int > m_refCount
Definition: TaskBase.h:47
HLT enums.
TaskSentry operator=(TaskSentry const &)=delete