Skip to content
Snippets Groups Projects
Commit 72c785eb authored by Fons Rademakers's avatar Fons Rademakers
Browse files

add TCondition::TimedWait() that takes a relative wait time in milliseconds.

git-svn-id: http://root.cern.ch/svn/root/trunk@10787 27541ba8-7e3a-0410-8455-c3a389f83636
parent 12b3dd13
Branches
Tags
No related merge requests found
// @(#)root/thread:$Name: $:$Id: TCondition.h,v 1.2 2002/12/03 16:44:25 brun Exp $
// @(#)root/thread:$Name: $:$Id: TCondition.h,v 1.3 2004/12/10 12:13:33 rdm Exp $
// Author: Fons Rademakers 01/07/97
/*************************************************************************
......@@ -49,7 +49,8 @@ public:
TMutex *GetMutex() const;
Int_t Wait();
Int_t TimedWait(ULong_t secs, ULong_t nanoSecs = 0);
Int_t TimedWait(ULong_t secs, ULong_t nanoSecs);
Int_t TimedWait(ULong_t ms);
Int_t Signal() { if (fConditionImp) return fConditionImp->Signal(); return -1; }
Int_t Broadcast() { if (fConditionImp) return fConditionImp->Broadcast(); return -1; }
......
// @(#)root/thread:$Name: $:$Id: TCondition.cxx,v 1.3 2004/12/10 22:27:21 rdm Exp $
// @(#)root/thread:$Name: $:$Id: TCondition.cxx,v 1.4 2004/12/14 15:06:18 rdm Exp $
// Author: Fons Rademakers 01/07/97
/*************************************************************************
......@@ -86,7 +86,11 @@ Int_t TCondition::Wait()
//______________________________________________________________________________
Int_t TCondition::TimedWait(ULong_t secs, ULong_t nanoSec)
{
// Wait not more than secs+nanoSecs to be signaled.
// Wait to be signaled or till the timer times out.
// This method is given an absolute time since the beginning of
// the EPOCH (use TThread::GetTime() to get this absolute time).
// To wait for a relative time from now, use
// TCondition::TimedWait(ULong_t ms).
// Returns 0 if successfully signalled, 1 if time expired and -1 in
// case of error.
......@@ -99,3 +103,25 @@ Int_t TCondition::TimedWait(ULong_t secs, ULong_t nanoSec)
if (fPrivateMutex) fMutex->UnLock();
return iret;
}
//______________________________________________________________________________
Int_t TCondition::TimedWait(ULong_t ms)
{
// Wait to be signaled or till the timer times out.
// This method is given a relative time from now.
// To wait for an absolute time since the beginning of the EPOCH, use
// TCondition::TimedWait(ULong_t secs, ULong_t nanoSec).
// Returns 0 if successfully signalled, 1 if time expired and -1 in
// case of error.
if (!fConditionImp) return -1;
ULong_t absSec, absNanoSec;
TThread::GetTime(&absSec, &absNanoSec);
ULong_t dsec = ms/1000;
absSec += dsec;
absNanoSec += (ms - dsec*1000) * 1000000;
return TimedWait(absSec, absNanoSec);
}
// @(#)root/thread:$Name: $:$Id: TThread.cxx,v 1.28 2004/12/14 16:56:11 rdm Exp $
// @(#)root/thread:$Name: $:$Id: TThread.cxx,v 1.29 2004/12/14 17:39:36 rdm Exp $
// Author: Fons Rademakers 02/07/97
/*************************************************************************
......@@ -108,9 +108,7 @@ Int_t TJoinHelper::Join()
ULong_t absSec, absNanoSec;
while (kTRUE) {
TThread::GetTime(&absSec, &absNanoSec);
absNanoSec += 100 * 1000000;
int r = fC->TimedWait(absSec, absNanoSec); // 100 ms
int r = fC->TimedWait(100); // 100 ms
if (r == 0) break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment