mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-08 14:41:57 +08:00
CTimerThread now allows zero and negative timeouts. a negative
timeout never times out and CTimerThread is a no-op.
This commit is contained in:
@@ -10,20 +10,27 @@
|
||||
|
||||
CTimerThread::CTimerThread(double timeout) : m_timeout(timeout)
|
||||
{
|
||||
assert(m_timeout > 0.0);
|
||||
m_callingThread = new CThread(CThread::getCurrentThread());
|
||||
m_timingThread = new CThread(new TMethodJob<CTimerThread>(
|
||||
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()
|
||||
{
|
||||
log((CLOG_DEBUG1 "cancelling timeout"));
|
||||
m_timingThread->cancel();
|
||||
m_timingThread->wait();
|
||||
log((CLOG_DEBUG1 "cancelled timeout"));
|
||||
delete m_timingThread;
|
||||
delete m_callingThread;
|
||||
if (m_timingThread != NULL) {
|
||||
log((CLOG_DEBUG1 "cancelling timeout"));
|
||||
m_timingThread->cancel();
|
||||
m_timingThread->wait();
|
||||
log((CLOG_DEBUG1 "cancelled timeout"));
|
||||
delete m_timingThread;
|
||||
delete m_callingThread;
|
||||
}
|
||||
}
|
||||
|
||||
void CTimerThread::timer(void*)
|
||||
|
||||
Reference in New Issue
Block a user