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
void shouldKeepEvent(bool iChoice)
call this from the handleTransitions functor
Definition: WorkerChannel.h:78
WorkerChannel(std::string const &iName, const std::string &iUniqueID)
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
edm::Transition transition() const noexcept
Definition: WorkerChannel.h:85
boost::interprocess::managed_shared_memory managed_shm_
Definition: WorkerChannel.h:91
void notifyController()
These are here for expert use.
Definition: WorkerChannel.h:81
unsigned long long * transitionID_
Definition: WorkerChannel.h:97
const WorkerChannel & operator=(const WorkerChannel &)=delete
BufferInfo * toWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
Definition: WorkerChannel.h:51
void workerSetupDone()
Matches the ControllerChannel::setupWorker call.
Definition: WorkerChannel.h:56
Transition
Definition: Transition.h:12
BufferInfo * fromWorkerBufferInfo()
This can be used with WriteBuffer to keep Controller and Worker in sync.
Definition: WorkerChannel.h:53
boost::interprocess::named_condition cndFromController_
Definition: WorkerChannel.h:94
#define noexcept
unsigned long long transitionID() const noexcept
Definition: WorkerChannel.h:86
bool stopRequested() const noexcept
Definition: WorkerChannel.h:87
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
boost::interprocess::named_condition cndToController_
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
boost::interprocess::named_mutex mutex_
Definition: WorkerChannel.h:93