CMS 3D CMS Logo

WorkerMonitorThread.h
Go to the documentation of this file.
1 #ifndef FWCore_SharedMemory_WorkerMonitorThread_h
2 #define FWCore_SharedMemory_WorkerMonitorThread_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/SharedMemory
6 // Class : WorkerMonitorThread
7 //
15 //
16 // Original Author: Chris Jones
17 // Created: 21/01/2020
18 //
19 
20 // system include files
21 #include <atomic>
22 #include <csignal>
23 #include <functional>
24 #include <thread>
25 
26 // user include files
28 
29 // forward declarations
30 
31 namespace edm::shared_memory {
33  public:
36  if (not stopRequested_.load()) {
37  stop();
38  }
39  }
41  const WorkerMonitorThread& operator=(const WorkerMonitorThread&) = delete;
44 
45  // ---------- const member functions ---------------------
46 
47  // ---------- member functions ---------------------------
48  void setAction(std::function<void()> iFunc) {
49  action_ = std::move(iFunc);
50  actionSet_.store(true);
51  }
52 
53  void startThread();
54 
56  void setupSignalHandling();
57 
58  void stop();
59 
60  private:
61  static void sig_handler(int sig, siginfo_t*, void*);
62  void run();
63  // ---------- member data --------------------------------
64  std::atomic<bool> stopRequested_ = false;
65  std::atomic<bool> helperReady_ = false;
66  std::atomic<bool> actionSet_ = false;
68 
69  static std::atomic<int> s_pipeReadEnd;
70  static std::atomic<int> s_pipeWriteEnd;
71  static std::atomic<bool> s_helperThreadDone;
72 
73  std::thread helperThread_;
74  };
75 } // namespace edm::shared_memory
76 
77 #endif
edm::shared_memory::WorkerMonitorThread::helperReady_
std::atomic< bool > helperReady_
Definition: WorkerMonitorThread.h:65
edm::shared_memory::WorkerMonitorThread::s_helperThreadDone
static std::atomic< bool > s_helperThreadDone
Definition: WorkerMonitorThread.h:71
edm::shared_memory::WorkerMonitorThread::WorkerMonitorThread
WorkerMonitorThread()
Definition: WorkerMonitorThread.h:34
edm::shared_memory::WorkerMonitorThread::helperThread_
std::thread helperThread_
Definition: WorkerMonitorThread.h:73
edm::shared_memory::WorkerMonitorThread
Definition: WorkerMonitorThread.h:32
edm::shared_memory::WorkerMonitorThread::~WorkerMonitorThread
~WorkerMonitorThread()
Definition: WorkerMonitorThread.h:35
edm::shared_memory::WorkerMonitorThread::setupSignalHandling
void setupSignalHandling()
Sets the unix signal handler which communicates with the thread.
Definition: WorkerMonitorThread.cc:102
edm::shared_memory::WorkerMonitorThread::stop
void stop()
Definition: WorkerMonitorThread.cc:114
edm::shared_memory::WorkerMonitorThread::action_
std::function< void()> action_
Definition: WorkerMonitorThread.h:67
edm::shared_memory::WorkerMonitorThread::startThread
void startThread()
Definition: WorkerMonitorThread.cc:78
edm::shared_memory::WorkerMonitorThread::stopRequested_
std::atomic< bool > stopRequested_
Definition: WorkerMonitorThread.h:64
edm::shared_memory::WorkerMonitorThread::setAction
void setAction(std::function< void()> iFunc)
Definition: WorkerMonitorThread.h:48
edm::shared_memory::WorkerMonitorThread::actionSet_
std::atomic< bool > actionSet_
Definition: WorkerMonitorThread.h:66
thread_safety_macros.h
edm::shared_memory::WorkerMonitorThread::sig_handler
static void sig_handler(int sig, siginfo_t *, void *)
Definition: WorkerMonitorThread.cc:127
edm::shared_memory
Definition: buffer_names.h:27
edm::shared_memory::WorkerMonitorThread::s_pipeReadEnd
static std::atomic< int > s_pipeReadEnd
Definition: WorkerMonitorThread.h:69
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::shared_memory::WorkerMonitorThread::s_pipeWriteEnd
static std::atomic< int > s_pipeWriteEnd
Definition: WorkerMonitorThread.h:70
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
edm::shared_memory::WorkerMonitorThread::run
void run()
Definition: WorkerMonitorThread.cc:41
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:29
CMS_THREAD_GUARD
#define CMS_THREAD_GUARD(_var_)
Definition: thread_safety_macros.h:6
edm::shared_memory::WorkerMonitorThread::operator=
const WorkerMonitorThread & operator=(const WorkerMonitorThread &)=delete