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  if (stopRequested()) {
67  return;
68  }
69  while (true) {
71  if (stopRequested()) {
72  break;
73  }
74 
75  iF(transition(), transitionID());
77  }
78  }
79 
81  void shouldKeepEvent(bool iChoice) { *keepEvent_ = iChoice; }
82 
85  //change in transitionID_ used to signal worker finished
86  *transitionID_ = ~(*transitionID_);
87  cndToController_.notify_all();
88  }
90 
91  // ---------- const member functions ---------------------------
93  unsigned long long transitionID() const noexcept { return *transitionID_; }
94  bool stopRequested() const noexcept { return *stop_; }
95 
96  private:
97  // ---------- member data --------------------------------
98  boost::interprocess::managed_shared_memory managed_shm_;
99 
100  boost::interprocess::named_mutex mutex_;
101  boost::interprocess::named_condition cndFromController_;
102  bool* stop_;
104  unsigned long long* transitionID_;
107  boost::interprocess::named_condition cndToController_;
108  bool* keepEvent_;
109  boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock_;
110  };
111 } // namespace edm::shared_memory
112 
113 #endif
edm::shared_memory::WorkerChannel::mutex_
boost::interprocess::named_mutex mutex_
Definition: WorkerChannel.h:100
edm::shared_memory::WorkerChannel::transition
edm::Transition transition() const noexcept
Definition: WorkerChannel.h:92
edm::shared_memory::WorkerChannel::managed_shm_
boost::interprocess::managed_shared_memory managed_shm_
Definition: WorkerChannel.h:98
BufferInfo.h
edm::shared_memory::WorkerChannel::stop_
bool * stop_
Definition: WorkerChannel.h:102
edm::shared_memory::WorkerChannel::transitionType_
edm::Transition * transitionType_
Definition: WorkerChannel.h:103
watchdog.const
const
Definition: watchdog.py:83
edm::shared_memory::WorkerChannel::transitionID_
unsigned long long * transitionID_
Definition: WorkerChannel.h:104
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:101
edm::shared_memory::WorkerChannel::notifyController
void notifyController()
These are here for expert use.
Definition: WorkerChannel.h:84
Transition.h
edm::shared_memory::WorkerChannel::toWorkerBufferInfo_
BufferInfo * toWorkerBufferInfo_
Definition: WorkerChannel.h:105
edm::shared_memory::WorkerChannel::cndToController_
boost::interprocess::named_condition cndToController_
Definition: WorkerChannel.h:107
edm::shared_memory::WorkerChannel::waitForController
void waitForController()
Definition: WorkerChannel.h:89
edm::shared_memory::WorkerChannel::keepEvent_
bool * keepEvent_
Definition: WorkerChannel.h:108
edm::Transition
Transition
Definition: Transition.h:12
edm::shared_memory::WorkerChannel::lock_
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
Definition: WorkerChannel.h:109
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
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:94
edm::shared_memory::WorkerChannel::shouldKeepEvent
void shouldKeepEvent(bool iChoice)
call this from the handleTransitions functor
Definition: WorkerChannel.h:81
edm::shared_memory::WorkerChannel::transitionID
unsigned long long transitionID() const noexcept
Definition: WorkerChannel.h:93
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:106
edm::shared_memory::WorkerChannel::toWorkerBufferInfo
BufferInfo * toWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
Definition: WorkerChannel.h:51