1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
// $Id$
#define ACE_BUILD_DLL
#include "ace/Reactor.h"
#include "ace/Reactor_Impl.h"
#include "ace/Handle_Set.h"
#if !defined (ACE_HAS_WINCE)
# include "ace/Service_Config.h"
# include "ace/WFMO_Reactor.h"
# include "ace/Msg_WFMO_Reactor.h"
#endif /* !ACE_HAS_WINCE */
#include "ace/Select_Reactor.h"
#include "ace/TP_Reactor.h"
#include "ace/Object_Manager.h"
#if !defined (__ACE_INLINE__)
#include "ace/Reactor.i"
#endif /* __ACE_INLINE__ */
ACE_RCSID(ace, Reactor, "$Id$")
ACE_ALLOC_HOOK_DEFINE(ACE_Reactor)
ACE_Reactor::ACE_Reactor (ACE_Reactor_Impl *impl,
int delete_implementation)
: implementation_ (0),
delete_implementation_ (delete_implementation)
{
this->implementation (impl);
if (this->implementation () == 0)
{
#if !defined (ACE_WIN32) \
|| !defined (ACE_HAS_WINSOCK2) || (ACE_HAS_WINSOCK2 == 0) \
|| defined (ACE_USE_SELECT_REACTOR_FOR_REACTOR_IMPL) \
|| defined (ACE_USE_TP_REACTOR_FOR_REACTOR_IMPL)
#if defined (ACE_USE_TP_REACTOR_FOR_REACTOR_IMPL)
ACE_NEW (impl,
ACE_TP_Reactor);
#else
ACE_NEW (impl,
ACE_Select_Reactor);
#endif /* ACE_USE_TP_REACTOR_FOR_REACTOR_IMPL */
#else /* We are on Win32 and we have winsock and ACE_USE_SELECT_REACTOR_FOR_REACTOR_IMPL is not defined */
#if defined (ACE_USE_MSG_WFMO_REACTOR_FOR_REACTOR_IMPL)
ACE_NEW (impl,
ACE_Msg_WFMO_Reactor);
#else
ACE_NEW (impl,
ACE_WFMO_Reactor);
#endif /* ACE_USE_MSG_WFMO_REACTOR_FOR_REACTOR_IMPL */
#endif /* !defined (ACE_WIN32) || !defined (ACE_HAS_WINSOCK2) || (ACE_HAS_WINSOCK2 == 0) || defined (ACE_USE_SELECT_REACTOR_FOR_REACTOR_IMPL) */
this->implementation (impl);
this->delete_implementation_ = 1;
}
}
ACE_Reactor::~ACE_Reactor (void)
{
if (this->delete_implementation_)
delete this->implementation ();
}
// Process-wide ACE_Reactor.
ACE_Reactor *ACE_Reactor::reactor_ = 0;
// Controls whether the Reactor is deleted when we shut down (we can
// only delete it safely if we created it!)
int ACE_Reactor::delete_reactor_ = 0;
ACE_Reactor *
ACE_Reactor::instance (void)
{
ACE_TRACE ("ACE_Reactor::instance");
if (ACE_Reactor::reactor_ == 0)
{
// Perform Double-Checked Locking Optimization.
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance (), 0));
if (ACE_Reactor::reactor_ == 0)
{
ACE_NEW_RETURN (ACE_Reactor::reactor_,
ACE_Reactor,
0);
ACE_Reactor::delete_reactor_ = 1;
}
}
return ACE_Reactor::reactor_;
}
ACE_Reactor *
ACE_Reactor::instance (ACE_Reactor *r,
int delete_reactor)
{
ACE_TRACE ("ACE_Reactor::instance");
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance (), 0));
ACE_Reactor *t = ACE_Reactor::reactor_;
if (delete_reactor != 0)
ACE_Reactor::delete_reactor_ = 1;
else
// We can't safely delete it since we don't know who created it!
ACE_Reactor::delete_reactor_ = 0;
ACE_Reactor::reactor_ = r;
return t;
}
void
ACE_Reactor::close_singleton (void)
{
ACE_TRACE ("ACE_Reactor::close_singleton");
ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance ()));
if (ACE_Reactor::delete_reactor_)
{
delete ACE_Reactor::reactor_;
ACE_Reactor::reactor_ = 0;
ACE_Reactor::delete_reactor_ = 0;
}
}
int
ACE_Reactor::check_reconfiguration (void *)
{
#if !defined (ACE_HAS_WINCE)
if (ACE_Service_Config::reconfig_occurred ())
{
ACE_Service_Config::reconfigure ();
return 1;
}
#endif /* ACE_HAS_WINCE */
return 0;
}
int
ACE_Reactor::run_reactor_event_loop (REACTOR_EVENT_HOOK eh)
{
ACE_TRACE ("ACE_Reactor::run_reactor_event_loop");
while (1)
{
int result = this->implementation_->handle_events ();
if (eh != 0 && (*eh)(0))
continue;
else if (result == -1 && this->implementation_->deactivated ())
return 0;
else if (result == -1)
return -1;
}
ACE_NOTREACHED (return 0;)
}
int
ACE_Reactor::run_alertable_reactor_event_loop (REACTOR_EVENT_HOOK eh)
{
ACE_TRACE ("ACE_Reactor::run_alertable_reactor_event_loop");
while (1)
{
int result = this->implementation_->alertable_handle_events ();
if (eh != 0 && (*eh)(0))
continue;
else if (result == -1 && this->implementation_->deactivated ())
return 0;
else if (result == -1)
return -1;
}
ACE_NOTREACHED (return 0;)
}
int
ACE_Reactor::run_reactor_event_loop (ACE_Time_Value &tv,
REACTOR_EVENT_HOOK eh)
{
ACE_TRACE ("ACE_Reactor::run_reactor_event_loop");
while (1)
{
int result = this->implementation_->handle_events (tv);
if (eh != 0 && (*eh)(0))
continue;
else if (result == -1 && this->implementation_->deactivated ())
return 0;
else if (result <= 0)
return result;
}
ACE_NOTREACHED (return 0;)
}
int
ACE_Reactor::run_alertable_reactor_event_loop (ACE_Time_Value &tv,
REACTOR_EVENT_HOOK eh)
{
ACE_TRACE ("ACE_Reactor::run_alertable_reactor_event_loop");
while (1)
{
int result = this->implementation_->alertable_handle_events (tv);
if (eh != 0 && (*eh)(0))
continue;
else if (result == -1 && this->implementation_->deactivated ())
return 0;
else if (result <= 0)
return result;
}
ACE_NOTREACHED (return 0;)
}
int
ACE_Reactor::end_reactor_event_loop (void)
{
ACE_TRACE ("ACE_Reactor::end_reactor_event_loop");
this->implementation_->deactivate (1);
return 0;
}
int
ACE_Reactor::reactor_event_loop_done (void)
{
ACE_TRACE ("ACE_Reactor::reactor_event_loop_done");
return this->implementation_->deactivated ();
}
// Report if the <ACE_Reactor::instance>'s event loop is finished.
void
ACE_Reactor::reset_reactor_event_loop (void)
{
ACE_TRACE ("ACE_Reactor::reset_event_loop");
this->implementation_->deactivate (0);
}
// Resets the <ACE_Reactor::end_event_loop_> static so that the
// <run_event_loop> method can be restarted.
void
ACE_Reactor::dump (void) const
{
ACE_TRACE ("ACE_Reactor::dump");
implementation_->dump ();
}
|