CMS 3D CMS Logo

SonicDispatcherPseudoAsync.cc
Go to the documentation of this file.
4 
6  : SonicDispatcher(client), hasCall_(false), stop_(false) {
7  thread_ = std::make_unique<std::thread>([this]() { waitForNext(); });
8 }
9 
11  stop_ = true;
12  cond_.notify_one();
13  if (thread_) {
14  // avoid throwing in destructor
15  CMS_SA_ALLOW try {
16  thread_->join();
17  thread_.reset();
18  } catch (...) {
19  }
20  }
21 }
22 
24  //do all read/writes inside lock to ensure cache synchronization
25  {
26  std::lock_guard<std::mutex> guard(mutex_);
27  client_->start(std::move(holder));
28 
29  //activate thread to wait for response, and return
30  hasCall_ = true;
31  }
32  cond_.notify_one();
33 }
34 
36  while (true) {
37  //wait for condition
38  {
39  std::unique_lock<std::mutex> lk(mutex_);
40  cond_.wait(lk, [this]() { return (hasCall_ or stop_); });
41  if (stop_)
42  break;
43 
44  //do everything inside lock
45  client_->evaluate();
46 
47  //reset condition
48  hasCall_ = false;
49  }
50  }
51 }
SonicDispatcher::client_
SonicClientBase * client_
Definition: SonicDispatcher.h:23
funct::false
false
Definition: Factorize.h:29
SonicDispatcherPseudoAsync::mutex_
std::mutex mutex_
Definition: SonicDispatcherPseudoAsync.h:32
SonicDispatcherPseudoAsync.h
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
SonicDispatcherPseudoAsync::SonicDispatcherPseudoAsync
SonicDispatcherPseudoAsync(SonicClientBase *client)
Definition: SonicDispatcherPseudoAsync.cc:5
SonicClientBase
Definition: SonicClientBase.h:19
SonicDispatcher::dispatch
virtual void dispatch()
Definition: SonicDispatcher.cc:9
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:31
SonicDispatcherPseudoAsync::thread_
std::unique_ptr< std::thread > thread_
Definition: SonicDispatcherPseudoAsync.h:35
HLTObjectMonitor_Client_cff.client
client
Definition: HLTObjectMonitor_Client_cff.py:6
SonicClientBase::start
void start(edm::WaitingTaskWithArenaHolder holder)
Definition: SonicClientBase.cc:31
SonicClientBase::evaluate
virtual void evaluate()=0
SonicDispatcher
Definition: SonicDispatcher.h:8
SonicDispatcherPseudoAsync::stop_
std::atomic< bool > stop_
Definition: SonicDispatcherPseudoAsync.h:34
SonicDispatcherPseudoAsync::~SonicDispatcherPseudoAsync
~SonicDispatcherPseudoAsync() override
Definition: SonicDispatcherPseudoAsync.cc:10
thread_safety_macros.h
SonicDispatcherPseudoAsync::waitForNext
void waitForNext()
Definition: SonicDispatcherPseudoAsync.cc:35
SonicClientBase.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
SonicDispatcherPseudoAsync::hasCall_
bool hasCall_
Definition: SonicDispatcherPseudoAsync.h:31
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
SonicDispatcherPseudoAsync::cond_
std::condition_variable cond_
Definition: SonicDispatcherPseudoAsync.h:33