1 #include "ace/OS_NS_unistd.h"
2 #include "ace/OS_NS_sys_time.h"
5 #include "ace/Timer_Queue_Adapters.h"
6 #include "ace/Timer_Heap.h"
8 typedef ACE_Async_Timer_Queue_Adapter
<ACE_Timer_Heap
> Timer
;
11 class CB
: public ACE_Event_Handler
14 CB (int id
) : id_(id
) { }
16 virtual int handle_timeout (const ACE_Time_Value
&,
19 ACE_TRACE ("CB::handle_timeout");
21 const int *val
= static_cast<const int*> (arg
);
22 ACE_ASSERT ((*val
) == id_
);
26 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Timer expired\n")));
34 // Listing 2 code/ch20
35 int ACE_TMAIN (int, ACE_TCHAR
*[])
37 // Create the timer such that it blocks all signals
41 // Schedule a timer to go off 2 seconds later and then
42 // after every 4 seconds.
45 ACE_Time_Value
initial (2);
46 ACE_Time_Value
repeat (4);
47 initial
+= ACE_OS::gettimeofday ();
48 timer
.schedule (&cb
, &arg
, initial
, repeat
);
50 while (1) // Don't let the main thread exit.
52 ACE_NOTREACHED (return 0); // Not reached.