Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

ReactorThread.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 /*! \file ReactorThread.h
00003 *  \brief Declares and defines a class that manages threads for an ACE_Reactor.
00004 *  \author $Author: rsharo $
00005 *  \version $Revision: 1.1 $
00006 *  \date    $Date: 2004/04/07 13:45:04 $
00007 *///////////////////////////////////////////////////////////////////////////////
00008 #ifndef REACTOR_THREAD_H
00009 #define REACTOR_THREAD_H
00010 
00011 #include "ace/Reactor.h"
00012 #include "ace/Task.h"
00013 
00014 
00015 //
00016 // A class that encapsulates one or more reactor threads.
00017 // A reactor requires one or more threads to operate.  This class 
00018 // simplifies the spawning and termination of these reactor threads.
00019 class ReactorThread : public ACE_Task_Base
00020 {
00021 public:
00022         //
00023         // Constructs a ReactorThread object and spawns threads.
00024         // Spawns the specified number of threads, all running the reactor's
00025         // event loop.
00026         ReactorThread(ACE_Reactor *pReactor = ACE_Reactor::instance(), int numThreads=1)
00027                 : m_pReactor(pReactor)
00028         {
00029                 this->activate(THR_NEW_LWP | THR_JOINABLE, numThreads);
00030         }
00031         
00032         //
00033         // Destroys the ReactorThread object and terminates its threads.
00034         // Commands all the reactor's threads to stop running the reactor's
00035         // event loop and waits for them to actually terminate.
00036         ~ReactorThread()
00037         {
00038                 m_pReactor->end_reactor_event_loop();
00039                 
00040                 this->wait();
00041         }
00042         
00043         //
00044         // Implementation of ACE_Task_Base::svc().  This method
00045         // runs the reactor's event loop.
00046         int svc()
00047         {
00048                 return m_pReactor->run_reactor_event_loop();
00049         }
00050 
00051 protected:
00052         ACE_Reactor *m_pReactor;
00053 };
00054 
00055 
00056 
00057 #endif // REACTOR_THREAD_H
00058 

Generated on Wed Sep 5 12:54:24 2007 for DSACSS Operational Code by  doxygen 1.3.9.1