|
发表于 2009-1-9 13:58:55
|
显示全部楼层
经过测试,没有发现你说的情况,测试代码如下:
#include "ace/Timer_Queue.h"
#include "ace/Reactor.h"
#include "ace/High_Res_Timer.h"
#include "ace/Trace.h"
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Log_Msg.h"
ACE_Time_Value g_begin_time, g_end_time;
class CTimerHrTest: public ACE_Event_Handler
{
public:
int open()
{
ACE_Time_Value timer_interval(600);
m_timer_id = ACE_Reactor::instance ()->schedule_timer(this, 0, timer_interval, timer_interval);
g_begin_time = ACE_OS::gettimeofday();
ACE_Time_Value tm = ACE_High_Res_Timer::gettimeofday_hr();
ACE_DEBUG((LM_DEBUG, ACE_TEXT("begin absolute timer: %d\n"), g_begin_time.sec()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("begin tick timer: %d\n"), tm.sec() ));
if ( m_timer_id == -1 )
{
ACE_ERROR_RETURN((LM_ERROR, "%p\n", "schedule_timer failed."),-1);
}
return 0;
}
virtual int handle_timeout(const ACE_Time_Value &tm, const void *)
{
// ACE_Time_Value tmp = tm - g_begin_time;
g_end_time = ACE_OS::gettimeofday();
ACE_DEBUG((LM_DEBUG, ACE_TEXT("end absolute timer: %d\n"),
(g_end_time.sec() - g_begin_time.sec()) ));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("end tick timer: %d\n"), tm.sec() ));
return 0;
}
virtual int handle_close()
{
ACE_Reactor::instance ()->cancel_timer(m_timer_id);
delete this;
return 0;
}
private:
long m_timer_id;
};
int ACE_TMAIN(int argc, ACE_TCHAR **argv)
{
ACE_High_Res_Timer::global_scale_factor ();
// test timer source
ACE_Reactor::instance()->timer_queue()->gettimeofday(&ACE_High_Res_Timer::gettimeofday_hr);
CTimerHrTest timer_test;
if ( timer_test.open() == -1 )
{
ACE_DEBUG(( LM_DEBUG, ACE_TEXT("(%t) Timer_open failed\n") ));
return -1;
}
ACE_Reactor::instance()->run_event_loop();
}
测试结果: (Linux AS 4u5)
begin absolute timer: 1231479901
begin tick timer: 170079
end absolute timer: 600
end tick timer: 170679 |
|