Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / APG / Timers / Timers.cpp
blob9c223efe52b0b6f72b65bf6fadd2686b3e21a12a
1 // Listing 1 code/ch20
2 #include "ace/Timer_Queue.h"
3 #include "ace/Timer_Heap.h"
4 #include "ace/Timer_Wheel.h"
5 #include "ace/Timer_Hash.h"
6 #include "ace/Timer_List.h"
8 #include "CB.h"
9 #include "TimerDispatcher.h"
11 int ACE_TMAIN (int, ACE_TCHAR *[])
13 ACE_Timer_Queue *timer_queue;
15 #if defined(HEAP)
17 ACE_NEW_RETURN (timer_queue, ACE_Timer_Heap, -1);
18 #elif defined(HASH)
20 ACE_NEW_RETURN (timer_queue, ACE_Timer_Hash, -1);
21 #elif defined(WHEEL)
23 ACE_NEW_RETURN (timer_queue, ACE_Timer_Wheel, -1);
24 #else
26 ACE_NEW_RETURN (timer_queue, ACE_Timer_List, -1);
27 #endif
29 // setup the timer queue
30 Timer::instance ()->set (timer_queue);
32 CB cb[10];
33 long args[10];
34 for (long i = 0; i < 10 ; i++)
36 ACE_Time_Value const timeout (i);
37 long timerID =
38 Timer::instance ()->schedule
39 (&cb[i],
40 &args[i],
41 timer_queue->gettimeofday () + ACE_Time_Value(5),
42 timeout);
44 // Set the timerID state variable of the handler.
45 cb[i].setID (timerID);
47 // Implicitly send the handler it's timer id.
48 args[i] = timerID;
51 // "run" the timer.
52 Timer::instance ()->wait_for_event ();
54 return 0;
56 // Listing 1