File indexing completed on 2023-03-17 11:01:50
0001 #ifndef FWCore_Concurrency_TaskBase_h
0002 #define FWCore_Concurrency_TaskBase_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <atomic>
0023 #include <exception>
0024 #include <memory>
0025
0026
0027
0028
0029
0030 namespace edm {
0031 class TaskBase {
0032 public:
0033 friend class TaskSentry;
0034
0035
0036 TaskBase() : m_refCount{0} {}
0037 virtual ~TaskBase() = default;
0038
0039 virtual void execute() = 0;
0040
0041 void increment_ref_count() { ++m_refCount; }
0042 unsigned int decrement_ref_count() { return --m_refCount; }
0043
0044 private:
0045 virtual void recycle() { delete this; }
0046
0047 std::atomic<unsigned int> m_refCount{0};
0048 };
0049
0050 class TaskSentry {
0051 public:
0052 TaskSentry(TaskBase* iTask) : m_task{iTask} {}
0053 ~TaskSentry() { m_task->recycle(); }
0054 TaskSentry() = delete;
0055 TaskSentry(TaskSentry const&) = delete;
0056 TaskSentry(TaskSentry&&) = delete;
0057 TaskSentry operator=(TaskSentry const&) = delete;
0058 TaskSentry operator=(TaskSentry&&) = delete;
0059
0060 private:
0061 TaskBase* m_task;
0062 };
0063 }
0064
0065 #endif