CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
void shouldKeepEvent(bool iChoice)
call this from the handleTransitions functor
Definition: WorkerChannel.h:81
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
boost::interprocess::managed_shared_memory managed_shm_
Definition: WorkerChannel.h:98
void notifyController()
These are here for expert use.
Definition: WorkerChannel.h:84
unsigned long long * transitionID_
const WorkerChannel & operator=(const WorkerChannel &)=delete
edm::Transition transition() const noexcept
Definition: WorkerChannel.h:92
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
unsigned long long transitionID() const noexcept
Definition: WorkerChannel.h:93
boost::interprocess::named_condition cndFromController_
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
bool stopRequested() const noexcept
Definition: WorkerChannel.h:94
boost::interprocess::named_condition cndToController_
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
boost::interprocess::named_mutex mutex_