Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

WFMO_Reactor.i

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

Generated on Mon Jun 16 11:22:08 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002