CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::shared_memory::WorkerChannel Class Reference

#include <WorkerChannel.h>

Public Member Functions

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 a unix signal More...
 
BufferInfofromWorkerBufferInfo ()
 This can be used with WriteBuffer to keep Controller and Worker in sync. More...
 
template<typename F >
void handleTransitions (F &&iF)
 
void notifyController ()
 These are here for expert use. More...
 
const WorkerChanneloperator= (const WorkerChannel &)=delete
 
const WorkerChanneloperator= (WorkerChannel &&)=delete
 
void shouldKeepEvent (bool iChoice)
 call this from the handleTransitions functor More...
 
bool stopRequested () const noexcept
 
BufferInfotoWorkerBufferInfo ()
 This can be used with ReadBuffer to keep Controller and Worker in sync. More...
 
edm::Transition transition () const noexcept
 
unsigned long long transitionID () const noexcept
 
void waitForController ()
 
 WorkerChannel (std::string const &iName, const std::string &iUniqueID)
 
 WorkerChannel (const WorkerChannel &)=delete
 
 WorkerChannel (WorkerChannel &&)=delete
 
void workerSetupDone ()
 Matches the ControllerChannel::setupWorker call. More...
 

Private Attributes

boost::interprocess::named_condition cndFromController_
 
boost::interprocess::named_condition cndToController_
 
BufferInfofromWorkerBufferInfo_
 
bool * keepEvent_
 
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
 
boost::interprocess::managed_shared_memory managed_shm_
 
boost::interprocess::named_mutex mutex_
 
bool * stop_
 
BufferInfotoWorkerBufferInfo_
 
unsigned long long * transitionID_
 
edm::TransitiontransitionType_
 

Detailed Description

Definition at line 35 of file WorkerChannel.h.

Constructor & Destructor Documentation

WorkerChannel::WorkerChannel ( std::string const &  iName,
const std::string &  iUniqueID 
)

iName must match the value from ControllerChannel::sharedMemoryName() iUniqueName must match the value from ControllerChannel::uniqueID()

Definition at line 40 of file WorkerChannel.cc.

References cndFromController_, cndToController_, edm::first(), fromWorkerBufferInfo_, edm::shared_memory::channel_names::kConditionFromMain, edm::shared_memory::channel_names::kConditionToMain, keepEvent_, edm::shared_memory::channel_names::kFromWorkerBufferInfo, edm::shared_memory::channel_names::kKeepEvent, edm::shared_memory::channel_names::kMutex, edm::shared_memory::channel_names::kStop, edm::shared_memory::channel_names::kToWorkerBufferInfo, edm::shared_memory::channel_names::kTransitionID, edm::shared_memory::channel_names::kTransitionType, lock_, managed_shm_, mutex_, stop_, toWorkerBufferInfo_, transitionID_, and transitionType_.

41  : managed_shm_{open_only, iName.c_str()},
42  mutex_{open_or_create, unique_name(channel_names::kMutex, iUniqueID).c_str()},
43  cndFromController_{open_or_create, unique_name(channel_names::kConditionFromMain, iUniqueID).c_str()},
46  transitionID_{managed_shm_.find<unsigned long long>(channel_names::kTransitionID).first},
49  cndToController_{open_or_create, unique_name(channel_names::kConditionToMain, iUniqueID).c_str()},
51  lock_{mutex_} {
52  assert(stop_);
53  assert(transitionType_);
54  assert(transitionID_);
55  assert(toWorkerBufferInfo_);
56  assert(fromWorkerBufferInfo_);
57 }
constexpr char const *const kConditionToMain
Definition: channel_names.h:33
constexpr char const *const kConditionFromMain
Definition: channel_names.h:32
constexpr char const *const kStop
Definition: channel_names.h:34
constexpr char const *const kTransitionType
Definition: channel_names.h:36
boost::interprocess::managed_shared_memory managed_shm_
Definition: WorkerChannel.h:98
unsigned long long * transitionID_
constexpr char const *const kMutex
Definition: channel_names.h:31
Transition
Definition: Transition.h:12
constexpr char const *const kKeepEvent
Definition: channel_names.h:35
boost::interprocess::named_condition cndFromController_
constexpr char const *const kFromWorkerBufferInfo
Definition: channel_names.h:30
constexpr char const *const kTransitionID
Definition: channel_names.h:37
constexpr char const *const kToWorkerBufferInfo
Definition: channel_names.h:29
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
boost::interprocess::named_condition cndToController_
T first(std::pair< T, U > const &p)
boost::interprocess::named_mutex mutex_
edm::shared_memory::WorkerChannel::WorkerChannel ( const WorkerChannel )
delete
edm::shared_memory::WorkerChannel::WorkerChannel ( WorkerChannel &&  )
delete

Member Function Documentation

boost::interprocess::scoped_lock<boost::interprocess::named_mutex>* edm::shared_memory::WorkerChannel::accessLock ( )
inline

the lock is made accessible so that the WorkerMonitorThread can be used to unlock it in the event of a unix signal

Definition at line 48 of file WorkerChannel.h.

References lock_.

Referenced by main().

48 { return &lock_; }
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
BufferInfo* edm::shared_memory::WorkerChannel::fromWorkerBufferInfo ( )
inline

This can be used with WriteBuffer to keep Controller and Worker in sync.

Definition at line 53 of file WorkerChannel.h.

References fromWorkerBufferInfo_.

Referenced by main().

53 { return fromWorkerBufferInfo_; }
template<typename F >
void edm::shared_memory::WorkerChannel::handleTransitions ( F &&  iF)
inline

Matches the ControllerChannel::doTransition calls. iF is a function that takes as arguments a edm::Transition and unsigned long long

Definition at line 65 of file WorkerChannel.h.

References notifyController(), stopRequested(), transition(), transitionID(), and waitForController().

Referenced by main().

65  {
66  if (stopRequested()) {
67  return;
68  }
69  while (true) {
71  if (stopRequested()) {
72  break;
73  }
74 
75  iF(transition(), transitionID());
77  }
78  }
edm::Transition transition() const noexcept
Definition: WorkerChannel.h:92
void notifyController()
These are here for expert use.
Definition: WorkerChannel.h:84
unsigned long long transitionID() const noexcept
Definition: WorkerChannel.h:93
bool stopRequested() const noexcept
Definition: WorkerChannel.h:94
void edm::shared_memory::WorkerChannel::notifyController ( )
inline

These are here for expert use.

Definition at line 84 of file WorkerChannel.h.

References cndToController_, and transitionID_.

Referenced by handleTransitions(), and workerSetupDone().

84  {
85  //change in transitionID_ used to signal worker finished
86  *transitionID_ = ~(*transitionID_);
87  cndToController_.notify_all();
88  }
unsigned long long * transitionID_
boost::interprocess::named_condition cndToController_
const WorkerChannel& edm::shared_memory::WorkerChannel::operator= ( const WorkerChannel )
delete
const WorkerChannel& edm::shared_memory::WorkerChannel::operator= ( WorkerChannel &&  )
delete
void edm::shared_memory::WorkerChannel::shouldKeepEvent ( bool  iChoice)
inline

call this from the handleTransitions functor

Definition at line 81 of file WorkerChannel.h.

References keepEvent_.

81 { *keepEvent_ = iChoice; }
bool edm::shared_memory::WorkerChannel::stopRequested ( ) const
inlinenoexcept

Definition at line 94 of file WorkerChannel.h.

References stop_.

Referenced by handleTransitions().

94 { return *stop_; }
BufferInfo* edm::shared_memory::WorkerChannel::toWorkerBufferInfo ( )
inline

This can be used with ReadBuffer to keep Controller and Worker in sync.

Definition at line 51 of file WorkerChannel.h.

References toWorkerBufferInfo_.

Referenced by main().

51 { return toWorkerBufferInfo_; }
edm::Transition edm::shared_memory::WorkerChannel::transition ( ) const
inlinenoexcept

Definition at line 92 of file WorkerChannel.h.

References transitionType_.

Referenced by handleTransitions().

92 { return *transitionType_; }
unsigned long long edm::shared_memory::WorkerChannel::transitionID ( ) const
inlinenoexcept

Definition at line 93 of file WorkerChannel.h.

References transitionID_.

Referenced by handleTransitions().

93 { return *transitionID_; }
unsigned long long * transitionID_
void edm::shared_memory::WorkerChannel::waitForController ( )
inline

Definition at line 89 of file WorkerChannel.h.

References cndFromController_, and lock_.

Referenced by handleTransitions().

89 { cndFromController_.wait(lock_); }
boost::interprocess::named_condition cndFromController_
boost::interprocess::scoped_lock< boost::interprocess::named_mutex > lock_
void edm::shared_memory::WorkerChannel::workerSetupDone ( )
inline

Matches the ControllerChannel::setupWorker call.

Definition at line 56 of file WorkerChannel.h.

References notifyController().

Referenced by main().

56  {
57  //The controller is waiting for the worker to be setup
59  }
void notifyController()
These are here for expert use.
Definition: WorkerChannel.h:84

Member Data Documentation

boost::interprocess::named_condition edm::shared_memory::WorkerChannel::cndFromController_
private

Definition at line 101 of file WorkerChannel.h.

Referenced by waitForController(), and WorkerChannel().

boost::interprocess::named_condition edm::shared_memory::WorkerChannel::cndToController_
private

Definition at line 107 of file WorkerChannel.h.

Referenced by notifyController(), and WorkerChannel().

BufferInfo* edm::shared_memory::WorkerChannel::fromWorkerBufferInfo_
private

Definition at line 106 of file WorkerChannel.h.

Referenced by fromWorkerBufferInfo(), and WorkerChannel().

bool* edm::shared_memory::WorkerChannel::keepEvent_
private

Definition at line 108 of file WorkerChannel.h.

Referenced by shouldKeepEvent(), and WorkerChannel().

boost::interprocess::scoped_lock<boost::interprocess::named_mutex> edm::shared_memory::WorkerChannel::lock_
private

Definition at line 109 of file WorkerChannel.h.

Referenced by accessLock(), waitForController(), and WorkerChannel().

boost::interprocess::managed_shared_memory edm::shared_memory::WorkerChannel::managed_shm_
private

Definition at line 98 of file WorkerChannel.h.

Referenced by WorkerChannel().

boost::interprocess::named_mutex edm::shared_memory::WorkerChannel::mutex_
private

Definition at line 100 of file WorkerChannel.h.

Referenced by WorkerChannel().

bool* edm::shared_memory::WorkerChannel::stop_
private

Definition at line 102 of file WorkerChannel.h.

Referenced by stopRequested(), and WorkerChannel().

BufferInfo* edm::shared_memory::WorkerChannel::toWorkerBufferInfo_
private

Definition at line 105 of file WorkerChannel.h.

Referenced by toWorkerBufferInfo(), and WorkerChannel().

unsigned long long* edm::shared_memory::WorkerChannel::transitionID_
private

Definition at line 104 of file WorkerChannel.h.

Referenced by notifyController(), transitionID(), and WorkerChannel().

edm::Transition* edm::shared_memory::WorkerChannel::transitionType_
private

Definition at line 103 of file WorkerChannel.h.

Referenced by transition(), and WorkerChannel().