Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Timer_Cancellation_Test.cpp
blobaf2a3fae4cb723a782db9b26d54bd6574d51b83f
1 //=============================================================================
2 /**
3 * @file Timer_Cancellation_Test.cpp
5 * A test to ensure the timer cancellation works correctly.
7 * @author Irfan Pyarali <irfan@oomworks.com>
8 */
9 //=============================================================================
11 #include "test_config.h"
12 #include "ace/OS_NS_unistd.h"
13 #include "ace/Reactor.h"
14 #include "ace/TP_Reactor.h"
15 #include "ace/Task.h"
17 #if defined (ACE_HAS_THREADS)
19 class Deadlock : public ACE_Task_Base
21 public:
22 int svc () override;
24 int handle_timeout (const ACE_Time_Value &current_time,
25 const void *act) override;
28 int
29 Deadlock::svc ()
31 ACE_DEBUG ((LM_DEBUG,
32 ACE_TEXT ("Deadlock starts accessing Reactor and Timer Queue....\n")));
34 this->reactor ()->schedule_timer (this,
36 ACE_Time_Value (1));
38 ACE_DEBUG ((LM_DEBUG,
39 ACE_TEXT ("Deadlock completes accessing Reactor and Timer Queue....\n")));
41 return 0;
44 int
45 Deadlock::handle_timeout (const ACE_Time_Value &,
46 const void *)
48 ACE_DEBUG ((LM_DEBUG,
49 ACE_TEXT ("Deadlock timeout\n")));
51 return 0;
54 class Event_Handler : public ACE_Event_Handler
56 public:
57 Event_Handler (Deadlock &deadlock);
59 int handle_timeout (const ACE_Time_Value &current_time,
60 const void *act) override;
62 int handle_close (ACE_HANDLE handle,
63 ACE_Reactor_Mask close_mask) override;
65 Deadlock &deadlock_;
68 Event_Handler::Event_Handler (Deadlock &deadlock)
69 : deadlock_ (deadlock)
73 int
74 Event_Handler::handle_timeout (const ACE_Time_Value &,
75 const void *)
77 ACE_DEBUG ((LM_DEBUG,
78 ACE_TEXT ("Event_Handler timeout\n")));
80 return -1;
83 int
84 Event_Handler::handle_close (ACE_HANDLE,
85 ACE_Reactor_Mask)
87 ACE_DEBUG ((LM_DEBUG,
88 ACE_TEXT ("Event_Handler closed\n")));
90 // Activate Deadlock.
91 this->deadlock_.activate ();
93 // Give Deadlock a chance to deadlock... ;-)
94 ACE_OS::sleep (1);
96 ACE_DEBUG ((LM_DEBUG,
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")));
105 return 0;
109 run_main (int, ACE_TCHAR *[])
111 ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));
113 ACE_Reactor reactor (new ACE_TP_Reactor, true);
115 Deadlock deadlock;
116 deadlock.reactor (&reactor);
118 Event_Handler handler (deadlock);
120 // Scheduler a timer to kick things off.
121 reactor.schedule_timer (&handler,
123 ACE_Time_Value (1));
125 // Run the event loop for a while.
126 ACE_Time_Value timeout (4);
127 reactor.run_reactor_event_loop (timeout);
129 ACE_END_TEST;
131 return 0;
134 #else /* ACE_HAS_THREADS */
137 run_main (int, ACE_TCHAR *[])
139 ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));
141 ACE_ERROR ((LM_INFO,
142 ACE_TEXT ("threads not supported on this platform\n")));
144 ACE_END_TEST;
146 return 0;
149 #endif /* ACE_HAS_THREADS */