-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTaskBase.h
65 lines (51 loc) · 1.35 KB
/
TaskBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef FWCore_Concurrency_TaskBase_h
#define FWCore_Concurrency_TaskBase_h
// -*- C++ -*-
//
// Package: Concurrency
// Class : TaskBase
//
/**\class TaskBase TaskBase.h FWCore/Concurrency/interface/TaskBase.h
Description: Base class for tasks.
Usage:
Used as a callback to happen after a task has been completed.
*/
//
// Original Author: Chris Jones
// Created: Tue Jan 5 13:46:31 CST 2020
// $Id$
//
// system include files
#include <atomic>
#include <exception>
#include <memory>
// user include files
// forward declarations
namespace edm {
class TaskBase {
public:
friend class TaskSentry;
///Constructor
TaskBase() : m_refCount{0} {}
virtual ~TaskBase() = default;
virtual void execute() = 0;
void increment_ref_count() { ++m_refCount; }
unsigned int decrement_ref_count() { return --m_refCount; }
private:
virtual void recycle() { delete this; }
std::atomic<unsigned int> m_refCount{0};
};
class TaskSentry {
public:
TaskSentry(TaskBase* iTask) : m_task{iTask} {}
~TaskSentry() { m_task->recycle(); }
TaskSentry() = delete;
TaskSentry(TaskSentry const&) = delete;
TaskSentry(TaskSentry&&) = delete;
TaskSentry operator=(TaskSentry const&) = delete;
TaskSentry operator=(TaskSentry&&) = delete;
private:
TaskBase* m_task;
};
} // namespace edm
#endif