CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
TRootXTReq Class Referenceabstract

#include <TRootXTReq.h>

Public Member Functions

void ShootRequest ()
 
void ShootRequestAndWait ()
 
 TRootXTReq (const char *n="TRootXTReq")
 
virtual ~TRootXTReq ()
 

Static Public Member Functions

static void Bootstrap (pthread_t root_thread)
 
static void ProcessQueue ()
 
static void Shutdown ()
 

Protected Member Functions

void post_request ()
 

Protected Attributes

TString mName
 

Private Types

typedef std::list< TRootXTReq * > lpXTReq_t
 

Private Member Functions

virtual void Act ()=0
 

Private Attributes

TCondition * m_return_condition
 

Static Private Attributes

static lpXTReq_t sQueue
 
static TMutex * sQueueMutex = nullptr
 
static pthread_t sRootThread = 0
 
static bool sSheduled = false
 
static TSignalHandler * sSigHandler = nullptr
 

Detailed Description

Definition at line 17 of file TRootXTReq.h.

Member Typedef Documentation

Definition at line 20 of file TRootXTReq.h.

Constructor & Destructor Documentation

TRootXTReq::TRootXTReq ( const char *  n = "TRootXTReq")

Definition at line 50 of file TRootXTReq.cc.

50  :
51  m_return_condition(nullptr),
52  mName(n)
53 {}
TCondition * m_return_condition
Definition: TRootXTReq.h:22
TString mName
Definition: TRootXTReq.h:33
TRootXTReq::~TRootXTReq ( )
virtual

Definition at line 55 of file TRootXTReq.cc.

References m_return_condition.

56 {
57  delete m_return_condition;
58 }
TCondition * m_return_condition
Definition: TRootXTReq.h:22

Member Function Documentation

virtual void TRootXTReq::Act ( )
privatepure virtual

Referenced by ProcessQueue().

void TRootXTReq::Bootstrap ( pthread_t  root_thread)
static

Definition at line 151 of file TRootXTReq.cc.

References sQueueMutex, sRootThread, and sSigHandler.

152 {
153  static const TString _eh("TRootXTReq::Bootstrap ");
154 
155  if (sRootThread != 0)
156  throw _eh + "Already initialized.";
157 
158  sRootThread = root_thread;
159  sQueueMutex = new TMutex(kTRUE);
161 }
static pthread_t sRootThread
Definition: TRootXTReq.h:25
static TSignalHandler * sSigHandler
Definition: TRootXTReq.h:27
static TMutex * sQueueMutex
Definition: TRootXTReq.h:26
void TRootXTReq::post_request ( )
protected

Definition at line 62 of file TRootXTReq.cc.

References sQueue, sQueueMutex, sRootThread, and sSheduled.

Referenced by ShootRequest(), and ShootRequestAndWait().

63 {
64  TLockGuard _lck(sQueueMutex);
65 
66  sQueue.push_back(this);
67 
68  if ( ! sSheduled)
69  {
70  sSheduled = true;
71  pthread_kill(sRootThread, SIGUSR1);
72  }
73 }
static pthread_t sRootThread
Definition: TRootXTReq.h:25
static lpXTReq_t sQueue
Definition: TRootXTReq.h:24
static bool sSheduled
Definition: TRootXTReq.h:28
static TMutex * sQueueMutex
Definition: TRootXTReq.h:26
void TRootXTReq::ProcessQueue ( )
static

Definition at line 177 of file TRootXTReq.cc.

References Act(), m_return_condition, sQueue, sQueueMutex, and sSheduled.

Referenced by RootSig2XTReqHandler::XTReqTimer::Notify().

178 {
179  printf("Timer fired, processing queue.\n");
180 
181  while (true)
182  {
183  TRootXTReq *req = nullptr;
184  {
185  TLockGuard _lck(sQueueMutex);
186 
187  if ( ! sQueue.empty())
188  {
189  req = sQueue.front();
190  sQueue.pop_front();
191  }
192  else
193  {
194  sSheduled = false;
195  break;
196  }
197  }
198 
199  req->Act();
200 
201  if (req->m_return_condition)
202  {
203  req->m_return_condition->GetMutex()->Lock();
204  req->m_return_condition->Signal();
205  req->m_return_condition->GetMutex()->UnLock();
206  }
207  else
208  {
209  delete req;
210  }
211  }
212 }
TCondition * m_return_condition
Definition: TRootXTReq.h:22
virtual void Act()=0
static lpXTReq_t sQueue
Definition: TRootXTReq.h:24
static bool sSheduled
Definition: TRootXTReq.h:28
static TMutex * sQueueMutex
Definition: TRootXTReq.h:26
void TRootXTReq::ShootRequest ( )

Definition at line 75 of file TRootXTReq.cc.

References m_return_condition, and post_request().

76 {
77  // Places request into the queue and requests execution in Rint thread.
78  // It returns immediately after that, without waiting for execution.
79  // The request is deleted after execution.
80 
82  {
83  delete m_return_condition;
84  m_return_condition = nullptr;
85  }
86 
87  post_request();
88 }
TCondition * m_return_condition
Definition: TRootXTReq.h:22
void post_request()
Definition: TRootXTReq.cc:62
void TRootXTReq::ShootRequestAndWait ( )

Definition at line 90 of file TRootXTReq.cc.

References m_return_condition, and post_request().

91 {
92  // Places request into the queue, requests execution in Rint thread and
93  // waits for the execution to be completed.
94  // The request is not deleted after execution as it might carry return
95  // value.
96  // The same request can be reused several times.
97 
98  if (!m_return_condition)
99  m_return_condition = new TCondition;
100 
101  m_return_condition->GetMutex()->Lock();
102 
103  post_request();
104 
105  m_return_condition->Wait();
106  m_return_condition->GetMutex()->UnLock();
107 }
TCondition * m_return_condition
Definition: TRootXTReq.h:22
void post_request()
Definition: TRootXTReq.cc:62
void TRootXTReq::Shutdown ( )
static

Definition at line 163 of file TRootXTReq.cc.

References sQueueMutex, sRootThread, and sSigHandler.

164 {
165  static const TString _eh("TRootXTReq::Shutdown ");
166 
167  if (sRootThread == 0)
168  throw _eh + "Have not beem initialized.";
169 
170  // Should lock and drain queue ... or sth.
171 
172  sRootThread = 0;
173  delete sSigHandler; sSigHandler = nullptr;
174  delete sQueueMutex; sQueueMutex = nullptr;
175 }
static pthread_t sRootThread
Definition: TRootXTReq.h:25
static TSignalHandler * sSigHandler
Definition: TRootXTReq.h:27
static TMutex * sQueueMutex
Definition: TRootXTReq.h:26

Member Data Documentation

TCondition* TRootXTReq::m_return_condition
private

Definition at line 22 of file TRootXTReq.h.

Referenced by ProcessQueue(), ShootRequest(), ShootRequestAndWait(), and ~TRootXTReq().

TString TRootXTReq::mName
protected

Definition at line 33 of file TRootXTReq.h.

TRootXTReq::lpXTReq_t TRootXTReq::sQueue
staticprivate

Definition at line 24 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TMutex * TRootXTReq::sQueueMutex = nullptr
staticprivate

Definition at line 26 of file TRootXTReq.h.

Referenced by Bootstrap(), post_request(), ProcessQueue(), and Shutdown().

pthread_t TRootXTReq::sRootThread = 0
staticprivate

Definition at line 25 of file TRootXTReq.h.

Referenced by Bootstrap(), post_request(), and Shutdown().

bool TRootXTReq::sSheduled = false
staticprivate

Definition at line 28 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TSignalHandler * TRootXTReq::sSigHandler = nullptr
staticprivate

Definition at line 27 of file TRootXTReq.h.

Referenced by Bootstrap(), and Shutdown().