1 //=============================================================================
3 * @file Timer_Cancellation_Test.cpp
5 * A test to ensure the timer cancellation works correctly.
7 * @author Irfan Pyarali <irfan@oomworks.com>
9 //=============================================================================
11 #include "test_config.h"
12 #include "ace/OS_NS_unistd.h"
13 #include "ace/Reactor.h"
14 #include "ace/TP_Reactor.h"
17 #if defined (ACE_HAS_THREADS)
19 class Deadlock
: public ACE_Task_Base
25 int handle_timeout (const ACE_Time_Value
¤t_time
,
33 ACE_TEXT ("Deadlock starts accessing Reactor and Timer Queue....\n")));
35 this->reactor ()->schedule_timer (this,
40 ACE_TEXT ("Deadlock completes accessing Reactor and Timer Queue....\n")));
46 Deadlock::handle_timeout (const ACE_Time_Value
&,
50 ACE_TEXT ("Deadlock timeout\n")));
55 class Event_Handler
: public ACE_Event_Handler
59 Event_Handler (Deadlock
&deadlock
);
61 int handle_timeout (const ACE_Time_Value
¤t_time
,
64 int handle_close (ACE_HANDLE handle
,
65 ACE_Reactor_Mask close_mask
);
70 Event_Handler::Event_Handler (Deadlock
&deadlock
)
71 : deadlock_ (deadlock
)
76 Event_Handler::handle_timeout (const ACE_Time_Value
&,
80 ACE_TEXT ("Event_Handler timeout\n")));
86 Event_Handler::handle_close (ACE_HANDLE
,
90 ACE_TEXT ("Event_Handler closed\n")));
93 this->deadlock_
.activate ();
95 // Give Deadlock a chance to deadlock... ;-)
99 ACE_TEXT ("Event Handler starts accessing Reactor....\n")));
101 // This is a superfluous call to the Reactor to acquire its lock.
102 this->reactor ()->max_notify_iterations ();
104 ACE_DEBUG ((LM_DEBUG
,
105 ACE_TEXT ("Event Handler completes accessing Reactor....\n")));
111 run_main (int, ACE_TCHAR
*[])
113 ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));
115 ACE_Reactor
reactor (new ACE_TP_Reactor
, true);
118 deadlock
.reactor (&reactor
);
120 Event_Handler
handler (deadlock
);
122 // Scheduler a timer to kick things off.
123 reactor
.schedule_timer (&handler
,
127 // Run the event loop for a while.
128 ACE_Time_Value
timeout (4);
129 reactor
.run_reactor_event_loop (timeout
);
136 #else /* ACE_HAS_THREADS */
139 run_main (int, ACE_TCHAR
*[])
141 ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));
144 ACE_TEXT ("threads not supported on this platform\n")));
151 #endif /* ACE_HAS_THREADS */