ACE_Reactor_Token_T< ACE_TOKEN_TYPE > Class Template Reference

Used as a synchronization mechanism to coordinate concurrent access to an ACE_Reactor_Impl object. More...

#include <Reactor_Token_T.h>

Collaboration diagram for ACE_Reactor_Token_T< ACE_TOKEN_TYPE >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Reactor_Token_T (ACE_Reactor_Impl &r, int s_queue=ACE_TOKEN_TYPE::FIFO)
 ACE_Reactor_Token_T (int s_queue=ACE_TOKEN_TYPE::FIFO)
virtual ~ACE_Reactor_Token_T (void)
virtual void sleep_hook (void)
ACE_Reactor_Implreactor (void)
 Get the reactor implementation.

void reactor (ACE_Reactor_Impl &)
 Set the reactor implementation.

virtual void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Attributes

ACE_Reactor_Implreactor_

Detailed Description

template<class ACE_TOKEN_TYPE>
class ACE_Reactor_Token_T< ACE_TOKEN_TYPE >

Used as a synchronization mechanism to coordinate concurrent access to an ACE_Reactor_Impl object.

For internal use only.

For ACE internal use only.

This class is used to make access to a reactor's internals and demultiplexing mechanism thread-safe. By default, the thread that runs the handle_events() loop holds the token, even when it is blocked in the demultiplexer. Whenever another thread wants to access the reactor, such as via the register_handler(), remove_handler(), etc. methods, it must ask the token owner for temporary release of the token. To accomplish this, this class reimplements the ACE_Token::sleep_hook() method through which the owning thread can be notified to temporarily release the token if the current situation permits.

The owner of the token is responsible for deciding which request for the token can be granted. By using the ACE_Token::renew() method, the thread that releases the token temporarily can specify to get the token back right after the other thread has completed using the token. Thus, there is a dedicated thread that owns the token by default. This thread grants other threads access to the token by ensuring that whenever somebody else has finished using the token the original owner reclaims the token again, i.e., the owner has the chance to schedule other threads. The thread that most likely needs the token most of the time is the thread running the dispatch loop.

Definition at line 54 of file Reactor_Token_T.h.


Constructor & Destructor Documentation

template<class ACE_TOKEN_TYPE>
ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::ACE_Reactor_Token_T ACE_Reactor_Impl r,
int  s_queue = ACE_TOKEN_TYPE::FIFO
 

Definition at line 22 of file Reactor_Token_T.cpp.

References ACE_TRACE.

00024     : reactor_ (&r)
00025 {
00026   ACE_TRACE ("ACE_Reactor_Token_T::ACE_Reactor_Token");
00027 
00028   this->queueing_strategy (s_queue);
00029 }

template<class ACE_TOKEN_TYPE>
ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::ACE_Reactor_Token_T int  s_queue = ACE_TOKEN_TYPE::FIFO  ) 
 

Definition at line 32 of file Reactor_Token_T.cpp.

References ACE_TRACE.

00033   : reactor_ (0)
00034 {
00035   ACE_TRACE ("ACE_Reactor_Token_T::ACE_Reactor_Token");
00036 
00037   this->queueing_strategy (s_queue);
00038 }

template<class ACE_TOKEN_TYPE>
ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::~ACE_Reactor_Token_T void   )  [virtual]
 

Definition at line 41 of file Reactor_Token_T.cpp.

References ACE_TRACE.

00042 {
00043   ACE_TRACE ("ACE_Reactor_Token_T::~ACE_Reactor_Token_T");
00044 }


Member Function Documentation

template<class ACE_TOKEN_TYPE>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::dump void   )  const [virtual]
 

Dump the state of an object.

Definition at line 9 of file Reactor_Token_T.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00010 {
00011 #if defined (ACE_HAS_DUMP)
00012   ACE_TRACE ("ACE_Reactor_Token_T::dump");
00013 
00014   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00015   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00016   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00017 #endif /* ACE_HAS_DUMP */
00018 }

template<class ACE_TOKEN_TYPE>
void ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::reactor ACE_Reactor_Impl  ) 
 

Set the reactor implementation.

Definition at line 53 of file Reactor_Token_T.cpp.

00054 {
00055   this->reactor_ = &reactor;
00056 }

template<class ACE_TOKEN_TYPE>
ACE_Reactor_Impl & ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::reactor void   ) 
 

Get the reactor implementation.

Definition at line 47 of file Reactor_Token_T.cpp.

00048 {
00049   return *this->reactor_;
00050 }

template<class ACE_TOKEN_TYPE>
void ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::sleep_hook void   )  [virtual]
 

Called just before a token waiter goes to sleep.

See also:
ACE_Token::sleep_hook

Definition at line 61 of file Reactor_Token_T.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and ACE_Reactor_Impl::notify().

00062 {
00063   ACE_TRACE ("ACE_Reactor_Token_T::sleep_hook");
00064   if (this->reactor_->notify () == -1)
00065     ACE_ERROR ((LM_ERROR,
00066                 ACE_LIB_TEXT ("%p\n"),
00067                 ACE_LIB_TEXT ("sleep_hook failed")));
00068 }


Member Data Documentation

template<class ACE_TOKEN_TYPE>
ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 76 of file Reactor_Token_T.h.

template<class ACE_TOKEN_TYPE>
ACE_Reactor_Impl* ACE_Reactor_Token_T< ACE_TOKEN_TYPE >::reactor_ [private]
 

Definition at line 79 of file Reactor_Token_T.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:27:47 2006 for ACE by doxygen 1.3.6