2001-10-06 18:13:28 +04:00
|
|
|
#include "CTimerThread.h"
|
|
|
|
#include "CThread.h"
|
|
|
|
#include "TMethodJob.h"
|
2001-10-14 22:29:43 +04:00
|
|
|
#include "CLog.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
//
|
|
|
|
// CTimerThread
|
|
|
|
//
|
|
|
|
|
|
|
|
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>(
|
|
|
|
this, &CTimerThread::timer));
|
|
|
|
}
|
|
|
|
|
|
|
|
CTimerThread::~CTimerThread()
|
|
|
|
{
|
2002-04-27 22:49:03 +04:00
|
|
|
log((CLOG_DEBUG1 "cancelling timeout"));
|
2001-10-06 18:13:28 +04:00
|
|
|
m_timingThread->cancel();
|
2001-10-14 23:16:54 +04:00
|
|
|
m_timingThread->wait();
|
2002-04-27 22:49:03 +04:00
|
|
|
log((CLOG_DEBUG1 "cancelled timeout"));
|
2001-10-06 18:13:28 +04:00
|
|
|
delete m_timingThread;
|
|
|
|
delete m_callingThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTimerThread::timer(void*)
|
|
|
|
{
|
2002-04-27 22:49:03 +04:00
|
|
|
log((CLOG_DEBUG1 "timeout in %f seconds", m_timeout));
|
2001-10-06 18:13:28 +04:00
|
|
|
CThread::sleep(m_timeout);
|
2002-04-27 22:49:03 +04:00
|
|
|
log((CLOG_DEBUG1 "timeout"));
|
2001-10-06 18:13:28 +04:00
|
|
|
m_callingThread->cancel();
|
|
|
|
}
|