CTimerThread now allows zero and negative timeouts. a negative
timeout never times out and CTimerThread is a no-op.
This commit is contained in:
parent
db8165db09
commit
30a6a8b837
|
@ -10,14 +10,20 @@
|
|||
|
||||
CTimerThread::CTimerThread(double timeout) : m_timeout(timeout)
|
||||
{
|
||||
assert(m_timeout > 0.0);
|
||||
if (m_timeout >= 0.0) {
|
||||
m_callingThread = new CThread(CThread::getCurrentThread());
|
||||
m_timingThread = new CThread(new TMethodJob<CTimerThread>(
|
||||
this, &CTimerThread::timer));
|
||||
}
|
||||
else {
|
||||
m_callingThread = NULL;
|
||||
m_timingThread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CTimerThread::~CTimerThread()
|
||||
{
|
||||
if (m_timingThread != NULL) {
|
||||
log((CLOG_DEBUG1 "cancelling timeout"));
|
||||
m_timingThread->cancel();
|
||||
m_timingThread->wait();
|
||||
|
@ -25,6 +31,7 @@ CTimerThread::~CTimerThread()
|
|||
delete m_timingThread;
|
||||
delete m_callingThread;
|
||||
}
|
||||
}
|
||||
|
||||
void CTimerThread::timer(void*)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,9 @@ class CThread;
|
|||
|
||||
class CTimerThread {
|
||||
public:
|
||||
// cancels the calling thread after timeout seconds unless destroyed
|
||||
// before then. if timeout is less than zero then it never times
|
||||
// out and is a no-op.
|
||||
CTimerThread(double timeout);
|
||||
~CTimerThread();
|
||||
|
||||
|
|
Loading…
Reference in New Issue