blob: 509cba175abf90d363ba9877c82c8b3efc37d310 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Listing 1 code/ch20
#include "ace/Timer_Queue.h"
#include "ace/Timer_Heap.h"
#include "ace/Timer_Wheel.h"
#include "ace/Timer_Hash.h"
#include "ace/Timer_List.h"
#include "CB.h"
#include "TimerDispatcher.h"
int ACE_TMAIN (int, ACE_TCHAR *[])
{
ACE_Timer_Queue *timer_queue;
#if defined(HEAP)
ACE_NEW_RETURN (timer_queue, ACE_Timer_Heap, -1);
#elsif defined(HASH)
ACE_NEW_RETURN (timer_queue, ACE_Timer_Hash, -1);
#elsif defined(WHEEL)
ACE_NEW_RETURN (timer_queue, ACE_Timer_Wheel, -1);
#else
ACE_NEW_RETURN (timer_queue, ACE_Timer_List, -1);
#endif
// setup the timer queue
Timer::instance ()->set (timer_queue);
CB cb[10];
long args[10];
for (long i = 0; i < 10 ; i++)
{
ACE_Time_Value const timeout (i);
long timerID =
Timer::instance ()->schedule
(&cb[i],
&args[i],
timer_queue->gettimeofday () + ACE_Time_Value(5),
timeout);
// Set the timerID state variable of the handler.
cb[i].setID (timerID);
// Implicitly send the handler it's timer id.
args[i] = timerID;
}
// "run" the timer.
Timer::instance ()->wait_for_event ();
return 0;
}
// Listing 1
|