1 //=============================================================================
3 * @file test_end_event_loop.cpp
5 * This program tests the event loop mechanism of the
6 * Proactor. To end the event loop, threads that are blocked in
7 * waiting for completions are woken up and the event loop comes
8 * to the end. This is tested in this program.
9 * Threads are doing <run_event_loop> with/without time_out
10 * values and the main thread calls <end_event_loop>.
12 * ./test_end_event_loop
14 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
16 //=============================================================================
19 #include "ace/OS_NS_unistd.h"
20 #include "ace/Proactor.h"
22 #include "ace/WIN32_Proactor.h"
23 #include "ace/POSIX_Proactor.h"
24 #include "ace/OS_main.h"
26 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
27 // This only works on Win32 platforms and on Unix platforms supporting
33 * @brief Contains thread functions which execute event loops. Each
34 * thread waits for a different signal.
36 class My_Task
: public ACE_Task
<ACE_NULL_SYNCH
>
45 virtual ~My_Task () {}
47 //FUZZ: disable check_for_lack_ACE_OS
48 // If time_flag is zero do the eventloop indefinitely, otherwise do
49 // it for finite amount of time (13secs!!!).
50 int open (void *timed_event_loop
)
52 //FUZZ: enble check_for_lack_ACE_OS
54 // Set the local variable.
55 if (timed_event_loop
== 0)
61 if (this->activate (THR_NEW_LWP
, 5) == -1)
62 ACE_ERROR_RETURN ((LM_ERROR
,
64 "My_Task:open: <activate> failed"),
74 "(%P|%t):Starting svc routine\n"));
79 "(%P|%t):Going to do *timed* <run_event_loop>\n"));
81 ACE_Time_Value
run_time (13);
83 if (ACE_Proactor::instance ()->run_event_loop (run_time
) == -1)
84 ACE_ERROR_RETURN ((LM_ERROR
, "(%P|%t):%p.\n",
85 "<Proactor::run_event_loop> failed"),
91 "(%P|%t):Going to do *indefinite* <run_event_loop>\n"));
93 if (ACE_Proactor::instance ()->run_event_loop () == -1)
94 ACE_ERROR_RETURN ((LM_ERROR
, "(%P|%t):%p.\n",
95 "<Proactor::run_event_loop> failed"),
102 /// If zero, indefinite event loop, otherwise timed event loop.
107 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
109 ACE_UNUSED_ARG (argc
);
110 ACE_UNUSED_ARG (argv
);
112 ACE_DEBUG ((LM_DEBUG
,
113 "(%P | %t):Test starts\n"));
115 // Let us get the singleton proactor created here. This is very
116 // important. This will mask the signal used in the Proactor masked
117 // for the main thread (and all the threads).
118 ACE_Proactor
*proactor
= ACE_Proactor::instance ();
119 ACE_UNUSED_ARG (proactor
);
121 My_Task task1
, task2
;
123 // Test the indefinite run event loop.
124 if (task1
.open (0) == -1)
125 ACE_ERROR_RETURN ((LM_ERROR
,
126 "%N:%l:(%P | %t):Failed to <open> the task\n"),
129 // Test the indefinite run event loop. Just pass a non-zero.
130 if (task2
.open ((void *)&task2
) == -1)
131 ACE_ERROR_RETURN ((LM_ERROR
,
132 "%N:%l:(%P | %t):Failed to <open> the task\n"),
138 // End the event loop.
139 if (ACE_Proactor::instance ()->end_event_loop () == -1)
140 ACE_ERROR_RETURN ((LM_ERROR
,
141 "%N:%l:(%P | %t):Failed to <end_event_loop>\n"),
144 ACE_Thread_Manager::instance ()->wait ();
146 ACE_DEBUG ((LM_DEBUG
,
147 "(%P | %t):Test ends\n"));
151 #else /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
154 ACE_TMAIN (int, ACE_TCHAR
*[])
156 ACE_DEBUG ((LM_DEBUG
,
157 "This example cannot work with AIOCB_Proactor.\n"));
161 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */