XRootD
XrdSysCondVar Class Reference

#include <XrdSysPthread.hh>

+ Collaboration diagram for XrdSysCondVar:

Public Member Functions

 XrdSysCondVar (int relm=1, const char *cid=0)
 
 ~XrdSysCondVar ()
 
void Broadcast ()
 
void Lock ()
 
void Signal ()
 
void UnLock ()
 
int Wait ()
 
int Wait (int sec)
 
int WaitMS (int msec)
 

Detailed Description

Definition at line 78 of file XrdSysPthread.hh.

Constructor & Destructor Documentation

◆ XrdSysCondVar()

XrdSysCondVar::XrdSysCondVar ( int  relm = 1,
const char *  cid = 0 
)
inline

Definition at line 100 of file XrdSysPthread.hh.

102  {pthread_cond_init(&cvar, NULL);
103  pthread_mutex_init(&cmut, NULL);
104  relMutex = relm; condID = (cid ? cid : "unk");
105  }

◆ ~XrdSysCondVar()

XrdSysCondVar::~XrdSysCondVar ( )
inline

Definition at line 106 of file XrdSysPthread.hh.

106  {pthread_cond_destroy(&cvar);
107  pthread_mutex_destroy(&cmut);
108  }

Member Function Documentation

◆ Broadcast()

void XrdSysCondVar::Broadcast ( )
inline

Definition at line 89 of file XrdSysPthread.hh.

89  {if (relMutex) pthread_mutex_lock(&cmut);
90  pthread_cond_broadcast(&cvar);
91  if (relMutex) pthread_mutex_unlock(&cmut);
92  }

Referenced by XrdOssCsiFile::aioDec(), XrdOssCsiFile::aioWait(), XrdCl::XCpCtx::GetChunk(), XrdPfc::Cache::GetFile(), XrdCl::SyncResponseHandler::HandleResponse(), XrdCl::XCpCtx::NotifyIdleSrc(), XrdCl::XCpCtx::NotifyInitExpectant(), XrdCl::XCpCtx::SetFileSize(), and XrdOssCsiPages::TrackedSizeRelease().

+ Here is the caller graph for this function:

◆ Lock()

◆ Signal()

void XrdSysCondVar::Signal ( )
inline

Definition at line 84 of file XrdSysPthread.hh.

84  {if (relMutex) pthread_mutex_lock(&cmut);
85  pthread_cond_signal(&cvar);
86  if (relMutex) pthread_mutex_unlock(&cmut);
87  }

Referenced by XrdOfsHanXpr::add2Q(), XrdLinkXeq::Close(), XrdPfc::IO::ReadReqRHCond::Done(), XrdBuffManager::Obtain(), XrdPfc::ResourceMonitor::perform_purge_task_cleanup(), XrdSysSemWait::Post(), XrdOfsPrepGPIReal::PrepGPI::query(), XrdPfc::Cache::RegisterPrefetchFile(), XrdCmsClientMsg::Reply(), XrdScheduler::Schedule(), and XrdTlsFlush::Setup_Flusher().

+ Here is the caller graph for this function:

◆ UnLock()

◆ Wait() [1/2]

int XrdSysCondVar::Wait ( )

Definition at line 99 of file XrdSysPthread.cc.

100 {
101  int retc;
102 
103 // Wait for the condition
104 //
105  if (relMutex) Lock();
106  retc = pthread_cond_wait(&cvar, &cmut);
107  if (relMutex) UnLock();
108  return retc;
109 }

References Lock(), and UnLock().

Referenced by XrdOssCsiFile::aioInc(), XrdOssCsiFile::aioWait(), XrdCl::XCpCtx::AllDone(), XrdThrottleManager::Apply(), XrdPfc::ResourceMonitor::CrossCheckIfScanIsInProgress(), XrdCl::XRootDMsgHandler::Examine(), XrdTlsFlush::Flusher(), XrdOfsHanXpr::Get(), XrdPfc::Cache::GetFile(), XrdPfc::Cache::GetNextFileToPrefetch(), XrdCl::XCpCtx::GetSize(), XrdOfsPrepGPIReal::PrepGPI::query(), XrdPfc::IOFileBlock::Read(), XrdBuffManager::Reshape(), XrdThrottleManager::StartIOTimer(), XrdLink::Terminate(), XrdScheduler::TimeSched(), XrdOssCsiPages::TrackedSizesGet(), XrdSysSemWait::Wait(), XrdCmsClientMsg::Wait4Reply(), and XrdCl::SyncResponseHandler::WaitForResponse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Wait() [2/2]

int XrdSysCondVar::Wait ( int  sec)

Definition at line 113 of file XrdSysPthread.cc.

113 {return WaitMS(sec*1000);}
int WaitMS(int msec)

References WaitMS().

+ Here is the call graph for this function:

◆ WaitMS()

int XrdSysCondVar::WaitMS ( int  msec)

Definition at line 119 of file XrdSysPthread.cc.

120 {
121  int sec, retc, usec;
122  struct timeval tnow;
123  struct timespec tval;
124 
125 // Adjust millseconds
126 //
127  if (msec < 1000) sec = 0;
128  else {sec = msec / 1000; msec = msec % 1000;}
129  usec = msec * 1000;
130 
131 // Get the mutex before getting the time
132 //
133  if (relMutex) Lock();
134 
135 // Get current time of day
136 //
137  gettimeofday(&tnow, 0);
138 
139 // Add the second and microseconds
140 //
141  tval.tv_sec = tnow.tv_sec + sec;
142  tval.tv_nsec = tnow.tv_usec + usec;
143  if (tval.tv_nsec >= 1000000)
144  {tval.tv_sec += tval.tv_nsec / 1000000;
145  tval.tv_nsec = tval.tv_nsec % 1000000;
146  }
147  tval.tv_nsec *= 1000;
148 
149 
150 // Now wait for the condition or timeout
151 //
152  do {retc = pthread_cond_timedwait(&cvar, &cmut, &tval);}
153  while (retc && (retc == EINTR));
154 
155  if (relMutex) UnLock();
156 
157 // Determine how to return
158 //
159  if (retc && retc != ETIMEDOUT) {throw "cond_timedwait() failed";}
160  return retc == ETIMEDOUT;
161 }

References Lock(), and UnLock().

Referenced by Wait().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: