CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 = 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

typedef std::list<TRootXTReq *> TRootXTReq::lpXTReq_t
private

Definition at line 19 of file TRootXTReq.h.

Constructor & Destructor Documentation

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

Definition at line 48 of file TRootXTReq.cc.

48 : m_return_condition(nullptr), mName(n) {}
TCondition * m_return_condition
Definition: TRootXTReq.h:21
TString mName
Definition: TRootXTReq.h:32
TRootXTReq::~TRootXTReq ( )
virtual

Definition at line 50 of file TRootXTReq.cc.

References m_return_condition.

50 { delete m_return_condition; }
TCondition * m_return_condition
Definition: TRootXTReq.h:21

Member Function Documentation

virtual void TRootXTReq::Act ( )
privatepure virtual

Referenced by ProcessQueue().

void TRootXTReq::Bootstrap ( pthread_t  root_thread)
static

Definition at line 132 of file TRootXTReq.cc.

References sQueueMutex, sRootThread, and sSigHandler.

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 }
static pthread_t sRootThread
Definition: TRootXTReq.h:24
static TSignalHandler * sSigHandler
Definition: TRootXTReq.h:26
static TMutex * sQueueMutex
Definition: TRootXTReq.h:25
void TRootXTReq::post_request ( )
protected

Definition at line 54 of file TRootXTReq.cc.

References sQueue, sQueueMutex, sRootThread, and sSheduled.

Referenced by ShootRequest(), and ShootRequestAndWait().

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 }
static pthread_t sRootThread
Definition: TRootXTReq.h:24
static lpXTReq_t sQueue
Definition: TRootXTReq.h:23
static bool sSheduled
Definition: TRootXTReq.h:27
static TMutex * sQueueMutex
Definition: TRootXTReq.h:25
void TRootXTReq::ProcessQueue ( )
static

Definition at line 158 of file TRootXTReq.cc.

References Act(), m_return_condition, gpuVertexFinder::printf(), sQueue, sQueueMutex, and sSheduled.

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

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 }
TCondition * m_return_condition
Definition: TRootXTReq.h:21
virtual void Act()=0
static lpXTReq_t sQueue
Definition: TRootXTReq.h:23
static bool sSheduled
Definition: TRootXTReq.h:27
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
static TMutex * sQueueMutex
Definition: TRootXTReq.h:25
void TRootXTReq::ShootRequest ( )

Definition at line 65 of file TRootXTReq.cc.

References m_return_condition, and post_request().

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 }
TCondition * m_return_condition
Definition: TRootXTReq.h:21
void post_request()
Definition: TRootXTReq.cc:54
void TRootXTReq::ShootRequestAndWait ( )

Definition at line 78 of file TRootXTReq.cc.

References m_return_condition, and post_request().

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 }
TCondition * m_return_condition
Definition: TRootXTReq.h:21
void post_request()
Definition: TRootXTReq.cc:54
void TRootXTReq::Shutdown ( )
static

Definition at line 143 of file TRootXTReq.cc.

References sQueueMutex, sRootThread, and sSigHandler.

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 }
static pthread_t sRootThread
Definition: TRootXTReq.h:24
static TSignalHandler * sSigHandler
Definition: TRootXTReq.h:26
static TMutex * sQueueMutex
Definition: TRootXTReq.h:25

Member Data Documentation

TCondition* TRootXTReq::m_return_condition
private

Definition at line 21 of file TRootXTReq.h.

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

TString TRootXTReq::mName
protected

Definition at line 32 of file TRootXTReq.h.

TRootXTReq::lpXTReq_t TRootXTReq::sQueue
staticprivate

Definition at line 23 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TMutex * TRootXTReq::sQueueMutex = nullptr
staticprivate

Definition at line 25 of file TRootXTReq.h.

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

pthread_t TRootXTReq::sRootThread = 0
staticprivate

Definition at line 24 of file TRootXTReq.h.

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

bool TRootXTReq::sSheduled = false
staticprivate

Definition at line 27 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TSignalHandler * TRootXTReq::sSigHandler = nullptr
staticprivate

Definition at line 26 of file TRootXTReq.h.

Referenced by Bootstrap(), and Shutdown().