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,20 +10,27 @@
|
||||||
|
|
||||||
CTimerThread::CTimerThread(double timeout) : m_timeout(timeout)
|
CTimerThread::CTimerThread(double timeout) : m_timeout(timeout)
|
||||||
{
|
{
|
||||||
assert(m_timeout > 0.0);
|
if (m_timeout >= 0.0) {
|
||||||
m_callingThread = new CThread(CThread::getCurrentThread());
|
m_callingThread = new CThread(CThread::getCurrentThread());
|
||||||
m_timingThread = new CThread(new TMethodJob<CTimerThread>(
|
m_timingThread = new CThread(new TMethodJob<CTimerThread>(
|
||||||
this, &CTimerThread::timer));
|
this, &CTimerThread::timer));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_callingThread = NULL;
|
||||||
|
m_timingThread = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CTimerThread::~CTimerThread()
|
CTimerThread::~CTimerThread()
|
||||||
{
|
{
|
||||||
log((CLOG_DEBUG1 "cancelling timeout"));
|
if (m_timingThread != NULL) {
|
||||||
m_timingThread->cancel();
|
log((CLOG_DEBUG1 "cancelling timeout"));
|
||||||
m_timingThread->wait();
|
m_timingThread->cancel();
|
||||||
log((CLOG_DEBUG1 "cancelled timeout"));
|
m_timingThread->wait();
|
||||||
delete m_timingThread;
|
log((CLOG_DEBUG1 "cancelled timeout"));
|
||||||
delete m_callingThread;
|
delete m_timingThread;
|
||||||
|
delete m_callingThread;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTimerThread::timer(void*)
|
void CTimerThread::timer(void*)
|
||||||
|
|
|
@ -7,6 +7,9 @@ class CThread;
|
||||||
|
|
||||||
class CTimerThread {
|
class CTimerThread {
|
||||||
public:
|
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(double timeout);
|
||||||
~CTimerThread();
|
~CTimerThread();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue