CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SonicDispatcherPseudoAsync Class Reference

#include <SonicDispatcherPseudoAsync.h>

Inheritance diagram for SonicDispatcherPseudoAsync:
SonicDispatcher

Public Member Functions

void dispatch (edm::WaitingTaskWithArenaHolder holder) override
 
 SonicDispatcherPseudoAsync (SonicClientBase *client)
 
 ~SonicDispatcherPseudoAsync () override
 
- Public Member Functions inherited from SonicDispatcher
virtual void dispatch ()
 
 SonicDispatcher (SonicClientBase *client)
 
virtual ~SonicDispatcher ()=default
 

Private Member Functions

void waitForNext ()
 

Private Attributes

std::condition_variable cond_
 
bool hasCall_
 
std::mutex mutex_
 
std::atomic< bool > stop_
 
std::unique_ptr< std::thread > thread_
 

Additional Inherited Members

- Protected Attributes inherited from SonicDispatcher
SonicClientBaseclient_
 

Detailed Description

Definition at line 16 of file SonicDispatcherPseudoAsync.h.

Constructor & Destructor Documentation

◆ SonicDispatcherPseudoAsync()

SonicDispatcherPseudoAsync::SonicDispatcherPseudoAsync ( SonicClientBase client)

Definition at line 5 of file SonicDispatcherPseudoAsync.cc.

6  : SonicDispatcher(client), hasCall_(false), stop_(false) {
7  thread_ = std::make_unique<std::thread>([this]() { waitForNext(); });
8 }

References thread_, and waitForNext().

◆ ~SonicDispatcherPseudoAsync()

SonicDispatcherPseudoAsync::~SonicDispatcherPseudoAsync ( )
override

Definition at line 10 of file SonicDispatcherPseudoAsync.cc.

10  {
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 }

References CMS_SA_ALLOW, cond_, stop_, and thread_.

Member Function Documentation

◆ dispatch()

void SonicDispatcherPseudoAsync::dispatch ( edm::WaitingTaskWithArenaHolder  holder)
overridevirtual

Reimplemented from SonicDispatcher.

Definition at line 23 of file SonicDispatcherPseudoAsync.cc.

23  {
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 }

References SonicDispatcher::client_, cond_, hasCall_, eostools::move(), mutex_, and SonicClientBase::start().

◆ waitForNext()

void SonicDispatcherPseudoAsync::waitForNext ( )
private

Definition at line 35 of file SonicDispatcherPseudoAsync.cc.

35  {
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 }

References SonicDispatcher::client_, cond_, SonicClientBase::evaluate(), hasCall_, mutex_, or, and stop_.

Referenced by SonicDispatcherPseudoAsync().

Member Data Documentation

◆ cond_

std::condition_variable SonicDispatcherPseudoAsync::cond_
private

Definition at line 33 of file SonicDispatcherPseudoAsync.h.

Referenced by dispatch(), waitForNext(), and ~SonicDispatcherPseudoAsync().

◆ hasCall_

bool SonicDispatcherPseudoAsync::hasCall_
private

Definition at line 31 of file SonicDispatcherPseudoAsync.h.

Referenced by dispatch(), and waitForNext().

◆ mutex_

std::mutex SonicDispatcherPseudoAsync::mutex_
private

Definition at line 32 of file SonicDispatcherPseudoAsync.h.

Referenced by dispatch(), and waitForNext().

◆ stop_

std::atomic<bool> SonicDispatcherPseudoAsync::stop_
private

Definition at line 34 of file SonicDispatcherPseudoAsync.h.

Referenced by waitForNext(), and ~SonicDispatcherPseudoAsync().

◆ thread_

std::unique_ptr<std::thread> SonicDispatcherPseudoAsync::thread_
private
SonicDispatcher::client_
SonicClientBase * client_
Definition: SonicDispatcher.h:23
SonicDispatcherPseudoAsync::mutex_
std::mutex mutex_
Definition: SonicDispatcherPseudoAsync.h:32
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
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
SonicDispatcherPseudoAsync::stop_
std::atomic< bool > stop_
Definition: SonicDispatcherPseudoAsync.h:34
SonicDispatcherPseudoAsync::waitForNext
void waitForNext()
Definition: SonicDispatcherPseudoAsync.cc:35
eostools.move
def move(src, dest)
Definition: eostools.py:511
SonicDispatcherPseudoAsync::hasCall_
bool hasCall_
Definition: SonicDispatcherPseudoAsync.h:31
SonicDispatcher::SonicDispatcher
SonicDispatcher(SonicClientBase *client)
Definition: SonicDispatcher.h:11
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