CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 = 0
 
static pthread_t sRootThread = 0
 
static bool sSheduled = false
 
static TSignalHandler * sSigHandler = 0
 

Detailed Description

Definition at line 18 of file TRootXTReq.h.

Member Typedef Documentation

Definition at line 21 of file TRootXTReq.h.

Constructor & Destructor Documentation

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

Definition at line 51 of file TRootXTReq.cc.

51  :
53  mName(n)
54 {}
TCondition * m_return_condition
Definition: TRootXTReq.h:23
TString mName
Definition: TRootXTReq.h:34
TRootXTReq::~TRootXTReq ( )
virtual

Definition at line 56 of file TRootXTReq.cc.

References m_return_condition.

57 {
58  delete m_return_condition;
59 }
TCondition * m_return_condition
Definition: TRootXTReq.h:23

Member Function Documentation

virtual void TRootXTReq::Act ( )
privatepure virtual

Referenced by ProcessQueue().

void TRootXTReq::Bootstrap ( pthread_t  root_thread)
static

Definition at line 152 of file TRootXTReq.cc.

References sQueueMutex, sRootThread, and sSigHandler.

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

Definition at line 63 of file TRootXTReq.cc.

References sQueue, sQueueMutex, sRootThread, and sSheduled.

Referenced by ShootRequest(), and ShootRequestAndWait().

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

Definition at line 178 of file TRootXTReq.cc.

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

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

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

Definition at line 76 of file TRootXTReq.cc.

References m_return_condition, and post_request().

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

Definition at line 91 of file TRootXTReq.cc.

References m_return_condition, and post_request().

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

Definition at line 164 of file TRootXTReq.cc.

References sQueueMutex, sRootThread, and sSigHandler.

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

Member Data Documentation

TCondition* TRootXTReq::m_return_condition
private

Definition at line 23 of file TRootXTReq.h.

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

TString TRootXTReq::mName
protected

Definition at line 34 of file TRootXTReq.h.

TRootXTReq::lpXTReq_t TRootXTReq::sQueue
staticprivate

Definition at line 25 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TMutex * TRootXTReq::sQueueMutex = 0
staticprivate

Definition at line 27 of file TRootXTReq.h.

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

pthread_t TRootXTReq::sRootThread = 0
staticprivate

Definition at line 26 of file TRootXTReq.h.

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

bool TRootXTReq::sSheduled = false
staticprivate

Definition at line 29 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TSignalHandler * TRootXTReq::sSigHandler = 0
staticprivate

Definition at line 28 of file TRootXTReq.h.

Referenced by Bootstrap(), and Shutdown().