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
|
|
|
|
|
|
|
//
|
|
|
|
// CTimerThread
|
|
|
|
//
|
|
|
|
|
|
|
|
CTimerThread::CTimerThread(double timeout) : m_timeout(timeout)
|
|
|
|
{
|
2002-06-10 02:20:01 +04:00
|
|
|
if (m_timeout >= 0.0) {
|
|
|
|
m_callingThread = new CThread(CThread::getCurrentThread());
|
|
|
|
m_timingThread = new CThread(new TMethodJob<CTimerThread>(
|
2001-10-06 18:13:28 +04:00
|
|
|
this, &CTimerThread::timer));
|
2002-06-10 02:20:01 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_callingThread = NULL;
|
|
|
|
m_timingThread = NULL;
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CTimerThread::~CTimerThread()
|
|
|
|
{
|
2002-06-10 02:20:01 +04:00
|
|
|
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;
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CTimerThread::timer(void*)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
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();
|
|
|
|
}
|