Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / examples / Reactor / Proactor / test_end_event_loop.cpp
blob853750bbb6c39608559b0fb462bf929f6392207f
1 //=============================================================================
2 /**
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>.
11 * make
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"
21 #include "ace/Task.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
28 // POSIX aio calls.
30 /**
31 * @class My_Task:
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>
38 public:
39 // Constructor.
40 My_Task ()
41 : time_flag_ (0)
44 /// Destructor.
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)
56 this->time_flag_ = 0;
57 else
58 this->time_flag_ = 1;
60 // Spawn the threads.
61 if (this->activate (THR_NEW_LWP, 5) == -1)
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "%N:%l:%p\n",
64 "My_Task:open: <activate> failed"),
65 -1);
67 return 0;
70 // Thread function.
71 int svc ()
73 ACE_DEBUG ((LM_DEBUG,
74 "(%P|%t):Starting svc routine\n"));
76 if (this->time_flag_)
78 ACE_DEBUG ((LM_DEBUG,
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"),
86 -1);
88 else
90 ACE_DEBUG ((LM_DEBUG,
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"),
96 -1);
98 return 0;
101 private:
102 /// If zero, indefinite event loop, otherwise timed event loop.
103 int time_flag_;
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"),
135 // Give a gap.
136 ACE_OS::sleep (3);
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"));
148 return 0;
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"));
158 return 1;
161 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */