CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes

TRootXTReq Class Reference

#include <TRootXTReq.h>

List of all members.

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

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

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.

TRootXTReq::~TRootXTReq ( ) [virtual]

Definition at line 56 of file TRootXTReq.cc.

References m_return_condition.

{
   delete m_return_condition;
}

Member Function Documentation

virtual void TRootXTReq::Act ( ) [private, pure 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.

{
   static const TString _eh("TRootXTReq::Bootstrap ");

   if (sRootThread != 0)
      throw _eh + "Already initialized.";

   sRootThread = root_thread;
   sQueueMutex = new TMutex(kTRUE);
   sSigHandler = new RootSig2XTReqHandler;
}
void TRootXTReq::post_request ( ) [protected]

Definition at line 63 of file TRootXTReq.cc.

References sQueue, sQueueMutex, sRootThread, and sSheduled.

Referenced by ShootRequest(), and ShootRequestAndWait().

{
   TLockGuard _lck(sQueueMutex);

   sQueue.push_back(this);

   if ( ! sSheduled)
   {
      sSheduled = true;
      pthread_kill(sRootThread, SIGUSR1);
   }
}
void TRootXTReq::ProcessQueue ( ) [static]

Definition at line 178 of file TRootXTReq.cc.

References Act(), m_return_condition, cmsDownloadME::req, sQueue, sQueueMutex, and sSheduled.

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

{
   printf("Timer fired, processing queue.\n");

   while (true)
   {
      TRootXTReq *req = 0;
      {
         TLockGuard _lck(sQueueMutex);

         if ( ! sQueue.empty())
         {
            req = sQueue.front();
            sQueue.pop_front();
         }
         else
         {
            sSheduled = false;
            break;
         }
      }

      req->Act();

      if (req->m_return_condition)
      {
         req->m_return_condition->GetMutex()->Lock();
         req->m_return_condition->Signal();
         req->m_return_condition->GetMutex()->UnLock();
      }
      else
      {
         delete req;
      }
   }
}
void TRootXTReq::ShootRequest ( )

Definition at line 76 of file TRootXTReq.cc.

References m_return_condition, and post_request().

{
   // Places request into the queue and requests execution in Rint thread.
   // It returns immediately after that, without waiting for execution.
   // The request is deleted after execution.

   if (m_return_condition)
   {
      delete m_return_condition;
      m_return_condition = 0;
   }

   post_request();
}
void TRootXTReq::ShootRequestAndWait ( )

Definition at line 91 of file TRootXTReq.cc.

References m_return_condition, and post_request().

{
   // Places request into the queue, requests execution in Rint thread and
   // waits for the execution to be completed.
   // The request is not deleted after execution as it might carry return
   // value.
   // The same request can be reused several times.

   if (!m_return_condition)
      m_return_condition = new TCondition;

   m_return_condition->GetMutex()->Lock();

   post_request();

   m_return_condition->Wait();
   m_return_condition->GetMutex()->UnLock();
}
void TRootXTReq::Shutdown ( ) [static]

Definition at line 164 of file TRootXTReq.cc.

References sQueueMutex, sRootThread, and sSigHandler.

{
   static const TString _eh("TRootXTReq::Shutdown ");

   if (sRootThread == 0)
      throw _eh + "Have not beem initialized.";

   // Should lock and drain queue ... or sth.

   sRootThread = 0;
   delete sSigHandler; sSigHandler = 0;
   delete sQueueMutex; sQueueMutex = 0;
}

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.

Definition at line 25 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TMutex * TRootXTReq::sQueueMutex = 0 [static, private]

Definition at line 27 of file TRootXTReq.h.

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

pthread_t TRootXTReq::sRootThread = 0 [static, private]

Definition at line 26 of file TRootXTReq.h.

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

bool TRootXTReq::sSheduled = false [static, private]

Definition at line 29 of file TRootXTReq.h.

Referenced by post_request(), and ProcessQueue().

TSignalHandler * TRootXTReq::sSigHandler = 0 [static, private]

Definition at line 28 of file TRootXTReq.h.

Referenced by Bootstrap(), and Shutdown().