WFMO_Reactor.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: WFMO_Reactor.inl 81138 2008-03-28 09:18:15Z johnnyw $
00004 
00005 #include "ace/Handle_Set.h"
00006 #include "ace/Reactor.h"
00007 #include "ace/Thread.h"
00008 #include "ace/Sig_Handler.h"
00009 #include "ace/OS_NS_errno.h"
00010 
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 /************************************************************/
00014 
00015 ACE_INLINE int
00016 ACE_Wakeup_All_Threads_Handler::handle_signal (int /* signum */,
00017                                                siginfo_t * /* siginfo */,
00018                                                ucontext_t *)
00019 {
00020   // This will get called when <WFMO_Reactor->wakeup_all_threads_> event
00021   // is signaled. There is nothing to be done here.
00022   //  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("(%t) waking up to get updated handle set info\n")));
00023   return 0;
00024 }
00025 
00026 #if defined (ACE_WIN32)
00027 
00028 /************************************************************/
00029 
00030 ACE_INLINE
00031 ACE_WFMO_Reactor_Handler_Repository::Common_Info::Common_Info (void)
00032   : io_entry_ (false),
00033     event_handler_ (0),
00034     io_handle_ (ACE_INVALID_HANDLE),
00035     network_events_ (0),
00036     delete_event_ (false),
00037     delete_entry_ (false),
00038     close_masks_ (ACE_Event_Handler::NULL_MASK)
00039 {
00040 }
00041 
00042 ACE_INLINE void
00043 ACE_WFMO_Reactor_Handler_Repository::Common_Info::reset (void)
00044 {
00045   this->event_handler_ = 0;
00046   this->io_entry_ = false;
00047   this->io_handle_ = ACE_INVALID_HANDLE;
00048   this->network_events_ = 0;
00049   this->delete_event_ = false;
00050   this->delete_entry_ = false;
00051   this->close_masks_ = ACE_Event_Handler::NULL_MASK;
00052 }
00053 
00054 ACE_INLINE void
00055 ACE_WFMO_Reactor_Handler_Repository::Common_Info::set (bool io_entry,
00056                                                        ACE_Event_Handler *event_handler,
00057                                                        ACE_HANDLE io_handle,
00058                                                        long network_events,
00059                                                        bool delete_event,
00060                                                        bool delete_entry,
00061                                                        ACE_Reactor_Mask close_masks)
00062 {
00063   this->event_handler_ = event_handler;
00064   this->io_entry_ = io_entry;
00065   this->io_handle_ = io_handle;
00066   this->network_events_ = network_events;
00067   this->delete_event_ = delete_event;
00068   this->delete_entry_ = delete_entry;
00069   this->close_masks_ = close_masks;
00070 }
00071 
00072 ACE_INLINE void
00073 ACE_WFMO_Reactor_Handler_Repository::Common_Info::set (Common_Info &common_info)
00074 {
00075   *this = common_info;
00076 }
00077 
00078 ACE_INLINE void
00079 ACE_WFMO_Reactor_Handler_Repository::Common_Info::dump (void) const
00080 {
00081 #if defined (ACE_HAS_DUMP)
00082   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::Common_Info::dump");
00083 
00084   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00085 
00086   ACE_DEBUG ((LM_DEBUG,
00087               ACE_TEXT ("I/O Entry = %d\n"),
00088               this->io_entry_));
00089 
00090   ACE_DEBUG ((LM_DEBUG,
00091               ACE_TEXT ("Event Handler = %d\n"),
00092               this->event_handler_));
00093 
00094   ACE_DEBUG ((LM_DEBUG,
00095               ACE_TEXT ("I/O Handle = %d\n"),
00096               this->io_handle_));
00097 
00098   ACE_DEBUG ((LM_DEBUG,
00099               ACE_TEXT ("Network Events = %d\n"),
00100               this->network_events_));
00101 
00102   ACE_DEBUG ((LM_DEBUG,
00103               ACE_TEXT ("Delete Event = %d\n"),
00104               this->delete_event_));
00105 
00106   ACE_DEBUG ((LM_DEBUG,
00107               ACE_TEXT ("Delete Entry = %d\n"),
00108               this->delete_entry_));
00109 
00110   ACE_DEBUG ((LM_DEBUG,
00111               ACE_TEXT ("Close Masks = %d\n"),
00112               this->close_masks_));
00113 
00114   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00115 #endif /* ACE_HAS_DUMP */
00116 }
00117 
00118 /************************************************************/
00119 
00120 ACE_INLINE
00121 ACE_WFMO_Reactor_Handler_Repository::Current_Info::Current_Info (void)
00122   : suspend_entry_ (false)
00123 {
00124 }
00125 
00126 ACE_INLINE void
00127 ACE_WFMO_Reactor_Handler_Repository::Current_Info::set (bool io_entry,
00128                                                         ACE_Event_Handler *event_handler,
00129                                                         ACE_HANDLE io_handle,
00130                                                         long network_events,
00131                                                         bool delete_event,
00132                                                         bool delete_entry,
00133                                                         ACE_Reactor_Mask close_masks,
00134                                                         bool suspend_entry)
00135 {
00136   this->suspend_entry_ = suspend_entry;
00137   Common_Info::set (io_entry,
00138                     event_handler,
00139                     io_handle,
00140                     network_events,
00141                     delete_event,
00142                     delete_entry,
00143                     close_masks);
00144 }
00145 
00146 ACE_INLINE void
00147 ACE_WFMO_Reactor_Handler_Repository::Current_Info::set (Common_Info &common_info,
00148                                                         bool suspend_entry)
00149 {
00150   this->suspend_entry_ = suspend_entry;
00151   Common_Info::set (common_info);
00152 }
00153 
00154 ACE_INLINE void
00155 ACE_WFMO_Reactor_Handler_Repository::Current_Info::reset (void)
00156 {
00157   this->suspend_entry_ = false;
00158   Common_Info::reset ();
00159 }
00160 
00161 ACE_INLINE void
00162 ACE_WFMO_Reactor_Handler_Repository::Current_Info::dump (ACE_HANDLE event_handle) const
00163 {
00164 #if defined (ACE_HAS_DUMP)
00165   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::Current_Info::dump");
00166 
00167   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00168 
00169   Common_Info::dump ();
00170 
00171   ACE_DEBUG ((LM_DEBUG,
00172               ACE_TEXT ("Event Handle = %d\n"),
00173               event_handle));
00174 
00175   ACE_DEBUG ((LM_DEBUG,
00176               ACE_TEXT ("Suspend Entry = %d\n"),
00177               this->suspend_entry_));
00178 
00179   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00180 #else /* !ACE_HAS_DUMP */
00181   ACE_UNUSED_ARG (event_handle);
00182 #endif /* ACE_HAS_DUMP */
00183 }
00184 
00185 /************************************************************/
00186 
00187 ACE_INLINE
00188 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::To_Be_Added_Info (void)
00189   : event_handle_ (ACE_INVALID_HANDLE),
00190     suspend_entry_ (false)
00191 {
00192 }
00193 
00194 ACE_INLINE void
00195 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::set (ACE_HANDLE event_handle,
00196                                                             bool io_entry,
00197                                                             ACE_Event_Handler *event_handler,
00198                                                             ACE_HANDLE io_handle,
00199                                                             long network_events,
00200                                                             bool delete_event,
00201                                                             bool delete_entry,
00202                                                             ACE_Reactor_Mask close_masks,
00203                                                             bool suspend_entry)
00204 {
00205   this->event_handle_ = event_handle;
00206   this->suspend_entry_ = suspend_entry;
00207   Common_Info::set (io_entry,
00208                     event_handler,
00209                     io_handle,
00210                     network_events,
00211                     delete_event,
00212                     delete_entry,
00213                     close_masks);
00214 }
00215 
00216 ACE_INLINE void
00217 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::set (ACE_HANDLE event_handle,
00218                                                             Common_Info &common_info,
00219                                                             bool suspend_entry)
00220 {
00221   this->event_handle_ = event_handle;
00222   this->suspend_entry_ = suspend_entry;
00223   Common_Info::set (common_info);
00224 }
00225 
00226 ACE_INLINE void
00227 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::reset (void)
00228 {
00229   this->event_handle_ = ACE_INVALID_HANDLE;
00230   this->suspend_entry_ = false;
00231   Common_Info::reset ();
00232 }
00233 
00234 ACE_INLINE void
00235 ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::dump (void) const
00236 {
00237 #if defined (ACE_HAS_DUMP)
00238   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::To_Be_Added_Info::dump");
00239 
00240   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00241 
00242   Common_Info::dump ();
00243 
00244   ACE_DEBUG ((LM_DEBUG,
00245               ACE_TEXT ("Event Handle = %d\n"),
00246               this->event_handle_));
00247 
00248   ACE_DEBUG ((LM_DEBUG,
00249               ACE_TEXT ("Suspend Entry = %d\n"),
00250               this->suspend_entry_));
00251 
00252   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00253 #endif /* ACE_HAS_DUMP */
00254 }
00255 
00256 /************************************************************/
00257 
00258 ACE_INLINE
00259 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::Suspended_Info (void)
00260   : event_handle_ (ACE_INVALID_HANDLE),
00261     resume_entry_ (false)
00262 {
00263 }
00264 
00265 ACE_INLINE void
00266 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::reset (void)
00267 {
00268   this->event_handle_ = ACE_INVALID_HANDLE;
00269   this->resume_entry_ = false;
00270   Common_Info::reset ();
00271 }
00272 
00273 ACE_INLINE void
00274 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::set (ACE_HANDLE event_handle,
00275                                                           bool io_entry,
00276                                                           ACE_Event_Handler *event_handler,
00277                                                           ACE_HANDLE io_handle,
00278                                                           long network_events,
00279                                                           bool delete_event,
00280                                                           bool delete_entry,
00281                                                           ACE_Reactor_Mask close_masks,
00282                                                           bool resume_entry)
00283 {
00284   this->event_handle_ = event_handle;
00285   this->resume_entry_ = resume_entry;
00286   Common_Info::set (io_entry,
00287                     event_handler,
00288                     io_handle,
00289                     network_events,
00290                     delete_event,
00291                     delete_entry,
00292                     close_masks);
00293 }
00294 
00295 ACE_INLINE void
00296 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::set (ACE_HANDLE event_handle,
00297                                                           Common_Info &common_info,
00298                                                           bool resume_entry)
00299 {
00300   this->event_handle_ = event_handle;
00301   this->resume_entry_ = resume_entry;
00302   Common_Info::set (common_info);
00303 }
00304 
00305 ACE_INLINE void
00306 ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::dump (void) const
00307 {
00308 #if defined (ACE_HAS_DUMP)
00309   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::Suspended_Info::dump");
00310 
00311   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00312 
00313   Common_Info::dump ();
00314 
00315   ACE_DEBUG ((LM_DEBUG,
00316               ACE_TEXT ("Event Handle = %d\n"),
00317               this->event_handle_));
00318 
00319   ACE_DEBUG ((LM_DEBUG,
00320               ACE_TEXT ("Resume Entry = %d\n"),
00321               this->resume_entry_));
00322 
00323   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00324 #endif /* ACE_HAS_DUMP */
00325 }
00326 
00327 /************************************************************/
00328 
00329 ACE_INLINE int
00330 ACE_WFMO_Reactor_Handler_Repository::close (void)
00331 {
00332   // Let all the handlers know that the <WFMO_Reactor> is closing down
00333   this->unbind_all ();
00334 
00335   return 0;
00336 }
00337 
00338 ACE_INLINE ACE_HANDLE *
00339 ACE_WFMO_Reactor_Handler_Repository::handles (void) const
00340 {
00341   // This code is probably too subtle to be useful in the long run...
00342   // The basic idea is that all threads wait on all user handles plus
00343   // the <wakeup_all_threads_> handle. The owner thread additional
00344   // waits on the <notify_> handle. This is to ensure that only the
00345   // <owner_> thread get to expire timers and handle event on the
00346   // notify pipe.
00347   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
00348     return this->current_handles_;
00349   else
00350     return this->current_handles_ + 1;
00351 }
00352 
00353 ACE_INLINE ACE_WFMO_Reactor_Handler_Repository::Current_Info *
00354 ACE_WFMO_Reactor_Handler_Repository::current_info (void) const
00355 {
00356   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
00357     return this->current_info_;
00358   else
00359     return this->current_info_ + 1;
00360 }
00361 
00362 ACE_INLINE DWORD
00363 ACE_WFMO_Reactor_Handler_Repository::max_handlep1 (void) const
00364 {
00365   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
00366     return this->max_handlep1_;
00367   else
00368     return this->max_handlep1_ - 1;
00369 }
00370 
00371 ACE_INLINE int
00372 ACE_WFMO_Reactor_Handler_Repository::scheduled_for_deletion (size_t slot) const
00373 {
00374   if (ACE_Thread::self () == this->wfmo_reactor_.owner_i ())
00375     return this->current_info_[slot].delete_entry_ == true;
00376   else
00377     return this->current_info_[slot + 1].delete_entry_ == true;
00378 }
00379 
00380 ACE_INLINE int
00381 ACE_WFMO_Reactor_Handler_Repository::invalid_handle (ACE_HANDLE handle) const
00382 {
00383   ACE_TRACE ("ACE_WFMO_Reactor_Handler_Repository::invalid_handle");
00384   // It's too expensive to perform more exhaustive validity checks on
00385   // Win32 due to the way that they implement SOCKET HANDLEs.
00386   if (handle == ACE_INVALID_HANDLE)
00387     {
00388       errno = EINVAL;
00389       return 1;
00390     }
00391   else
00392     return 0;
00393 }
00394 
00395 ACE_INLINE bool
00396 ACE_WFMO_Reactor_Handler_Repository::changes_required (void)
00397 {
00398   // Check if handles have be scheduled for additions or removal
00399   return this->handles_to_be_added_ > 0
00400     || this->handles_to_be_deleted_ > 0
00401     || this->handles_to_be_suspended_ > 0
00402     || this->handles_to_be_resumed_ > 0;
00403 }
00404 
00405 ACE_INLINE int
00406 ACE_WFMO_Reactor_Handler_Repository::make_changes (void)
00407 {
00408   // This method must ONLY be called by the
00409   // <WFMO_Reactor->change_state_thread_>. We therefore assume that
00410   // there will be no contention for this method and hence no guards
00411   // are neccessary.
00412 
00413   // Deletions and suspensions in current_info_
00414   this->make_changes_in_current_infos ();
00415 
00416   // Deletions and resumptions in current_suspended_info_
00417   this->make_changes_in_suspension_infos ();
00418 
00419   // Deletions in to_be_added_info_, or transfers to current_info_ or
00420   // current_suspended_info_ from to_be_added_info_
00421   this->make_changes_in_to_be_added_infos ();
00422 
00423   return 0;
00424 }
00425 
00426 ACE_INLINE int
00427 ACE_WFMO_Reactor_Handler_Repository::unbind (ACE_HANDLE handle,
00428                                              ACE_Reactor_Mask mask)
00429 {
00430   if (this->invalid_handle (handle))
00431     return -1;
00432 
00433   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->wfmo_reactor_.lock_, -1);
00434 
00435   bool changes_required = false;
00436   int const result = this->unbind_i (handle,
00437                                      mask,
00438                                      changes_required);
00439 
00440   if (changes_required)
00441     // Wake up all threads in WaitForMultipleObjects so that they can
00442     // reconsult the handle set
00443     this->wfmo_reactor_.wakeup_all_threads ();
00444 
00445   return result;
00446 }
00447 
00448 ACE_INLINE int
00449 ACE_WFMO_Reactor::reset_timer_interval
00450   (long timer_id,
00451    const ACE_Time_Value &interval)
00452 {
00453   ACE_TRACE ("ACE_WFMO_Reactor::reset_timer_interval");
00454 
00455   if (0 != this->timer_queue_)
00456     {
00457       long result = this->timer_queue_->reset_interval
00458         (timer_id,
00459          interval);
00460 
00461       // Wakeup the owner thread so that it gets the latest timer values
00462       this->notify ();
00463 
00464       return result;
00465     }
00466 
00467   errno = ESHUTDOWN;
00468   return -1;
00469 }
00470 
00471 ACE_INLINE long
00472 ACE_WFMO_Reactor::schedule_timer (ACE_Event_Handler *handler,
00473                                   const void *arg,
00474                                   const ACE_Time_Value &delay_time,
00475                                   const ACE_Time_Value &interval)
00476 {
00477   ACE_TRACE ("ACE_WFMO_Reactor::schedule_timer");
00478 
00479   if (0 != this->timer_queue_)
00480     {
00481       long result = this->timer_queue_->schedule
00482         (handler,
00483          arg,
00484          timer_queue_->gettimeofday () + delay_time,
00485          interval);
00486 
00487       // Wakeup the owner thread so that it gets the latest timer values
00488       this->notify ();
00489 
00490       return result;
00491     }
00492 
00493   errno = ESHUTDOWN;
00494   return -1;
00495 }
00496 
00497 ACE_INLINE int
00498 ACE_WFMO_Reactor::cancel_timer (ACE_Event_Handler *handler,
00499                                 int dont_call_handle_close)
00500 {
00501   ACE_TRACE ("ACE_WFMO_Reactor::cancel_timer");
00502   if (0 != this->timer_queue_)
00503     return this->timer_queue_->cancel (handler, dont_call_handle_close);
00504   return 0;
00505 }
00506 
00507 ACE_INLINE int
00508 ACE_WFMO_Reactor::cancel_timer (long timer_id,
00509                                 const void **arg,
00510                                 int dont_call_handle_close)
00511 {
00512   ACE_TRACE ("ACE_WFMO_Reactor::cancel_timer");
00513   if (0 != this->timer_queue_)
00514     return this->timer_queue_->cancel (timer_id, arg, dont_call_handle_close);
00515   return 0;
00516 }
00517 
00518 ACE_INLINE int
00519 ACE_WFMO_Reactor::register_handler (ACE_Event_Handler *event_handler,
00520                                     ACE_HANDLE event_handle)
00521 {
00522   // This GUARD is necessary since we are updating shared state.
00523   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00524 
00525   return this->handler_rep_.bind_i (0,
00526                                     event_handler,
00527                                     0,
00528                                     ACE_INVALID_HANDLE,
00529                                     event_handle,
00530                                     0);
00531 }
00532 
00533 ACE_INLINE int
00534 ACE_WFMO_Reactor::register_handler (ACE_Event_Handler *event_handler,
00535                                     ACE_Reactor_Mask mask)
00536 {
00537   // This GUARD is necessary since we are updating shared state.
00538   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00539 
00540   return this->register_handler_i (ACE_INVALID_HANDLE,
00541                                    ACE_INVALID_HANDLE,
00542                                    event_handler,
00543                                    mask);
00544 }
00545 
00546 ACE_INLINE int
00547 ACE_WFMO_Reactor::register_handler (ACE_HANDLE io_handle,
00548                                     ACE_Event_Handler *event_handler,
00549                                     ACE_Reactor_Mask mask)
00550 {
00551   // This GUARD is necessary since we are updating shared state.
00552   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00553 
00554   return this->register_handler_i (ACE_INVALID_HANDLE,
00555                                    io_handle,
00556                                    event_handler,
00557                                    mask);
00558 }
00559 
00560 ACE_INLINE int
00561 ACE_WFMO_Reactor::register_handler (ACE_HANDLE event_handle,
00562                                     ACE_HANDLE io_handle,
00563                                     ACE_Event_Handler *event_handler,
00564                                     ACE_Reactor_Mask mask)
00565 {
00566   // This GUARD is necessary since we are updating shared state.
00567   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00568 
00569   return this->register_handler_i (event_handle,
00570                                    io_handle,
00571                                    event_handler,
00572                                    mask);
00573 }
00574 
00575 ACE_INLINE int
00576 ACE_WFMO_Reactor::register_handler (const ACE_Handle_Set &handles,
00577                                     ACE_Event_Handler *handler,
00578                                     ACE_Reactor_Mask mask)
00579 {
00580   // This GUARD is necessary since we are updating shared state.
00581   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00582 
00583   ACE_Handle_Set_Iterator handle_iter (handles);
00584   ACE_HANDLE h;
00585 
00586   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
00587     if (this->register_handler_i (h,
00588                                   ACE_INVALID_HANDLE,
00589                                   handler,
00590                                   mask) == -1)
00591       return -1;
00592 
00593   return 0;
00594 }
00595 
00596 ACE_INLINE int
00597 ACE_WFMO_Reactor::schedule_wakeup (ACE_HANDLE io_handle,
00598                                    ACE_Reactor_Mask masks_to_be_added)
00599 {
00600   // This GUARD is necessary since we are updating shared state.
00601   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00602 
00603   return this->mask_ops_i (io_handle,
00604                            masks_to_be_added,
00605                            ACE_Reactor::ADD_MASK);
00606 }
00607 
00608 ACE_INLINE int
00609 ACE_WFMO_Reactor::schedule_wakeup (ACE_Event_Handler *event_handler,
00610                                    ACE_Reactor_Mask masks_to_be_added)
00611 {
00612   // This GUARD is necessary since we are updating shared state.
00613   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00614 
00615   return this->mask_ops_i (event_handler->get_handle (),
00616                            masks_to_be_added,
00617                            ACE_Reactor::ADD_MASK);
00618 }
00619 
00620 ACE_INLINE int
00621 ACE_WFMO_Reactor::cancel_wakeup (ACE_HANDLE io_handle,
00622                                  ACE_Reactor_Mask masks_to_be_removed)
00623 {
00624   // This GUARD is necessary since we are updating shared state.
00625   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00626 
00627   return this->mask_ops_i (io_handle,
00628                            masks_to_be_removed,
00629                            ACE_Reactor::CLR_MASK);
00630 }
00631 
00632 ACE_INLINE int
00633 ACE_WFMO_Reactor::cancel_wakeup (ACE_Event_Handler *event_handler,
00634                                  ACE_Reactor_Mask masks_to_be_removed)
00635 {
00636   // This GUARD is necessary since we are updating shared state.
00637   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00638 
00639   return this->mask_ops_i (event_handler->get_handle (),
00640                            masks_to_be_removed,
00641                            ACE_Reactor::CLR_MASK);
00642 }
00643 
00644 ACE_INLINE int
00645 ACE_WFMO_Reactor::remove_handler (ACE_Event_Handler *event_handler,
00646                                   ACE_Reactor_Mask mask)
00647 {
00648   return this->handler_rep_.unbind (event_handler->get_handle (),
00649                                     mask);
00650 }
00651 
00652 ACE_INLINE int
00653 ACE_WFMO_Reactor::remove_handler (ACE_HANDLE handle,
00654                                   ACE_Reactor_Mask mask)
00655 {
00656   return this->handler_rep_.unbind (handle,
00657                                     mask);
00658 }
00659 
00660 ACE_INLINE int
00661 ACE_WFMO_Reactor::remove_handler (const ACE_Handle_Set &handles,
00662                                   ACE_Reactor_Mask mask)
00663 {
00664   ACE_Handle_Set_Iterator handle_iter (handles);
00665   ACE_HANDLE h;
00666   bool changes_required = false;
00667 
00668   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00669 
00670   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
00671     if (this->handler_rep_.unbind_i (h,
00672                                      mask,
00673                                      changes_required) == -1)
00674       return -1;
00675 
00676   // Wake up all threads in WaitForMultipleObjects so that they can
00677   // reconsult the handle set
00678   this->wakeup_all_threads ();
00679 
00680   return 0;
00681 }
00682 
00683 ACE_INLINE int
00684 ACE_WFMO_Reactor::suspend_handler (ACE_HANDLE handle)
00685 {
00686   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00687 
00688   bool changes_required = false;
00689   int const result =
00690     this->handler_rep_.suspend_handler_i (handle,
00691                                           changes_required);
00692 
00693   if (changes_required)
00694     // Wake up all threads in WaitForMultipleObjects so that they can
00695     // reconsult the handle set
00696     this->wakeup_all_threads ();
00697 
00698   return result;
00699 }
00700 
00701 ACE_INLINE int
00702 ACE_WFMO_Reactor::suspend_handler (ACE_Event_Handler *event_handler)
00703 {
00704   return this->suspend_handler (event_handler->get_handle ());
00705 }
00706 
00707 ACE_INLINE int
00708 ACE_WFMO_Reactor::suspend_handler (const ACE_Handle_Set &handles)
00709 {
00710   ACE_Handle_Set_Iterator handle_iter (handles);
00711   ACE_HANDLE h;
00712   bool changes_required = false;
00713 
00714   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00715 
00716   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
00717     if (this->handler_rep_.suspend_handler_i (h,
00718                                               changes_required) == -1)
00719       return -1;
00720 
00721   // Wake up all threads in WaitForMultipleObjects so that they can
00722   // reconsult the handle set
00723   this->wakeup_all_threads ();
00724 
00725   return 0;
00726 }
00727 
00728 ACE_INLINE int
00729 ACE_WFMO_Reactor::suspend_handlers (void)
00730 {
00731   bool error = false;
00732   int result = 0;
00733   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00734 
00735   // First suspend all current handles
00736   bool changes_required = false;
00737 
00738   for (size_t i = 0;
00739        i < this->handler_rep_.max_handlep1_ && !error;
00740        i++)
00741     {
00742       result =
00743         this->handler_rep_.suspend_handler_i (this->handler_rep_.current_handles_[i],
00744                                               changes_required);
00745       if (result == -1)
00746         error = true;
00747     }
00748 
00749   // Then suspend all to_be_added_handles
00750   for (size_t i = 0;
00751        i < this->handler_rep_.handles_to_be_added_ && !error;
00752        i++)
00753     {
00754       if (this->handler_rep_.to_be_added_info_[i].io_entry_)
00755         {
00756           result =
00757             this->handler_rep_.suspend_handler_i (this->handler_rep_.to_be_added_info_[i].io_handle_,
00758                                                   changes_required);
00759         }
00760       else
00761         {
00762           result =
00763             this->handler_rep_.suspend_handler_i (this->handler_rep_.to_be_added_info_[i].event_handle_,
00764                                                   changes_required);
00765         }
00766       if (result == -1)
00767         error = true;
00768     }
00769 
00770   // Wake up all threads in WaitForMultipleObjects so that they can
00771   // reconsult the handle set
00772   this->wakeup_all_threads ();
00773 
00774   return error ? -1 : 0;
00775 }
00776 
00777 ACE_INLINE int
00778 ACE_WFMO_Reactor::resume_handler (ACE_HANDLE handle)
00779 {
00780   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00781 
00782   bool changes_required = false;
00783   int result =
00784     this->handler_rep_.resume_handler_i (handle, changes_required);
00785 
00786   if (changes_required)
00787     // Wake up all threads in WaitForMultipleObjects so that they can
00788     // reconsult the handle set
00789     this->wakeup_all_threads ();
00790 
00791   return result;
00792 }
00793 
00794 ACE_INLINE int
00795 ACE_WFMO_Reactor::resume_handler (ACE_Event_Handler *event_handler)
00796 {
00797   return this->resume_handler (event_handler->get_handle ());
00798 }
00799 
00800 ACE_INLINE int
00801 ACE_WFMO_Reactor::resume_handler (const ACE_Handle_Set &handles)
00802 {
00803   ACE_Handle_Set_Iterator handle_iter (handles);
00804   ACE_HANDLE h;
00805   bool changes_required = false;
00806 
00807   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00808 
00809   while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
00810     if (this->handler_rep_.resume_handler_i (h,
00811                                              changes_required) == -1)
00812       return -1;
00813 
00814   // Wake up all threads in WaitForMultipleObjects so that they can
00815   // reconsult the handle set
00816   this->wakeup_all_threads ();
00817 
00818   return 0;
00819 }
00820 
00821 ACE_INLINE int
00822 ACE_WFMO_Reactor::resume_handlers (void)
00823 {
00824   bool error = false;
00825   int result = 0;
00826   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00827 
00828   bool changes_required = false;
00829   for (size_t i = 0;
00830        i < this->handler_rep_.suspended_handles_ && !error;
00831        i++)
00832     {
00833       result =
00834         this->handler_rep_.resume_handler_i (this->handler_rep_.current_suspended_info_[i].event_handle_,
00835                                              changes_required);
00836       if (result == -1)
00837         error = true;
00838     }
00839 
00840   // Then resume all to_be_added_handles
00841   for (size_t i = 0;
00842         i < this->handler_rep_.handles_to_be_added_ && !error;
00843         i++)
00844     {
00845       if (this->handler_rep_.to_be_added_info_[i].io_entry_)
00846         {
00847           result =
00848             this->handler_rep_.resume_handler_i (this->handler_rep_.to_be_added_info_[i].io_handle_,
00849                                                   changes_required);
00850         }
00851       else
00852         {
00853           result =
00854            this->handler_rep_.resume_handler_i (this->handler_rep_.to_be_added_info_[i].event_handle_,
00855                                                 changes_required);
00856         }
00857       if (result == -1)
00858         error = true;
00859     }
00860 
00861   // Wake up all threads in WaitForMultipleObjects so that they can
00862   // reconsult the handle set
00863   this->wakeup_all_threads ();
00864 
00865   return error ? -1 : 0;
00866 }
00867 
00868 ACE_INLINE int
00869 ACE_WFMO_Reactor::uses_event_associations (void)
00870 {
00871   // Since the WFMO_Reactor does use event associations, this function
00872   // always return 1.
00873   return 1;
00874 }
00875 
00876 ACE_INLINE int
00877 ACE_WFMO_Reactor::handle_events (ACE_Time_Value &how_long)
00878 {
00879   return this->event_handling (&how_long, FALSE);
00880 }
00881 
00882 ACE_INLINE int
00883 ACE_WFMO_Reactor::alertable_handle_events (ACE_Time_Value &how_long)
00884 {
00885   return this->event_handling (&how_long, TRUE);
00886 }
00887 
00888 ACE_INLINE int
00889 ACE_WFMO_Reactor::handle_events (ACE_Time_Value *how_long)
00890 {
00891   return this->event_handling (how_long, FALSE);
00892 }
00893 
00894 ACE_INLINE int
00895 ACE_WFMO_Reactor::alertable_handle_events (ACE_Time_Value *how_long)
00896 {
00897   return this->event_handling (how_long, TRUE);
00898 }
00899 
00900 ACE_INLINE int
00901 ACE_WFMO_Reactor::deactivated (void)
00902 {
00903   return this->deactivated_;
00904 }
00905 
00906 ACE_INLINE void
00907 ACE_WFMO_Reactor::deactivate (int do_stop)
00908 {
00909   this->deactivated_ = do_stop;
00910   this->wakeup_all_threads ();
00911 }
00912 
00913 ACE_INLINE int
00914 ACE_WFMO_Reactor::owner (ACE_thread_t *t)
00915 {
00916   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
00917   *t = this->owner_i ();
00918   return 0;
00919 }
00920 
00921 ACE_INLINE ACE_thread_t
00922 ACE_WFMO_Reactor::owner_i (void)
00923 {
00924   return this->owner_;
00925 }
00926 
00927 ACE_INLINE int
00928 ACE_WFMO_Reactor::owner (ACE_thread_t new_owner, ACE_thread_t *old_owner)
00929 {
00930   ACE_GUARD_RETURN (ACE_Process_Mutex, monitor, this->lock_, -1);
00931   this->new_owner_ = new_owner;
00932 
00933   if (old_owner != 0)
00934     *old_owner = this->owner_i ();
00935 
00936   // Wake up all threads in WaitForMultipleObjects so that they can
00937   // reconsult the new owner responsibilities
00938   this->wakeup_all_threads ();
00939 
00940   return 0;
00941 }
00942 
00943 ACE_INLINE int
00944 ACE_WFMO_Reactor::new_owner (void)
00945 {
00946   return this->new_owner_ != ACE_thread_t (0);
00947 }
00948 
00949 ACE_INLINE int
00950 ACE_WFMO_Reactor::change_owner (void)
00951 {
00952   this->owner_ = this->new_owner_;
00953   this->new_owner_ = ACE_thread_t (0);
00954   return 0;
00955 }
00956 
00957 ACE_INLINE int
00958 ACE_WFMO_Reactor::safe_dispatch (DWORD wait_status)
00959 {
00960   int result = -1;
00961   ACE_SEH_TRY
00962     {
00963       result = this->dispatch (wait_status);
00964     }
00965   ACE_SEH_FINALLY
00966     {
00967       this->update_state ();
00968     }
00969 
00970   return result;
00971 }
00972 
00973 ACE_INLINE int
00974 ACE_WFMO_Reactor::dispatch_window_messages (void)
00975 {
00976   return 0;
00977 }
00978 
00979 ACE_INLINE void
00980 ACE_WFMO_Reactor::wakeup_all_threads (void)
00981 {
00982   this->wakeup_all_threads_.signal ();
00983 }
00984 
00985 ACE_INLINE int
00986 ACE_WFMO_Reactor::notify (ACE_Event_Handler *event_handler,
00987                           ACE_Reactor_Mask mask,
00988                           ACE_Time_Value *timeout)
00989 {
00990   return this->notify_handler_->notify (event_handler, mask, timeout);
00991 }
00992 
00993 ACE_INLINE int
00994 ACE_WFMO_Reactor::register_handler (int signum,
00995                                     ACE_Event_Handler *new_sh,
00996                                     ACE_Sig_Action *new_disp,
00997                                     ACE_Event_Handler **old_sh,
00998                                     ACE_Sig_Action *old_disp)
00999 {
01000   return this->signal_handler_->register_handler (signum,
01001                                                   new_sh, new_disp,
01002                                                   old_sh, old_disp);
01003 }
01004 
01005 ACE_INLINE int
01006 ACE_WFMO_Reactor::register_handler (const ACE_Sig_Set &sigset,
01007                                     ACE_Event_Handler *new_sh,
01008                                     ACE_Sig_Action *new_disp)
01009 {
01010   int result = 0;
01011 
01012 #if (ACE_NSIG > 0)
01013   for (int s = 1; s < ACE_NSIG; s++)
01014     if (sigset.is_member (s)
01015         && this->signal_handler_->register_handler (s,
01016                                                     new_sh,
01017                                                     new_disp) == -1)
01018       result = -1;
01019 #else
01020   ACE_UNUSED_ARG (sigset);
01021   ACE_UNUSED_ARG (new_sh);
01022   ACE_UNUSED_ARG (new_disp);
01023 #endif /* ACE_NSIG */
01024 
01025   return result;
01026 }
01027 
01028 ACE_INLINE int
01029 ACE_WFMO_Reactor::remove_handler (int signum,
01030                                   ACE_Sig_Action *new_disp,
01031                                   ACE_Sig_Action *old_disp,
01032                                   int sigkey)
01033 {
01034   return this->signal_handler_->remove_handler (signum,
01035                                                 new_disp,
01036                                                 old_disp,
01037                                                 sigkey);
01038 }
01039 
01040 ACE_INLINE int
01041 ACE_WFMO_Reactor::remove_handler (const ACE_Sig_Set &sigset)
01042 {
01043   int result = 0;
01044 
01045 #if (ACE_NSIG > 0)
01046   for (int s = 1; s < ACE_NSIG; s++)
01047     if (sigset.is_member (s)
01048         && this->signal_handler_->remove_handler (s) == -1)
01049       result = -1;
01050 #else
01051   ACE_UNUSED_ARG (sigset);
01052 #endif /* ACE_NSIG */
01053 
01054   return result;
01055 }
01056 
01057 ACE_INLINE int
01058 ACE_WFMO_Reactor::handler (int signum, ACE_Event_Handler **eh)
01059 {
01060   ACE_Event_Handler *handler =
01061     this->signal_handler_->handler (signum);
01062 
01063   if (handler == 0)
01064     return -1;
01065   else if (eh != 0)
01066     *eh = handler;
01067   return 0;
01068 }
01069 
01070 ACE_INLINE int
01071 ACE_WFMO_Reactor::mask_ops (ACE_Event_Handler *event_handler,
01072                             ACE_Reactor_Mask mask,
01073                             int operation)
01074 {
01075   ACE_GUARD_RETURN (ACE_Process_Mutex, monitor, this->lock_, -1);
01076 
01077   return this->mask_ops_i (event_handler->get_handle (),
01078                            mask,
01079                            operation);
01080 }
01081 
01082 ACE_INLINE int
01083 ACE_WFMO_Reactor::mask_ops (ACE_HANDLE io_handle,
01084                             ACE_Reactor_Mask mask,
01085                             int operation)
01086 {
01087   ACE_GUARD_RETURN (ACE_Process_Mutex, monitor, this->lock_, -1);
01088 
01089   return this->mask_ops_i (io_handle,
01090                            mask,
01091                            operation);
01092 }
01093 
01094 ACE_INLINE void
01095 ACE_WFMO_Reactor::requeue_position (int)
01096 {
01097   // Not implemented
01098 }
01099 
01100 ACE_INLINE int
01101 ACE_WFMO_Reactor::requeue_position (void)
01102 {
01103   // Don't have an implementation for this yet...
01104   ACE_NOTSUP_RETURN (-1);
01105 }
01106 
01107 ACE_INLINE int
01108 ACE_WFMO_Reactor::restart (void)
01109 {
01110   return 0;
01111 }
01112 
01113 ACE_INLINE int
01114 ACE_WFMO_Reactor::restart (int)
01115 {
01116   return 0;
01117 }
01118 
01119 ACE_INLINE int
01120 ACE_WFMO_Reactor::ready_ops (ACE_Event_Handler *event_handler,
01121                              ACE_Reactor_Mask mask,
01122                              int ops)
01123 {
01124   // Don't have an implementation for this yet...
01125   ACE_UNUSED_ARG (event_handler);
01126   ACE_UNUSED_ARG (mask);
01127   ACE_UNUSED_ARG (ops);
01128   ACE_NOTSUP_RETURN (-1);
01129 }
01130 
01131 ACE_INLINE int
01132 ACE_WFMO_Reactor::ready_ops (ACE_HANDLE handle,
01133                              ACE_Reactor_Mask,
01134                              int ops)
01135 {
01136   // Don't have an implementation for this yet...
01137   ACE_UNUSED_ARG (handle);
01138   ACE_UNUSED_ARG (ops);
01139   ACE_NOTSUP_RETURN (-1);
01140 }
01141 
01142 ACE_INLINE ACE_Event_Handler *
01143 ACE_WFMO_Reactor::find_handler (ACE_HANDLE handle)
01144 {
01145   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, 0);
01146 
01147   return this->handler_rep_.find_handler (handle);
01148 }
01149 
01150 ACE_INLINE int
01151 ACE_WFMO_Reactor::handler (ACE_HANDLE handle,
01152                            ACE_Reactor_Mask mask,
01153                            ACE_Event_Handler **event_handler)
01154 {
01155   ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, this->lock_, -1);
01156 
01157   return this->handler_rep_.handler (handle,
01158                                      mask,
01159                                      event_handler);
01160 }
01161 
01162 ACE_INLINE bool
01163 ACE_WFMO_Reactor::initialized (void)
01164 {
01165   return this->open_for_business_;
01166 }
01167 
01168 ACE_INLINE ACE_Lock &
01169 ACE_WFMO_Reactor::lock (void)
01170 {
01171   return this->lock_adapter_;
01172 }
01173 
01174 ACE_INLINE size_t
01175 ACE_WFMO_Reactor::size (void) const
01176 {
01177   // Size of repository minus the 2 used for internal purposes
01178   return this->handler_rep_.max_size_ - 2;
01179 }
01180 #else
01181 ACE_INLINE bool
01182 ACE_WFMO_Reactor_Handler_Repository::changes_required (void)
01183 {
01184   return false;
01185 }
01186 
01187 ACE_INLINE int
01188 ACE_WFMO_Reactor_Handler_Repository::make_changes (void)
01189 {
01190   return 0;
01191 }
01192 
01193 ACE_INLINE
01194 ACE_WFMO_Reactor_Handler_Repository::~ACE_WFMO_Reactor_Handler_Repository (void)
01195 {
01196 }
01197 
01198 #endif /* ACE_WIN32 */
01199 
01200 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:44 2010 for ACE by  doxygen 1.4.7