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

◆ lpXTReq_t

Definition at line 19 of file TRootXTReq.h.

Constructor & Destructor Documentation

◆ TRootXTReq()

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

Definition at line 48 of file TRootXTReq.cc.

48 : m_return_condition(nullptr), mName(n) {}

◆ ~TRootXTReq()

TRootXTReq::~TRootXTReq ( )
virtual

Definition at line 50 of file TRootXTReq.cc.

50 { delete m_return_condition; }

References m_return_condition.

Member Function Documentation

◆ Act()

virtual void TRootXTReq::Act ( )
privatepure virtual

Referenced by ProcessQueue().

◆ Bootstrap()

void TRootXTReq::Bootstrap ( pthread_t  root_thread)
static

Definition at line 132 of file TRootXTReq.cc.

132  {
133  static const TString _eh("TRootXTReq::Bootstrap ");
134 
135  if (sRootThread != 0)
136  throw _eh + "Already initialized.";
137 
138  sRootThread = root_thread;
139  sQueueMutex = new TMutex(kTRUE);
141 }

References sQueueMutex, sRootThread, and sSigHandler.

◆ post_request()

void TRootXTReq::post_request ( )
protected

Definition at line 54 of file TRootXTReq.cc.

54  {
55  TLockGuard _lck(sQueueMutex);
56 
57  sQueue.push_back(this);
58 
59  if (!sSheduled) {
60  sSheduled = true;
61  pthread_kill(sRootThread, SIGUSR1);
62  }
63 }

References sQueue, sQueueMutex, sRootThread, and sSheduled.

Referenced by ShootRequest(), and ShootRequestAndWait().

◆ ProcessQueue()

void TRootXTReq::ProcessQueue ( )
static

Definition at line 158 of file TRootXTReq.cc.

158  {
159  printf("Timer fired, processing queue.\n");
160 
161  while (true) {
162  TRootXTReq *req = nullptr;
163  {
164  TLockGuard _lck(sQueueMutex);
165 
166  if (!sQueue.empty()) {
167  req = sQueue.front();
168  sQueue.pop_front();
169  } else {
170  sSheduled = false;
171  break;
172  }
173  }
174 
175  req->Act();
176 
177  if (req->m_return_condition) {
178  req->m_return_condition->GetMutex()->Lock();
179  req->m_return_condition->Signal();
180  req->m_return_condition->GetMutex()->UnLock();
181  } else {
182  delete req;
183  }
184  }
185 }

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

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

◆ ShootRequest()

void TRootXTReq::ShootRequest ( )

Definition at line 65 of file TRootXTReq.cc.

65  {
66  // Places request into the queue and requests execution in Rint thread.
67  // It returns immediately after that, without waiting for execution.
68  // The request is deleted after execution.
69 
70  if (m_return_condition) {
71  delete m_return_condition;
72  m_return_condition = nullptr;
73  }
74 
75  post_request();
76 }

References m_return_condition, and post_request().

◆ ShootRequestAndWait()

void TRootXTReq::ShootRequestAndWait ( )

Definition at line 78 of file TRootXTReq.cc.

78  {
79  // Places request into the queue, requests execution in Rint thread and
80  // waits for the execution to be completed.
81  // The request is not deleted after execution as it might carry return
82  // value.
83  // The same request can be reused several times.
84 
85  if (!m_return_condition)
86  m_return_condition = new TCondition;
87 
88  m_return_condition->GetMutex()->Lock();
89 
90  post_request();
91 
92  m_return_condition->Wait();
93  m_return_condition->GetMutex()->UnLock();
94 }

References m_return_condition, and post_request().

◆ Shutdown()

void TRootXTReq::Shutdown ( )
static

Definition at line 143 of file TRootXTReq.cc.

143  {
144  static const TString _eh("TRootXTReq::Shutdown ");
145 
146  if (sRootThread == 0)
147  throw _eh + "Have not beem initialized.";
148 
149  // Should lock and drain queue ... or sth.
150 
151  sRootThread = 0;
152  delete sSigHandler;
153  sSigHandler = nullptr;
154  delete sQueueMutex;
155  sQueueMutex = nullptr;
156 }

References sQueueMutex, sRootThread, and sSigHandler.

Member Data Documentation

◆ m_return_condition

TCondition* TRootXTReq::m_return_condition
private

Definition at line 21 of file TRootXTReq.h.

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

◆ mName

TString TRootXTReq::mName
protected

Definition at line 32 of file TRootXTReq.h.

◆ sQueue

TRootXTReq::lpXTReq_t TRootXTReq::sQueue
staticprivate

Definition at line 23 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

◆ sQueueMutex

TMutex * TRootXTReq::sQueueMutex = nullptr
staticprivate

Definition at line 25 of file TRootXTReq.h.

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

◆ sRootThread

pthread_t TRootXTReq::sRootThread = 0
staticprivate

Definition at line 24 of file TRootXTReq.h.

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

◆ sSheduled

bool TRootXTReq::sSheduled = false
staticprivate

Definition at line 27 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

◆ sSigHandler

TSignalHandler * TRootXTReq::sSigHandler = nullptr
staticprivate

Definition at line 26 of file TRootXTReq.h.

Referenced by Bootstrap(), and Shutdown().

TRootXTReq::mName
TString mName
Definition: TRootXTReq.h:32
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TRootXTReq::sSigHandler
static TSignalHandler * sSigHandler
Definition: TRootXTReq.h:26
TRootXTReq::post_request
void post_request()
Definition: TRootXTReq.cc:54
TRootXTReq::m_return_condition
TCondition * m_return_condition
Definition: TRootXTReq.h:21
TRootXTReq::sQueueMutex
static TMutex * sQueueMutex
Definition: TRootXTReq.h:25
TRootXTReq::Act
virtual void Act()=0
TRootXTReq::sSheduled
static bool sSheduled
Definition: TRootXTReq.h:27
TRootXTReq
Definition: TRootXTReq.h:17
RootSig2XTReqHandler
Definition: TRootXTReq.cc:98
TRootXTReq::sRootThread
static pthread_t sRootThread
Definition: TRootXTReq.h:24
TRootXTReq::sQueue
static lpXTReq_t sQueue
Definition: TRootXTReq.h:23