CMS 3D CMS Logo

WorkerChannel.h
Go to the documentation of this file.
1 #ifndef FWCore_SharedMemory_WorkerChannel_h
2 #define FWCore_SharedMemory_WorkerChannel_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/SharedMemory
6 // Class : WorkerChannel
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: 21/01/2020
19 //
20 
21 // system include files
22 #include <string>
23 #include "boost/interprocess/managed_shared_memory.hpp"
24 #include "boost/interprocess/sync/named_mutex.hpp"
25 #include "boost/interprocess/sync/named_condition.hpp"
26 #include "boost/interprocess/sync/scoped_lock.hpp"
27 
28 // user include files
31 
32 // forward declarations
33 
34 namespace edm::shared_memory {
35  class WorkerChannel {
36  public:
40  WorkerChannel(std::string const& iName, const std::string& iUniqueID);
41  WorkerChannel(const WorkerChannel&) = delete;
42  const WorkerChannel& operator=(const WorkerChannel&) = delete;
43  WorkerChannel(WorkerChannel&&) = delete;
44  const WorkerChannel& operator=(WorkerChannel&&) = delete;
45 
46  // ---------- member functions ---------------------------
48  boost::interprocess::scoped_lock<boost::interprocess::named_mutex>* accessLock() { return &lock_; }
49 
54 
56  void workerSetupDone() {
57  //The controller is waiting for the worker to be setup
59  }
60 
64  template <typename F>
65  void handleTransitions(F&& iF) {
66  while (true) {
68  if (stopRequested()) {
69  break;
70  }
71 
72  iF(transition(), transitionID());
74  }
75  }
76 
78  void shouldKeepEvent(bool iChoice) { *keepEvent_ = iChoice; }
79 
81  void notifyController() { cndToController_.notify_all(); }
83 
84  // ---------- const member functions ---------------------------
86  unsigned long long transitionID() const noexcept { return *transitionID_; }
87  bool stopRequested() const noexcept { return *stop_; }
88 
89  private:
90  // ---------- member data --------------------------------
91  boost::interprocess::managed_shared_memory managed_shm_;
92 
93  boost::interprocess::named_mutex mutex_;
94  boost::interprocess::named_condition cndFromController_;
95  bool* stop_;
97  unsigned long long* transitionID_;
100  boost::interprocess::named_condition cndToController_;
101  bool* keepEvent_;
102  boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock_;
103  };
104 } // namespace edm::shared_memory
105 
106 #endif
edm::shared_memory::WorkerChannel::mutex_
boost::interprocess::named_mutex mutex_
Definition: WorkerChannel.h:93
edm::shared_memory::WorkerChannel::transition
edm::Transition transition() const noexcept
Definition: WorkerChannel.h:85
edm::shared_memory::WorkerChannel::managed_shm_
boost::interprocess::managed_shared_memory managed_shm_
Definition: WorkerChannel.h:91
BufferInfo.h
edm::shared_memory::WorkerChannel::stop_
bool * stop_
Definition: WorkerChannel.h:95
edm::shared_memory::WorkerChannel::transitionType_
edm::Transition * transitionType_
Definition: WorkerChannel.h:96
watchdog.const
const
Definition: watchdog.py:83
edm::shared_memory::WorkerChannel::transitionID_
unsigned long long * transitionID_
Definition: WorkerChannel.h:97
edm::shared_memory::WorkerChannel::fromWorkerBufferInfo
BufferInfo * fromWorkerBufferInfo()
This can be used with WriteBuffer to keep Controller and Worker in sync.
Definition: WorkerChannel.h:53
edm::shared_memory::WorkerChannel::accessLock
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > * accessLock()
the lock is made accessible so that the WorkerMonitorThread can be used to unlock it in the event of ...
Definition: WorkerChannel.h:48
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::shared_memory::BufferInfo
Definition: BufferInfo.h:27
edm::shared_memory::WorkerChannel::cndFromController_
boost::interprocess::named_condition cndFromController_
Definition: WorkerChannel.h:94
edm::shared_memory::WorkerChannel::notifyController
void notifyController()
These are here for expert use.
Definition: WorkerChannel.h:81
Transition.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::shared_memory::WorkerChannel::toWorkerBufferInfo_
BufferInfo * toWorkerBufferInfo_
Definition: WorkerChannel.h:98
edm::shared_memory::WorkerChannel::cndToController_
boost::interprocess::named_condition cndToController_
Definition: WorkerChannel.h:100
edm::shared_memory::WorkerChannel::waitForController
void waitForController()
Definition: WorkerChannel.h:82
edm::shared_memory::WorkerChannel::keepEvent_
bool * keepEvent_
Definition: WorkerChannel.h:101
edm::Transition
Transition
Definition: Transition.h:12
edm::shared_memory::WorkerChannel::lock_
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
Definition: WorkerChannel.h:102
edm::shared_memory::WorkerChannel::WorkerChannel
WorkerChannel(std::string const &iName, const std::string &iUniqueID)
Definition: WorkerChannel.cc:40
edm::shared_memory::WorkerChannel::operator=
const WorkerChannel & operator=(const WorkerChannel &)=delete
edm::shared_memory
Definition: buffer_names.h:27
edm::shared_memory::WorkerChannel::handleTransitions
void handleTransitions(F &&iF)
Definition: WorkerChannel.h:65
edm::shared_memory::WorkerChannel
Definition: WorkerChannel.h:35
edm::shared_memory::WorkerChannel::stopRequested
bool stopRequested() const noexcept
Definition: WorkerChannel.h:87
edm::shared_memory::WorkerChannel::shouldKeepEvent
void shouldKeepEvent(bool iChoice)
call this from the handleTransitions functor
Definition: WorkerChannel.h:78
edm::shared_memory::WorkerChannel::transitionID
unsigned long long transitionID() const noexcept
Definition: WorkerChannel.h:86
edm::shared_memory::WorkerChannel::workerSetupDone
void workerSetupDone()
Matches the ControllerChannel::setupWorker call.
Definition: WorkerChannel.h:56
edm::shared_memory::WorkerChannel::fromWorkerBufferInfo_
BufferInfo * fromWorkerBufferInfo_
Definition: WorkerChannel.h:99
edm::shared_memory::WorkerChannel::toWorkerBufferInfo
BufferInfo * toWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
Definition: WorkerChannel.h:51