Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / WFMO_Reactor.inl
blob6a78f29437ac028b28d9913b552213d075276f6c
1 // -*- C++ -*-
2 #include "ace/Handle_Set.h"
3 #include "ace/Reactor.h"
4 #include "ace/Thread.h"
5 #include "ace/Sig_Handler.h"
6 #include "ace/OS_NS_errno.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 /************************************************************/
12 ACE_INLINE int
13 ACE_Wakeup_All_Threads_Handler::handle_signal (int /* signum */, siginfo_t * /* siginfo */, ucontext_t *)
15   // This will get called when <WFMO_Reactor->wakeup_all_threads_> event
16   // is signaled. There is nothing to be done here.
17   //  ACELIB_DEBUG ((LM_DEBUG,  ACE_TEXT ("(%t) waking up to get updated handle set info\n")));
18   return 0;
21 #if defined (ACE_WIN32)
23 /************************************************************/
25 ACE_INLINE
26 ACE_WFMO_Reactor_Handler_Repository::Common_Info::Common_Info ()
27   : io_entry_ (false),
28     event_handler_ (0),
29     io_handle_ (ACE_INVALID_HANDLE),
30     network_events_ (0),
31     delete_event_ (false),
32     delete_entry_ (false),
33     close_masks_ (ACE_Event_Handler::NULL_MASK)
37 ACE_INLINE void
38 ACE_WFMO_Reactor_Handler_Repository::Common_Info::reset ()
40   this->event_handler_ = 0;
41   this->io_entry_ = false;
42   this->io_handle_ = ACE_INVALID_HANDLE;
43   this->network_events_ = 0;
44   this->delete_event_ = false;
45   this->delete_entry_ = false;
46   this->close_masks_ = ACE_Event_Handler::NULL_MASK;
49 ACE_INLINE void
50 ACE_WFMO_Reactor_Handler_Repository::Common_Info::set (bool io_entry,
51                                                        ACE_Event_Handler *event_handler,
52                                                        ACE_HANDLE io_handle,
53                                                        long network_events,
54                                                        bool delete_event,
55                                                        bool delete_entry,
56                                                        ACE_Reactor_Mask close_masks)
58   this->event_handler_ = event_handler;
59   this->io_entry_ = io_entry;
60   this->io_handle_ = io_handle;
61   this->network_events_ = network_events;
62   this->delete_event_ = delete_event;
63   this->delete_entry_ = delete_entry;
64   this->close_masks_ = close_masks;
67 ACE_INLINE void
68 ACE_WFMO_Reactor_Handler_Repository::Common_Info::set (Common_Info &common_info)
70   *this = common_info;
73 ACE_INLINE void
74 ACE_WFMO_Reactor_Handler_Repository::Common_Info::dump () const
76 #if defined (ACE_HAS_DUMP)
77   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::Common_Info::dump");
79   ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
81   ACELIB_DEBUG ((LM_DEBUG,
82               ACE_TEXT ("I/O Entry = %d\n"),
83               this->io_entry_));
85   ACELIB_DEBUG ((LM_DEBUG,
86               ACE_TEXT ("Event Handler = %d\n"),
87               this->event_handler_));
89   ACELIB_DEBUG ((LM_DEBUG,
90               ACE_TEXT ("I/O Handle = %d\n"),
91               this->io_handle_));
93   ACELIB_DEBUG ((LM_DEBUG,
94               ACE_TEXT ("Network Events = %d\n"),
95               this->network_events_));
97   ACELIB_DEBUG ((LM_DEBUG,
98               ACE_TEXT ("Delete Event = %d\n"),
99               this->delete_event_));
101   ACELIB_DEBUG ((LM_DEBUG,
102               ACE_TEXT ("Delete Entry = %d\n"),
103               this->delete_entry_));
105   ACELIB_DEBUG ((LM_DEBUG,
106               ACE_TEXT ("Close Masks = %d\n"),
107               this->close_masks_));
109   ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
110 #endif /* ACE_HAS_DUMP */
113 /************************************************************/
115 ACE_INLINE
116 ACE_WFMO_Reactor_Handler_Repository::Current_Info::Current_Info ()
117   : suspend_entry_ (false)
121 ACE_INLINE void
122 ACE_WFMO_Reactor_Handler_Repository::Current_Info::set (bool io_entry,
123                                                         ACE_Event_Handler *event_handler,
124                                                         ACE_HANDLE io_handle,
125                                                         long network_events,
126                                                         bool delete_event,
127                                                         bool delete_entry,
128                                                         ACE_Reactor_Mask close_masks,
129                                                         bool suspend_entry)
131   this->suspend_entry_ = suspend_entry;
132   Common_Info::set (io_entry,
133                     event_handler,
134                     io_handle,
135                     network_events,
136                     delete_event,
137                     delete_entry,
138                     close_masks);
141 ACE_INLINE void
142 ACE_WFMO_Reactor_Handler_Repository::Current_Info::set (Common_Info &common_info,
143                                                         bool suspend_entry)
145   this->suspend_entry_ = suspend_entry;
146   Common_Info::set (common_info);
149 ACE_INLINE void
150 ACE_WFMO_Reactor_Handler_Repository::Current_Info::reset ()
152   this->suspend_entry_ = false;
153   Common_Info::reset ();
156 ACE_INLINE void
157 ACE_WFMO_Reactor_Handler_Repository::Current_Info::dump (ACE_HANDLE event_handle) const
159 #if defined (ACE_HAS_DUMP)
160   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::Current_Info::dump");
162   ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
164   Common_Info::dump ();
166   ACELIB_DEBUG ((LM_DEBUG,
167               ACE_TEXT ("Event Handle = %d\n"),
168               event_handle));
170   ACELIB_DEBUG ((LM_DEBUG,
171               ACE_TEXT ("Suspend Entry = %d\n"),
172               this->suspend_entry_));
174   ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
175 #else /* !ACE_HAS_DUMP */
176   ACE_UNUSED_ARG (event_handle);
177 #endif /* ACE_HAS_DUMP */
180 /************************************************************/
182 ACE_INLINE
183 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::To_Be_Added_Info ()
184   : event_handle_ (ACE_INVALID_HANDLE),
185     suspend_entry_ (false)
189 ACE_INLINE void
190 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::set (ACE_HANDLE event_handle,
191                                                             bool io_entry,
192                                                             ACE_Event_Handler *event_handler,
193                                                             ACE_HANDLE io_handle,
194                                                             long network_events,
195                                                             bool delete_event,
196                                                             bool delete_entry,
197                                                             ACE_Reactor_Mask close_masks,
198                                                             bool suspend_entry)
200   this->event_handle_ = event_handle;
201   this->suspend_entry_ = suspend_entry;
202   Common_Info::set (io_entry,
203                     event_handler,
204                     io_handle,
205                     network_events,
206                     delete_event,
207                     delete_entry,
208                     close_masks);
211 ACE_INLINE void
212 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::set (ACE_HANDLE event_handle,
213                                                             Common_Info &common_info,
214                                                             bool suspend_entry)
216   this->event_handle_ = event_handle;
217   this->suspend_entry_ = suspend_entry;
218   Common_Info::set (common_info);
221 ACE_INLINE void
222 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::reset ()
224   this->event_handle_ = ACE_INVALID_HANDLE;
225   this->suspend_entry_ = false;
226   Common_Info::reset ();
229 ACE_INLINE void
230 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::dump () const
232 #if defined (ACE_HAS_DUMP)
233   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::dump");
235   ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
237   Common_Info::dump ();
239   ACELIB_DEBUG ((LM_DEBUG,
240               ACE_TEXT ("Event Handle = %d\n"),
241               this->event_handle_));
243   ACELIB_DEBUG ((LM_DEBUG,
244               ACE_TEXT ("Suspend Entry = %d\n"),
245               this->suspend_entry_));
247   ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
248 #endif /* ACE_HAS_DUMP */
251 /************************************************************/
253 ACE_INLINE
254 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::Suspended_Info ()
255   : event_handle_ (ACE_INVALID_HANDLE),
256     resume_entry_ (false)
260 ACE_INLINE void
261 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::reset ()
263   this->event_handle_ = ACE_INVALID_HANDLE;
264   this->resume_entry_ = false;
265   Common_Info::reset ();
268 ACE_INLINE void
269 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::set (ACE_HANDLE event_handle,
270                                                           bool io_entry,
271                                                           ACE_Event_Handler *event_handler,
272                                                           ACE_HANDLE io_handle,
273                                                           long network_events,
274                                                           bool delete_event,
275                                                           bool delete_entry,
276                                                           ACE_Reactor_Mask close_masks,
277                                                           bool resume_entry)
279   this->event_handle_ = event_handle;
280   this->resume_entry_ = resume_entry;
281   Common_Info::set (io_entry,
282                     event_handler,
283                     io_handle,
284                     network_events,
285                     delete_event,
286                     delete_entry,
287                     close_masks);
290 ACE_INLINE void
291 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::set (ACE_HANDLE event_handle,
292                                                           Common_Info &common_info,
293                                                           bool resume_entry)
295   this->event_handle_ = event_handle;
296   this->resume_entry_ = resume_entry;
297   Common_Info::set (common_info);
300 ACE_INLINE void
301 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::dump () const
303 #if defined (ACE_HAS_DUMP)
304   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::dump");
306   ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
308   Common_Info::dump ();
310   ACELIB_DEBUG ((LM_DEBUG,
311               ACE_TEXT ("Event Handle = %d\n"),
312               this->event_handle_));
314   ACELIB_DEBUG ((LM_DEBUG,
315               ACE_TEXT ("Resume Entry = %d\n"),
316               this->resume_entry_));
318   ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
319 #endif /* ACE_HAS_DUMP */
322 /************************************************************/
324 ACE_INLINE int
325 ACE_WFMO_Reactor_Handler_Repository::close ()
327   // Let all the handlers know that the <WFMO_Reactor> is closing down
328   this->unbind_all ();
330   return 0;
333 ACE_INLINE ACE_HANDLE *
334 ACE_WFMO_Reactor_Handler_Repository::handles () const
336   // This code is probably too subtle to be useful in the long run...
337   // The basic idea is that all threads wait on all user handles plus
338   // the <wakeup_all_threads_> handle. The owner thread additional
339   // waits on the <notify_> handle. This is to ensure that only the
340   // <owner_> thread get to expire timers and handle event on the
341   // notify pipe.
342   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
343     return this->current_handles_;
344   else
345     return this->current_handles_ + 1;
348 ACE_INLINE ACE_WFMO_Reactor_Handler_Repository::Current_Info *
349 ACE_WFMO_Reactor_Handler_Repository::current_info () const
351   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
352     return this->current_info_;
353   else
354     return this->current_info_ + 1;
357 ACE_INLINE DWORD
358 ACE_WFMO_Reactor_Handler_Repository::max_handlep1 () const
360   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
361     return this->max_handlep1_;
362   else
363     return this->max_handlep1_ - 1;
366 ACE_INLINE int
367 ACE_WFMO_Reactor_Handler_Repository::scheduled_for_deletion (size_t slot) const
369   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
370     return this->current_info_[slot].delete_entry_ == true;
371   else
372     return this->current_info_[slot + 1].delete_entry_ == true;
375 ACE_INLINE int
376 ACE_WFMO_Reactor_Handler_Repository::invalid_handle (ACE_HANDLE handle) const
378   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::invalid_handle");
379   // It's too expensive to perform more exhaustive validity checks on
380   // Win32 due to the way that they implement SOCKET HANDLEs.
381   if (handle == ACE_INVALID_HANDLE)
382     {
383       errno = EINVAL;
384       return 1;
385     }
386   else
387     return 0;
390 ACE_INLINE bool
391 ACE_WFMO_Reactor_Handler_Repository::changes_required ()
393   // Check if handles have be scheduled for additions or removal
394   return this->handles_to_be_added_ > 0
395     || this->handles_to_be_deleted_ > 0
396     || this->handles_to_be_suspended_ > 0
397     || this->handles_to_be_resumed_ > 0;
400 ACE_INLINE int
401 ACE_WFMO_Reactor_Handler_Repository::make_changes ()
403   // This method must ONLY be called by the
404   // <WFMO_Reactor->change_state_thread_>. We therefore assume that
405   // there will be no contention for this method and hence no guards
406   // are neccessary.
408   // Deletions and suspensions in current_info_
409   this->make_changes_in_current_infos ();
411   // Deletions and resumptions in current_suspended_info_
412   this->make_changes_in_suspension_infos ();
414   // Deletions in to_be_added_info_, or transfers to current_info_ or
415   // current_suspended_info_ from to_be_added_info_
416   this->make_changes_in_to_be_added_infos ();
418   return 0;
421 ACE_INLINE int
422 ACE_WFMO_Reactor_Handler_Repository::unbind (ACE_HANDLE handle,
423                                              ACE_Reactor_Mask mask)
425   if (this->invalid_handle (handle))
426     return -1;
428   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->wfmo_reactor_.lock_, -1);
430   bool changes_required = false;
431   int const result = this->unbind_i (handle,
432                                      mask,
433                                      changes_required);
435   if (changes_required)
436     // Wake up all threads in WaitForMultipleObjects so that they can
437     // reconsult the handle set
438     this->wfmo_reactor_.wakeup_all_threads ();
440   return result;
443 ACE_INLINE int
444 ACE_WFMO_Reactor::reset_timer_interval
445   (long timer_id,
446    const ACE_Time_Value &interval)
448   ACE_TRACE ("ACE_WFMO_Reactor::reset_timer_interval");
450   if (0 != this->timer_queue_)
451     {
452       long result = this->timer_queue_->reset_interval
453         (timer_id,
454          interval);
456       // Wakeup the owner thread so that it gets the latest timer values
457       this->notify ();
459       return result;
460     }
462   errno = ESHUTDOWN;
463   return -1;
466 ACE_INLINE long
467 ACE_WFMO_Reactor::schedule_timer (ACE_Event_Handler *handler,
468                                   const void *arg,
469                                   const ACE_Time_Value &delay_time,
470                                   const ACE_Time_Value &interval)
472   ACE_TRACE ("ACE_WFMO_Reactor::schedule_timer");
474   if (0 != this->timer_queue_)
475     {
476       long result = this->timer_queue_->schedule
477         (handler,
478          arg,
479          timer_queue_->gettimeofday () + delay_time,
480          interval);
482       // Wakeup the owner thread so that it gets the latest timer values
483       this->notify ();
485       return result;
486     }
488   errno = ESHUTDOWN;
489   return -1;
492 ACE_INLINE int
493 ACE_WFMO_Reactor::cancel_timer (ACE_Event_Handler *handler,
494                                 int dont_call_handle_close)
496   ACE_TRACE ("ACE_WFMO_Reactor::cancel_timer");
497   if ((0 != this->timer_queue_) && (0 != handler))
498     return this->timer_queue_->cancel (handler, dont_call_handle_close);
499   return 0;
502 ACE_INLINE int
503 ACE_WFMO_Reactor::cancel_timer (long timer_id,
504                                 const void **arg,
505                                 int dont_call_handle_close)
507   ACE_TRACE ("ACE_WFMO_Reactor::cancel_timer");
508   if (0 != this->timer_queue_)
509     return this->timer_queue_->cancel (timer_id, arg, dont_call_handle_close);
510   return 0;
513 ACE_INLINE int
514 ACE_WFMO_Reactor::register_handler (ACE_Event_Handler *event_handler,
515                                     ACE_HANDLE event_handle)
517   // This GUARD is necessary since we are updating shared state.
518   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
520   return this->handler_rep_.bind_i (0,
521                                     event_handler,
522                                     0,
523                                     ACE_INVALID_HANDLE,
524                                     event_handle,
525                                     0);
528 ACE_INLINE int
529 ACE_WFMO_Reactor::register_handler (ACE_Event_Handler *event_handler,
530                                     ACE_Reactor_Mask mask)
532   // This GUARD is necessary since we are updating shared state.
533   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
535   return this->register_handler_i (ACE_INVALID_HANDLE,
536                                    ACE_INVALID_HANDLE,
537                                    event_handler,
538                                    mask);
541 ACE_INLINE int
542 ACE_WFMO_Reactor::register_handler (ACE_HANDLE io_handle,
543                                     ACE_Event_Handler *event_handler,
544                                     ACE_Reactor_Mask mask)
546   // This GUARD is necessary since we are updating shared state.
547   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
549   return this->register_handler_i (ACE_INVALID_HANDLE,
550                                    io_handle,
551                                    event_handler,
552                                    mask);
555 ACE_INLINE int
556 ACE_WFMO_Reactor::register_handler (ACE_HANDLE event_handle,
557                                     ACE_HANDLE io_handle,
558                                     ACE_Event_Handler *event_handler,
559                                     ACE_Reactor_Mask mask)
561   // This GUARD is necessary since we are updating shared state.
562   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
564   return this->register_handler_i (event_handle,
565                                    io_handle,
566                                    event_handler,
567                                    mask);
570 ACE_INLINE int
571 ACE_WFMO_Reactor::register_handler (const ACE_Handle_Set &handles,
572                                     ACE_Event_Handler *handler,
573                                     ACE_Reactor_Mask mask)
575   // This GUARD is necessary since we are updating shared state.
576   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
578   ACE_Handle_Set_Iterator handle_iter (handles);
579   ACE_HANDLE h;
581   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
582     if (this->register_handler_i (h,
583                                   ACE_INVALID_HANDLE,
584                                   handler,
585                                   mask) == -1)
586       return -1;
588   return 0;
591 ACE_INLINE int
592 ACE_WFMO_Reactor::schedule_wakeup (ACE_HANDLE io_handle,
593                                    ACE_Reactor_Mask masks_to_be_added)
595   // This GUARD is necessary since we are updating shared state.
596   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
598   return this->mask_ops_i (io_handle,
599                            masks_to_be_added,
600                            ACE_Reactor::ADD_MASK);
603 ACE_INLINE int
604 ACE_WFMO_Reactor::schedule_wakeup (ACE_Event_Handler *event_handler,
605                                    ACE_Reactor_Mask masks_to_be_added)
607   // This GUARD is necessary since we are updating shared state.
608   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
610   return this->mask_ops_i (event_handler->get_handle (),
611                            masks_to_be_added,
612                            ACE_Reactor::ADD_MASK);
615 ACE_INLINE int
616 ACE_WFMO_Reactor::cancel_wakeup (ACE_HANDLE io_handle,
617                                  ACE_Reactor_Mask masks_to_be_removed)
619   // This GUARD is necessary since we are updating shared state.
620   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
622   return this->mask_ops_i (io_handle,
623                            masks_to_be_removed,
624                            ACE_Reactor::CLR_MASK);
627 ACE_INLINE int
628 ACE_WFMO_Reactor::cancel_wakeup (ACE_Event_Handler *event_handler,
629                                  ACE_Reactor_Mask masks_to_be_removed)
631   // This GUARD is necessary since we are updating shared state.
632   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
634   return this->mask_ops_i (event_handler->get_handle (),
635                            masks_to_be_removed,
636                            ACE_Reactor::CLR_MASK);
639 ACE_INLINE int
640 ACE_WFMO_Reactor::remove_handler (ACE_Event_Handler *event_handler,
641                                   ACE_Reactor_Mask mask)
643   return this->handler_rep_.unbind (event_handler->get_handle (),
644                                     mask);
647 ACE_INLINE int
648 ACE_WFMO_Reactor::remove_handler (ACE_HANDLE handle,
649                                   ACE_Reactor_Mask mask)
651   return this->handler_rep_.unbind (handle,
652                                     mask);
655 ACE_INLINE int
656 ACE_WFMO_Reactor::remove_handler (const ACE_Handle_Set &handles,
657                                   ACE_Reactor_Mask mask)
659   ACE_Handle_Set_Iterator handle_iter (handles);
660   ACE_HANDLE h;
661   bool changes_required = false;
663   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
665   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
666     if (this->handler_rep_.unbind_i (h,
667                                      mask,
668                                      changes_required) == -1)
669       return -1;
671   // Wake up all threads in WaitForMultipleObjects so that they can
672   // reconsult the handle set
673   this->wakeup_all_threads ();
675   return 0;
678 ACE_INLINE int
679 ACE_WFMO_Reactor::suspend_handler (ACE_HANDLE handle)
681   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
683   bool changes_required = false;
684   int const result =
685     this->handler_rep_.suspend_handler_i (handle,
686                                           changes_required);
688   if (changes_required)
689     // Wake up all threads in WaitForMultipleObjects so that they can
690     // reconsult the handle set
691     this->wakeup_all_threads ();
693   return result;
696 ACE_INLINE int
697 ACE_WFMO_Reactor::suspend_handler (ACE_Event_Handler *event_handler)
699   return this->suspend_handler (event_handler->get_handle ());
702 ACE_INLINE int
703 ACE_WFMO_Reactor::suspend_handler (const ACE_Handle_Set &handles)
705   ACE_Handle_Set_Iterator handle_iter (handles);
706   ACE_HANDLE h;
707   bool changes_required = false;
709   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
711   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
712     if (this->handler_rep_.suspend_handler_i (h,
713                                               changes_required) == -1)
714       return -1;
716   // Wake up all threads in WaitForMultipleObjects so that they can
717   // reconsult the handle set
718   this->wakeup_all_threads ();
720   return 0;
723 ACE_INLINE int
724 ACE_WFMO_Reactor::suspend_handlers ()
726   bool error = false;
727   int result = 0;
728   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
730   // First suspend all current handles
731   bool changes_required = false;
733   // Skip over the notify and wakeup_all_threads handles. These are registered
734   // by ACE_WFMO_Reactor::open(), not by users, and should not be suspended.
735   for (size_t i = 2;
736        i < this->handler_rep_.max_handlep1_ && !error;
737        i++)
738     {
739       result =
740         this->handler_rep_.suspend_handler_i (this->handler_rep_.current_handles_[i],
741                                               changes_required);
742       if (result == -1)
743         error = true;
744     }
746   // Then suspend all to_be_added_handles
747   for (size_t i = 0;
748        i < this->handler_rep_.handles_to_be_added_ && !error;
749        i++)
750     {
751       if (this->handler_rep_.to_be_added_info_[i].io_entry_)
752         {
753           result =
754             this->handler_rep_.suspend_handler_i (this->handler_rep_.to_be_added_info_[i].io_handle_,
755                                                   changes_required);
756         }
757       else
758         {
759           result =
760             this->handler_rep_.suspend_handler_i (this->handler_rep_.to_be_added_info_[i].event_handle_,
761                                                   changes_required);
762         }
763       if (result == -1)
764         error = true;
765     }
767   // Wake up all threads in WaitForMultipleObjects so that they can
768   // reconsult the handle set
769   this->wakeup_all_threads ();
771   return error ? -1 : 0;
774 ACE_INLINE int
775 ACE_WFMO_Reactor::resume_handler (ACE_HANDLE handle)
777   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
779   bool changes_required = false;
780   int result =
781     this->handler_rep_.resume_handler_i (handle, changes_required);
783   if (changes_required)
784     // Wake up all threads in WaitForMultipleObjects so that they can
785     // reconsult the handle set
786     this->wakeup_all_threads ();
788   return result;
791 ACE_INLINE int
792 ACE_WFMO_Reactor::resume_handler (ACE_Event_Handler *event_handler)
794   return this->resume_handler (event_handler->get_handle ());
797 ACE_INLINE int
798 ACE_WFMO_Reactor::resume_handler (const ACE_Handle_Set &handles)
800   ACE_Handle_Set_Iterator handle_iter (handles);
801   ACE_HANDLE h;
802   bool changes_required = false;
804   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
806   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
807     if (this->handler_rep_.resume_handler_i (h,
808                                              changes_required) == -1)
809       return -1;
811   // Wake up all threads in WaitForMultipleObjects so that they can
812   // reconsult the handle set
813   this->wakeup_all_threads ();
815   return 0;
818 ACE_INLINE int
819 ACE_WFMO_Reactor::resume_handlers ()
821   bool error = false;
822   int result = 0;
823   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
825   bool changes_required = false;
826   for (size_t i = 0;
827        i < this->handler_rep_.suspended_handles_ && !error;
828        i++)
829     {
830       result =
831         this->handler_rep_.resume_handler_i (this->handler_rep_.current_suspended_info_[i].event_handle_,
832                                              changes_required);
833       if (result == -1)
834         error = true;
835     }
837   // Then resume all to_be_added_handles
838   for (size_t i = 0;
839         i < this->handler_rep_.handles_to_be_added_ && !error;
840         i++)
841     {
842       if (this->handler_rep_.to_be_added_info_[i].io_entry_)
843         {
844           result =
845             this->handler_rep_.resume_handler_i (this->handler_rep_.to_be_added_info_[i].io_handle_,
846                                                   changes_required);
847         }
848       else
849         {
850           result =
851            this->handler_rep_.resume_handler_i (this->handler_rep_.to_be_added_info_[i].event_handle_,
852                                                 changes_required);
853         }
854       if (result == -1)
855         error = true;
856     }
858   // Wake up all threads in WaitForMultipleObjects so that they can
859   // reconsult the handle set
860   this->wakeup_all_threads ();
862   return error ? -1 : 0;
865 ACE_INLINE bool
866 ACE_WFMO_Reactor::uses_event_associations ()
868   // Since the WFMO_Reactor does use event associations, this function
869   // always return 1.
870   return true;
873 ACE_INLINE int
874 ACE_WFMO_Reactor::handle_events (ACE_Time_Value &how_long)
876   return this->event_handling (&how_long, FALSE);
879 ACE_INLINE int
880 ACE_WFMO_Reactor::alertable_handle_events (ACE_Time_Value &how_long)
882   return this->event_handling (&how_long, TRUE);
885 ACE_INLINE int
886 ACE_WFMO_Reactor::handle_events (ACE_Time_Value *how_long)
888   return this->event_handling (how_long, FALSE);
891 ACE_INLINE int
892 ACE_WFMO_Reactor::alertable_handle_events (ACE_Time_Value *how_long)
894   return this->event_handling (how_long, TRUE);
897 ACE_INLINE int
898 ACE_WFMO_Reactor::deactivated ()
900   return this->deactivated_;
903 ACE_INLINE void
904 ACE_WFMO_Reactor::deactivate (int do_stop)
906   this->deactivated_ = do_stop;
907   this->wakeup_all_threads ();
910 ACE_INLINE int
911 ACE_WFMO_Reactor::owner (ACE_thread_t *t)
913   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
914   *t = this->owner_i ();
915   return 0;
918 ACE_INLINE ACE_thread_t
919 ACE_WFMO_Reactor::owner_i ()
921   return this->owner_;
924 ACE_INLINE int
925 ACE_WFMO_Reactor::owner (ACE_thread_t new_owner, ACE_thread_t *old_owner)
927   ACE_GUARD_RETURN (ACE_Process_Mutex, monitor, this->lock_, -1);
928   this->new_owner_ = new_owner;
930   if (old_owner != 0)
931     *old_owner = this->owner_i ();
933   // Wake up all threads in WaitForMultipleObjects so that they can
934   // reconsult the new owner responsibilities
935   this->wakeup_all_threads ();
937   return 0;
940 ACE_INLINE int
941 ACE_WFMO_Reactor::new_owner ()
943   return this->new_owner_ != ACE_thread_t (0);
946 ACE_INLINE int
947 ACE_WFMO_Reactor::change_owner ()
949   this->owner_ = this->new_owner_;
950   this->new_owner_ = ACE_thread_t (0);
951   return 0;
954 ACE_INLINE int
955 ACE_WFMO_Reactor::safe_dispatch (DWORD wait_status)
957   int result = -1;
958   ACE_SEH_TRY
959     {
960       result = this->dispatch (wait_status);
961     }
962   ACE_SEH_FINALLY
963     {
964       this->update_state ();
965     }
967   return result;
970 ACE_INLINE int
971 ACE_WFMO_Reactor::dispatch_window_messages ()
973   return 0;
976 ACE_INLINE void
977 ACE_WFMO_Reactor::wakeup_all_threads ()
979   this->wakeup_all_threads_.signal ();
982 ACE_INLINE int
983 ACE_WFMO_Reactor::notify (ACE_Event_Handler *event_handler,
984                           ACE_Reactor_Mask mask,
985                           ACE_Time_Value *timeout)
987   return this->notify_handler_->notify (event_handler, mask, timeout);
990 ACE_INLINE int
991 ACE_WFMO_Reactor::register_handler (int signum,
992                                     ACE_Event_Handler *new_sh,
993                                     ACE_Sig_Action *new_disp,
994                                     ACE_Event_Handler **old_sh,
995                                     ACE_Sig_Action *old_disp)
997   return this->signal_handler_->register_handler (signum,
998                                                   new_sh, new_disp,
999                                                   old_sh, old_disp);
1002 ACE_INLINE int
1003 ACE_WFMO_Reactor::register_handler (const ACE_Sig_Set &sigset,
1004                                     ACE_Event_Handler *new_sh,
1005                                     ACE_Sig_Action *new_disp)
1007   int result = 0;
1009 #if (ACE_NSIG > 0)
1010   for (int s = 1; s < ACE_NSIG; s++)
1011     if (sigset.is_member (s)
1012         && this->signal_handler_->register_handler (s,
1013                                                     new_sh,
1014                                                     new_disp) == -1)
1015       result = -1;
1016 #else
1017   ACE_UNUSED_ARG (sigset);
1018   ACE_UNUSED_ARG (new_sh);
1019   ACE_UNUSED_ARG (new_disp);
1020 #endif /* ACE_NSIG */
1022   return result;
1025 ACE_INLINE int
1026 ACE_WFMO_Reactor::remove_handler (int signum,
1027                                   ACE_Sig_Action *new_disp,
1028                                   ACE_Sig_Action *old_disp,
1029                                   int sigkey)
1031   return this->signal_handler_->remove_handler (signum,
1032                                                 new_disp,
1033                                                 old_disp,
1034                                                 sigkey);
1037 ACE_INLINE int
1038 ACE_WFMO_Reactor::remove_handler (const ACE_Sig_Set &sigset)
1040   int result = 0;
1042 #if (ACE_NSIG > 0)
1043   for (int s = 1; s < ACE_NSIG; s++)
1044     if (sigset.is_member (s)
1045         && this->signal_handler_->remove_handler (s) == -1)
1046       result = -1;
1047 #else
1048   ACE_UNUSED_ARG (sigset);
1049 #endif /* ACE_NSIG */
1051   return result;
1054 ACE_INLINE int
1055 ACE_WFMO_Reactor::handler (int signum, ACE_Event_Handler **eh)
1057   ACE_Event_Handler *handler =
1058     this->signal_handler_->handler (signum);
1060   if (handler == 0)
1061     return -1;
1062   else if (eh != 0)
1063     *eh = handler;
1064   return 0;
1067 ACE_INLINE int
1068 ACE_WFMO_Reactor::mask_ops (ACE_Event_Handler *event_handler,
1069                             ACE_Reactor_Mask mask,
1070                             int operation)
1072   ACE_GUARD_RETURN (ACE_Process_Mutex, monitor, this->lock_, -1);
1074   return this->mask_ops_i (event_handler->get_handle (),
1075                            mask,
1076                            operation);
1079 ACE_INLINE int
1080 ACE_WFMO_Reactor::mask_ops (ACE_HANDLE io_handle,
1081                             ACE_Reactor_Mask mask,
1082                             int operation)
1084   ACE_GUARD_RETURN (ACE_Process_Mutex, monitor, this->lock_, -1);
1086   return this->mask_ops_i (io_handle,
1087                            mask,
1088                            operation);
1091 ACE_INLINE void
1092 ACE_WFMO_Reactor::requeue_position (int)
1094   // Not implemented
1097 ACE_INLINE int
1098 ACE_WFMO_Reactor::requeue_position ()
1100   // Don't have an implementation for this yet...
1101   ACE_NOTSUP_RETURN (-1);
1104 ACE_INLINE bool
1105 ACE_WFMO_Reactor::restart ()
1107   return false;
1110 ACE_INLINE bool
1111 ACE_WFMO_Reactor::restart (bool)
1113   return false;
1116 ACE_INLINE int
1117 ACE_WFMO_Reactor::ready_ops (ACE_Event_Handler *event_handler,
1118                              ACE_Reactor_Mask mask,
1119                              int ops)
1121   // Don't have an implementation for this yet...
1122   ACE_UNUSED_ARG (event_handler);
1123   ACE_UNUSED_ARG (mask);
1124   ACE_UNUSED_ARG (ops);
1125   ACE_NOTSUP_RETURN (-1);
1128 ACE_INLINE int
1129 ACE_WFMO_Reactor::ready_ops (ACE_HANDLE handle,
1130                              ACE_Reactor_Mask,
1131                              int ops)
1133   // Don't have an implementation for this yet...
1134   ACE_UNUSED_ARG (handle);
1135   ACE_UNUSED_ARG (ops);
1136   ACE_NOTSUP_RETURN (-1);
1139 ACE_INLINE ACE_Event_Handler *
1140 ACE_WFMO_Reactor::find_handler (ACE_HANDLE handle)
1142   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, 0);
1144   return this->handler_rep_.find_handler (handle);
1147 ACE_INLINE int
1148 ACE_WFMO_Reactor::handler (ACE_HANDLE handle,
1149                            ACE_Reactor_Mask mask,
1150                            ACE_Event_Handler **event_handler)
1152   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
1154   return this->handler_rep_.handler (handle, mask, event_handler);
1157 ACE_INLINE bool
1158 ACE_WFMO_Reactor::initialized ()
1160   return this->open_for_business_;
1163 ACE_INLINE ACE_Lock &
1164 ACE_WFMO_Reactor::lock ()
1166   return this->lock_adapter_;
1169 ACE_INLINE size_t
1170 ACE_WFMO_Reactor::size () const
1172   // Size of repository minus the 2 used for internal purposes
1173   return this->handler_rep_.max_size_ - 2;
1175 #else
1176 ACE_INLINE bool
1177 ACE_WFMO_Reactor_Handler_Repository::changes_required ()
1179   return false;
1182 ACE_INLINE int
1183 ACE_WFMO_Reactor_Handler_Repository::make_changes ()
1185   return 0;
1188 ACE_INLINE
1189 ACE_WFMO_Reactor_Handler_Repository::~ACE_WFMO_Reactor_Handler_Repository ()
1193 #endif /* ACE_WIN32 */
1195 ACE_END_VERSIONED_NAMESPACE_DECL