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
24 int handle_timeout (const ACE_Time_Value
¤t_time
,
25 const void *act
) override
;
32 ACE_TEXT ("Deadlock starts accessing Reactor and Timer Queue....\n")));
34 this->reactor ()->schedule_timer (this,
39 ACE_TEXT ("Deadlock completes accessing Reactor and Timer Queue....\n")));
45 Deadlock::handle_timeout (const ACE_Time_Value
&,
49 ACE_TEXT ("Deadlock timeout\n")));
54 class Event_Handler
: public ACE_Event_Handler
57 Event_Handler (Deadlock
&deadlock
);
59 int handle_timeout (const ACE_Time_Value
¤t_time
,
60 const void *act
) override
;
62 int handle_close (ACE_HANDLE handle
,
63 ACE_Reactor_Mask close_mask
) override
;
68 Event_Handler::Event_Handler (Deadlock
&deadlock
)
69 : deadlock_ (deadlock
)
74 Event_Handler::handle_timeout (const ACE_Time_Value
&,
78 ACE_TEXT ("Event_Handler timeout\n")));
84 Event_Handler::handle_close (ACE_HANDLE
,
88 ACE_TEXT ("Event_Handler closed\n")));
91 this->deadlock_
.activate ();
93 // Give Deadlock a chance to deadlock... ;-)
97 ACE_TEXT ("Event Handler starts accessing Reactor....\n")));
99 // This is a superfluous call to the Reactor to acquire its lock.
100 this->reactor ()->max_notify_iterations ();
102 ACE_DEBUG ((LM_DEBUG
,
103 ACE_TEXT ("Event Handler completes accessing Reactor....\n")));
109 run_main (int, ACE_TCHAR
*[])
111 ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));
113 ACE_Reactor
reactor (new ACE_TP_Reactor
, true);
116 deadlock
.reactor (&reactor
);
118 Event_Handler
handler (deadlock
);
120 // Scheduler a timer to kick things off.
121 reactor
.schedule_timer (&handler
,
125 // Run the event loop for a while.
126 ACE_Time_Value
timeout (4);
127 reactor
.run_reactor_event_loop (timeout
);
134 #else /* ACE_HAS_THREADS */
137 run_main (int, ACE_TCHAR
*[])
139 ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));
142 ACE_TEXT ("threads not supported on this platform\n")));
149 #endif /* ACE_HAS_THREADS */