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

ACE_Asynch_Pseudo_Task Class Reference

#include <Asynch_Pseudo_Task.h>

Inheritance diagram for ACE_Asynch_Pseudo_Task:

Inheritance graph
[legend]
Collaboration diagram for ACE_Asynch_Pseudo_Task:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Asynch_Pseudo_Task ()
virtual ~ACE_Asynch_Pseudo_Task ()
int start (void)
int stop (void)
virtual int svc (void)
 Run by a daemon thread to handle deferred processing. More...

int is_active (void)
int register_io_handler (ACE_HANDLE handle, ACE_Event_Handler *handler, ACE_Reactor_Mask mask, int flg_suspend)
int remove_io_handler (ACE_HANDLE handle)
int remove_io_handler (ACE_Handle_Set &set)
int resume_io_handler (ACE_HANDLE handle)
int suspend_io_handler (ACE_HANDLE handle)

Protected Methods

int lock_finish (void)
int unlock_finish (void)

Protected Attributes

int flg_active_
ACE_Select_Reactor select_reactor_
ACE_Reactor reactor_
 Pointer to the various event demultiplexors. More...

ACE_Locktoken_
int finish_count_
ACE_Manual_Event finish_event_

Friends

class ACE_POSIX_Asynch_Accept
class ACE_POSIX_Asynch_Connect
class ACE_WIN32_Asynch_Connect

Constructor & Destructor Documentation

ACE_Asynch_Pseudo_Task::ACE_Asynch_Pseudo_Task  
 

Definition at line 8 of file Asynch_Pseudo_Task.cpp.

00009   : flg_active_ (0),
00010     select_reactor_ (),               // should be initialized before reactor_
00011     reactor_ (&select_reactor_, 0),   // don't delete implementation
00012     token_ (select_reactor_.lock ()), // we can use reactor token       
00013     finish_count_ (0)
00014 {
00015 }

ACE_Asynch_Pseudo_Task::~ACE_Asynch_Pseudo_Task   [virtual]
 

Definition at line 17 of file Asynch_Pseudo_Task.cpp.

References stop.

00018 {
00019   stop();
00020 }


Member Function Documentation

int ACE_Asynch_Pseudo_Task::is_active void   
 

Definition at line 23 of file Asynch_Pseudo_Task.cpp.

References ACE_GUARD_RETURN, ACE_MT, and flg_active_.

Referenced by ACE_WIN32_Asynch_Connect::handle_close, and ACE_POSIX_Asynch_Connect::handle_close.

00024 {
00025   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00026   return flg_active_;
00027 }

int ACE_Asynch_Pseudo_Task::lock_finish void    [protected]
 

Definition at line 98 of file Asynch_Pseudo_Task.cpp.

References ACE_GUARD_RETURN, ACE_MT, and finish_count_.

Referenced by ACE_WIN32_Asynch_Connect::handle_close, ACE_POSIX_Asynch_Connect::handle_close, and ACE_POSIX_Asynch_Accept::handle_close.

00099 {
00100   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00101   finish_count_ ++;
00102   return 0;
00103 }

int ACE_Asynch_Pseudo_Task::register_io_handler ACE_HANDLE    handle,
ACE_Event_Handler   handler,
ACE_Reactor_Mask    mask,
int    flg_suspend
 

Definition at line 155 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_Reactor_Mask, ACE_Event_Handler::ALL_EVENTS_MASK, ACE_Event_Handler::DONT_CALL, flg_active_, LM_ERROR, reactor_, ACE_Reactor::register_handler, ACE_Reactor::remove_handler, and ACE_Reactor::suspend_handler.

Referenced by ACE_WIN32_Asynch_Connect::connect, ACE_POSIX_Asynch_Connect::connect, and ACE_POSIX_Asynch_Accept::open.

00159 {
00160   //  Return codes : 
00161   //   0  success
00162   //  -1  reactor errors
00163   //  -2  task not active 
00164 
00165   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00166 
00167   if (this->flg_active_ == 0)
00168     ACE_ERROR_RETURN ((LM_ERROR,
00169                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::register_io_handler \n")
00170                        ACE_LIB_TEXT ("task not active \n")),
00171                       -2);
00172     
00173   // Register the handler with the reactor.
00174   int retval = this->reactor_.register_handler (handle, handler, mask);
00175                                                     
00176   if (retval == -1)
00177     ACE_ERROR_RETURN ((LM_ERROR,
00178                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::register_io_handler \n")
00179                        ACE_LIB_TEXT ("register_handler failed \n")),
00180                       -1);
00181 
00182   if (flg_suspend == 0 )
00183     return 0;
00184 
00185   // Suspend the <handle> now. Enable only when the <accept> is issued
00186   // by the application.
00187   retval = this->reactor_.suspend_handler (handle);
00188 
00189   if (retval == -1)
00190     {
00191       this->reactor_.remove_handler (handle,
00192                                      ACE_Event_Handler::ALL_EVENTS_MASK
00193                                      | ACE_Event_Handler::DONT_CALL); 
00194  
00195       ACE_ERROR_RETURN ((LM_ERROR,
00196                          ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::register_io_handler \n")
00197                          ACE_LIB_TEXT ("suspend_handler failed \n")),
00198                         -1);
00199     }
00200 
00201   return 0;
00202 }

int ACE_Asynch_Pseudo_Task::remove_io_handler ACE_Handle_Set   set
 

Definition at line 234 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_Event_Handler::ALL_EVENTS_MASK, ACE_Event_Handler::DONT_CALL, flg_active_, LM_ERROR, reactor_, and ACE_Reactor::remove_handler.

00235 {
00236   //  Return codes : 
00237   //   0  success
00238   //  -1  reactor errors
00239   //  -2  task not active 
00240 
00241   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00242 
00243   if (this->flg_active_ == 0)
00244     ACE_ERROR_RETURN ((LM_ERROR,
00245                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::remove_io_handler \n")
00246                        ACE_LIB_TEXT ("task not active \n")),
00247                       -2);
00248     
00249   int retval =
00250     this->reactor_.remove_handler (set ,
00251                                    ACE_Event_Handler::ALL_EVENTS_MASK
00252                                    | ACE_Event_Handler::DONT_CALL); 
00253   if (retval == -1)
00254     ACE_ERROR_RETURN ((LM_ERROR,
00255                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::remove_io_handler \n")
00256                        ACE_LIB_TEXT ("remove_handler failed \n")),
00257                       -1);
00258 
00259   return 0;
00260 }

int ACE_Asynch_Pseudo_Task::remove_io_handler ACE_HANDLE    handle
 

Definition at line 205 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_Event_Handler::ALL_EVENTS_MASK, ACE_Event_Handler::DONT_CALL, flg_active_, LM_ERROR, reactor_, and ACE_Reactor::remove_handler.

Referenced by ACE_WIN32_Asynch_Connect::cancel, ACE_POSIX_Asynch_Connect::cancel, ACE_WIN32_Asynch_Connect::close, ACE_POSIX_Asynch_Connect::close, ACE_POSIX_Asynch_Accept::close, ACE_WIN32_Asynch_Connect::handle_close, and ACE_POSIX_Asynch_Connect::handle_close.

00206 {
00207   //  Return codes : 
00208   //   0  success
00209   //  -1  reactor errors
00210   //  -2  task not active 
00211 
00212   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00213 
00214   if (this->flg_active_ == 0)
00215     ACE_ERROR_RETURN ((LM_ERROR,
00216                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::remove_io_handler \n")
00217                        ACE_LIB_TEXT ("task not active \n")),
00218                       -2);
00219     
00220   int retval =
00221     this->reactor_.remove_handler (handle ,
00222                                    ACE_Event_Handler::ALL_EVENTS_MASK
00223                                    | ACE_Event_Handler::DONT_CALL); 
00224   if (retval == -1)
00225     ACE_ERROR_RETURN ((LM_ERROR,
00226                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::remove_io_handler \n")
00227                        ACE_LIB_TEXT ("remove_handler failed \n")),
00228                       -1);
00229 
00230   return 0;
00231 }

int ACE_Asynch_Pseudo_Task::resume_io_handler ACE_HANDLE    handle
 

Definition at line 290 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, flg_active_, LM_ERROR, reactor_, and ACE_Reactor::resume_handler.

Referenced by ACE_POSIX_Asynch_Accept::accept.

00291 {
00292   //  Return codes : 
00293   //   0  success
00294   //  -1  reactor errors
00295   //  -2  task not active 
00296 
00297   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00298 
00299   if (this->flg_active_ == 0)
00300     ACE_ERROR_RETURN ((LM_ERROR,
00301                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::resume_io_handler \n")
00302                        ACE_LIB_TEXT ("task not active \n")),
00303                       -2);
00304     
00305   int retval = this->reactor_.resume_handler (handle);
00306 
00307   if (retval == -1)
00308     ACE_ERROR_RETURN ((LM_ERROR,
00309                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::resume_io_handler \n")
00310                        ACE_LIB_TEXT ("resume_handler failed \n")),
00311                       -1);
00312 
00313   return 0;
00314 }

int ACE_Asynch_Pseudo_Task::start void   
 

Definition at line 30 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_Task_Base::activate, flg_active_, ACE_Reactor::initialized, LM_ERROR, and reactor_.

Referenced by ACE_POSIX_AIOCB_Proactor::ACE_POSIX_AIOCB_Proactor, ACE_POSIX_CB_Proactor::ACE_POSIX_CB_Proactor, and ACE_WIN32_Proactor::ACE_WIN32_Proactor.

00031 {
00032   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00033 
00034   if (this->flg_active_)
00035     ACE_ERROR_RETURN ((LM_ERROR,
00036                        ACE_LIB_TEXT ("%N:%l:%p\n"),
00037                        ACE_LIB_TEXT ("ACE_Asynch_Pseudo_Task::start already started")),
00038                        -1);
00039 
00040   if (this->reactor_.initialized () == 0)
00041     ACE_ERROR_RETURN ((LM_ERROR,
00042                        ACE_LIB_TEXT ("%N:%l:%p\n"),
00043                        ACE_LIB_TEXT ("ACE_Asynch_Pseudo_Task::start reactor is not initialized")),
00044                        -1);
00045 
00046 
00047   if (this->activate (THR_NEW_LWP | THR_JOINABLE, 1) != 0)
00048     ACE_ERROR_RETURN ((LM_ERROR,
00049                        ACE_LIB_TEXT ("%N:%l:%p\n"),
00050                        ACE_LIB_TEXT ("ACE_Asynch_Pseudo_Task::start failed")),
00051                        -1);
00052 
00053   this->flg_active_ = 1;
00054   return 0;
00055 }

int ACE_Asynch_Pseudo_Task::stop void   
 

Definition at line 58 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_Reactor::close, ACE_Reactor::end_reactor_event_loop, finish_count_, finish_event_, flg_active_, ACE_Reactor::initialized, LM_ERROR, reactor_, ACE_Event::reset, ACE_Event::wait, and ACE_Task_Base::wait.

Referenced by ACE_POSIX_AIOCB_Proactor::close, ~ACE_Asynch_Pseudo_Task, and ACE_WIN32_Proactor::~ACE_WIN32_Proactor.

00059 {
00060   {
00061     ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00062 
00063     if (this->flg_active_ == 0)  // already stopped 
00064       return 0;
00065 
00066     reactor_.end_reactor_event_loop ();
00067   }
00068 
00069   int rc = this->wait ();
00070 
00071   if  (rc != 0)
00072     ACE_ERROR_RETURN ((LM_ERROR,
00073                        ACE_LIB_TEXT ("%N:%l:%p\n"),
00074                        ACE_LIB_TEXT ("ACE_Asynch_Pseudo_Task::stop failed")),
00075                        -1);
00076 
00077   {
00078     ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00079     this->flg_active_ = 0;
00080 
00081     if (this->reactor_.initialized ())
00082       this->reactor_.close ();
00083 
00084     while (finish_count_ > 0)
00085       {
00086         ACE_MT (ace_mon.release ());
00087         finish_event_.wait ();
00088 
00089         ACE_MT (ace_mon.acquire ());
00090         finish_event_.reset ();
00091       }
00092   }
00093 
00094   return rc;
00095 }

int ACE_Asynch_Pseudo_Task::suspend_io_handler ACE_HANDLE    handle
 

Definition at line 263 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, flg_active_, LM_ERROR, reactor_, and ACE_Reactor::suspend_handler.

Referenced by ACE_POSIX_Asynch_Accept::cancel, and ACE_POSIX_Asynch_Accept::handle_input.

00264 {
00265   //  Return codes : 
00266   //   0  success
00267   //  -1  reactor errors
00268   //  -2  task not active 
00269 
00270   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00271 
00272   if (this->flg_active_ == 0)
00273     ACE_ERROR_RETURN ((LM_ERROR,
00274                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::suspend_io_handler \n")
00275                        ACE_LIB_TEXT ("task not active \n")),
00276                       -2);
00277     
00278   int retval = this->reactor_.suspend_handler (handle);
00279 
00280   if (retval == -1)
00281     ACE_ERROR_RETURN ((LM_ERROR,
00282                        ACE_LIB_TEXT ("%N:%l:ACE_Asynch_Pseudo_Task::suspend_io_handler \n")
00283                        ACE_LIB_TEXT ("suspend_handler failed \n")),
00284                       -1);
00285 
00286   return 0;
00287 }

int ACE_Asynch_Pseudo_Task::svc void    [virtual]
 

Run by a daemon thread to handle deferred processing.

Reimplemented from ACE_Task_Base.

Definition at line 117 of file Asynch_Pseudo_Task.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_SIGRTMAX, ACE_SIGRTMIN, LM_ERROR, ACE_Reactor::owner, ACE_OS::pthread_sigmask, reactor_, ACE_Reactor::run_reactor_event_loop, ACE_Thread::self, and SIG_BLOCK.

00118 {
00119 #if !defined (ACE_WIN32) 
00120 
00121   sigset_t RT_signals;
00122 
00123   if (sigemptyset (&RT_signals) == -1)
00124     ACE_ERROR ((LM_ERROR,
00125                 ACE_LIB_TEXT ("Error:(%P | %t):%p\n"),
00126                 ACE_LIB_TEXT ("sigemptyset failed")));
00127 
00128   int member = 0;
00129 
00130   for (int si = ACE_SIGRTMIN; si <= ACE_SIGRTMAX; si++)
00131     {
00132       member = sigismember (& RT_signals , si);
00133       if (member == 1)
00134         {
00135           sigaddset (&RT_signals, si);
00136         }
00137     }
00138 
00139   if (ACE_OS::pthread_sigmask (SIG_BLOCK, &RT_signals, 0) != 0)
00140     ACE_ERROR ((LM_ERROR,
00141                 ACE_LIB_TEXT ("Error:(%P | %t):%p\n"),
00142                 ACE_LIB_TEXT ("pthread_sigmask failed")));
00143 #endif
00144 
00145   reactor_.owner (ACE_Thread::self());
00146 
00147   reactor_.run_reactor_event_loop ();
00148 
00149   return 0;
00150 }

int ACE_Asynch_Pseudo_Task::unlock_finish void    [protected]
 

Definition at line 106 of file Asynch_Pseudo_Task.cpp.

References ACE_GUARD_RETURN, ACE_MT, finish_count_, finish_event_, and ACE_Event::signal.

Referenced by ACE_POSIX_Asynch_Accept::accept, ACE_WIN32_Asynch_Connect::cancel, ACE_POSIX_Asynch_Connect::cancel, ACE_POSIX_Asynch_Accept::cancel, ACE_WIN32_Asynch_Connect::close, ACE_POSIX_Asynch_Connect::close, ACE_POSIX_Asynch_Accept::close, ACE_WIN32_Asynch_Connect::connect, and ACE_POSIX_Asynch_Connect::connect.

00107 {
00108   ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->token_, -1));
00109 
00110   --finish_count_;
00111   finish_event_.signal ();
00112 
00113   return 0;
00114 }


Friends And Related Function Documentation

friend class ACE_POSIX_Asynch_Accept [friend]
 

Definition at line 34 of file Asynch_Pseudo_Task.h.

friend class ACE_POSIX_Asynch_Connect [friend]
 

Definition at line 35 of file Asynch_Pseudo_Task.h.

friend class ACE_WIN32_Asynch_Connect [friend]
 

Definition at line 36 of file Asynch_Pseudo_Task.h.


Member Data Documentation

int ACE_Asynch_Pseudo_Task::finish_count_ [protected]
 

Definition at line 74 of file Asynch_Pseudo_Task.h.

Referenced by lock_finish, stop, and unlock_finish.

ACE_Manual_Event ACE_Asynch_Pseudo_Task::finish_event_ [protected]
 

Definition at line 75 of file Asynch_Pseudo_Task.h.

Referenced by stop, and unlock_finish.

int ACE_Asynch_Pseudo_Task::flg_active_ [protected]
 

Definition at line 65 of file Asynch_Pseudo_Task.h.

Referenced by is_active, register_io_handler, remove_io_handler, resume_io_handler, start, stop, and suspend_io_handler.

ACE_Reactor ACE_Asynch_Pseudo_Task::reactor_ [protected]
 

Pointer to the various event demultiplexors.

Reimplemented from ACE_Event_Handler.

Definition at line 70 of file Asynch_Pseudo_Task.h.

Referenced by register_io_handler, remove_io_handler, resume_io_handler, start, stop, suspend_io_handler, and svc.

ACE_Select_Reactor ACE_Asynch_Pseudo_Task::select_reactor_ [protected]
 

Definition at line 67 of file Asynch_Pseudo_Task.h.

ACE_Lock& ACE_Asynch_Pseudo_Task::token_ [protected]
 

Definition at line 72 of file Asynch_Pseudo_Task.h.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:45:18 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002