CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SonicClientPseudoAsync< InputT, OutputT > Class Template Reference

#include <SonicClientPseudoAsync.h>

Inheritance diagram for SonicClientPseudoAsync< InputT, OutputT >:
SonicClientBase SonicClientTypes< InputT, OutputT >

Public Member Functions

void dispatch (edm::WaitingTaskWithArenaHolder holder) final
 
 SonicClientPseudoAsync ()
 
 ~SonicClientPseudoAsync () override
 
- Public Member Functions inherited from SonicClientBase
const std::string & debugName () const
 
void setDebugName (const std::string &debugName)
 
 SonicClientBase ()
 
virtual ~SonicClientBase ()=default
 
- Public Member Functions inherited from SonicClientTypes< InputT, OutputT >
Inputinput ()
 
const Outputoutput () const
 
virtual ~SonicClientTypes ()=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

- Public Types inherited from SonicClientTypes< InputT, OutputT >
typedef InputT Input
 
typedef OutputT Output
 
- Protected Member Functions inherited from SonicClientBase
virtual unsigned allowedTries () const
 
virtual void evaluate ()=0
 
void finish (bool success, std::exception_ptr eptr=std::exception_ptr{})
 
void setStartTime ()
 
- Protected Attributes inherited from SonicClientBase
std::string debugName_
 
edm::WaitingTaskWithArenaHolder holder_
 
std::chrono::time_point< std::chrono::high_resolution_clock > t0_
 
unsigned tries_
 
- Protected Attributes inherited from SonicClientTypes< InputT, OutputT >
Input input_
 
Output output_
 

Detailed Description

template<typename InputT, typename OutputT = InputT>
class SonicClientPseudoAsync< InputT, OutputT >

Definition at line 17 of file SonicClientPseudoAsync.h.

Constructor & Destructor Documentation

◆ SonicClientPseudoAsync()

template<typename InputT , typename OutputT = InputT>
SonicClientPseudoAsync< InputT, OutputT >::SonicClientPseudoAsync ( )
inline

Definition at line 20 of file SonicClientPseudoAsync.h.

21  thread_ = std::make_unique<std::thread>([this]() { waitForNext(); });
22  }

References SonicClientPseudoAsync< InputT, OutputT >::thread_, and SonicClientPseudoAsync< InputT, OutputT >::waitForNext().

◆ ~SonicClientPseudoAsync()

template<typename InputT , typename OutputT = InputT>
SonicClientPseudoAsync< InputT, OutputT >::~SonicClientPseudoAsync ( )
inlineoverride

Definition at line 24 of file SonicClientPseudoAsync.h.

24  {
25  stop_ = true;
26  cond_.notify_one();
27  if (thread_) {
28  try {
29  thread_->join();
30  thread_.reset();
31  } catch (...) {
32  }
33  }
34  }

References SonicClientPseudoAsync< InputT, OutputT >::cond_, SonicClientPseudoAsync< InputT, OutputT >::stop_, and SonicClientPseudoAsync< InputT, OutputT >::thread_.

Member Function Documentation

◆ dispatch()

template<typename InputT , typename OutputT = InputT>
void SonicClientPseudoAsync< InputT, OutputT >::dispatch ( edm::WaitingTaskWithArenaHolder  holder)
inlinefinalvirtual

Implements SonicClientBase.

Definition at line 36 of file SonicClientPseudoAsync.h.

36  {
37  //do all read/writes inside lock to ensure cache synchronization
38  {
39  std::lock_guard<std::mutex> guard(mutex_);
40  holder_ = std::move(holder);
41  setStartTime();
42 
43  //activate thread to wait for response, and return
44  hasCall_ = true;
45  }
46  cond_.notify_one();
47  }

References SonicClientPseudoAsync< InputT, OutputT >::cond_, SonicClientPseudoAsync< InputT, OutputT >::hasCall_, SonicClientBase::holder_, eostools::move(), SonicClientPseudoAsync< InputT, OutputT >::mutex_, and SonicClientBase::setStartTime().

◆ waitForNext()

template<typename InputT , typename OutputT = InputT>
void SonicClientPseudoAsync< InputT, OutputT >::waitForNext ( )
inlineprivate

Definition at line 50 of file SonicClientPseudoAsync.h.

50  {
51  while (true) {
52  //wait for condition
53  {
54  std::unique_lock<std::mutex> lk(mutex_);
55  cond_.wait(lk, [this]() { return (hasCall_ or stop_); });
56  if (stop_)
57  break;
58 
59  //do everything inside lock
60  evaluate();
61 
62  //reset condition
63  hasCall_ = false;
64  }
65  }
66  }

References SonicClientPseudoAsync< InputT, OutputT >::cond_, SonicClientBase::evaluate(), SonicClientPseudoAsync< InputT, OutputT >::hasCall_, SonicClientPseudoAsync< InputT, OutputT >::mutex_, or, and SonicClientPseudoAsync< InputT, OutputT >::stop_.

Referenced by SonicClientPseudoAsync< InputT, OutputT >::SonicClientPseudoAsync().

Member Data Documentation

◆ cond_

template<typename InputT , typename OutputT = InputT>
std::condition_variable SonicClientPseudoAsync< InputT, OutputT >::cond_
private

◆ hasCall_

template<typename InputT , typename OutputT = InputT>
bool SonicClientPseudoAsync< InputT, OutputT >::hasCall_
private

◆ mutex_

template<typename InputT , typename OutputT = InputT>
std::mutex SonicClientPseudoAsync< InputT, OutputT >::mutex_
private

◆ stop_

template<typename InputT , typename OutputT = InputT>
std::atomic<bool> SonicClientPseudoAsync< InputT, OutputT >::stop_
private

◆ thread_

template<typename InputT , typename OutputT = InputT>
std::unique_ptr<std::thread> SonicClientPseudoAsync< InputT, OutputT >::thread_
private
SonicClientBase::SonicClientBase
SonicClientBase()
Definition: SonicClientBase.h:14
SonicClientTypes
Definition: SonicClientTypes.h:6
SonicClientBase::holder_
edm::WaitingTaskWithArenaHolder holder_
Definition: SonicClientBase.h:65
SonicClientPseudoAsync::cond_
std::condition_variable cond_
Definition: SonicClientPseudoAsync.h:71
SonicClientBase::evaluate
virtual void evaluate()=0
SonicClientBase::setStartTime
void setStartTime()
Definition: SonicClientBase.h:31
SonicClientPseudoAsync::thread_
std::unique_ptr< std::thread > thread_
Definition: SonicClientPseudoAsync.h:73
SonicClientPseudoAsync::mutex_
std::mutex mutex_
Definition: SonicClientPseudoAsync.h:70
SonicClientPseudoAsync::hasCall_
bool hasCall_
Definition: SonicClientPseudoAsync.h:69
eostools.move
def move(src, dest)
Definition: eostools.py:511
SonicClientPseudoAsync::waitForNext
void waitForNext()
Definition: SonicClientPseudoAsync.h:50
SonicClientPseudoAsync::stop_
std::atomic< bool > stop_
Definition: SonicClientPseudoAsync.h:72
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