CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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() : m_refCount{0} {}
37  virtual ~TaskBase() = default;
38 
39  virtual void execute() = 0;
40 
42  unsigned int decrement_ref_count() { 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) : 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
virtual void execute()=0
TaskBase * m_task
Definition: TaskBase.h:61
TaskSentry(TaskBase *iTask)
Definition: TaskBase.h:52
virtual void recycle()
Definition: TaskBase.h:45
TaskSentry()=delete
virtual ~TaskBase()=default
std::atomic< unsigned int > m_refCount
Definition: TaskBase.h:47
TaskBase()
Constructor.
Definition: TaskBase.h:36
unsigned int decrement_ref_count()
Definition: TaskBase.h:42
TaskSentry operator=(TaskSentry const &)=delete
void increment_ref_count()
Definition: TaskBase.h:41