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.

References thread_, and waitForNext().

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

◆ ~SonicDispatcherPseudoAsync()

SonicDispatcherPseudoAsync::~SonicDispatcherPseudoAsync ( )
override

Definition at line 10 of file SonicDispatcherPseudoAsync.cc.

References CMS_SA_ALLOW, cond_, stop_, and thread_.

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 }
#define CMS_SA_ALLOW
std::unique_ptr< std::thread > thread_

Member Function Documentation

◆ dispatch()

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

Reimplemented from SonicDispatcher.

Definition at line 23 of file SonicDispatcherPseudoAsync.cc.

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

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 }
void start(edm::WaitingTaskWithArenaHolder holder)
def move(src, dest)
Definition: eostools.py:511
SonicClientBase * client_

◆ waitForNext()

void SonicDispatcherPseudoAsync::waitForNext ( )
private

Definition at line 35 of file SonicDispatcherPseudoAsync.cc.

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

Referenced by SonicDispatcherPseudoAsync().

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 }
virtual void evaluate()=0
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
SonicClientBase * client_

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