ACE_Dev_Poll_Reactor::Token_Guard Class Reference

A helper class that helps grabbing, releasing and waiting on tokens for a thread that needs access to the reactor's token. More...

#include <Dev_Poll_Reactor.h>

Collaboration diagram for ACE_Dev_Poll_Reactor::Token_Guard:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Token_Guard (ACE_Dev_Poll_Reactor_Token &token)
 Constructor that will grab the token for us.

 ~Token_Guard (void)
void release_token (void)
 Release the token ..

int is_owner (void)
int acquire_quietly (ACE_Time_Value *max_wait=0)
int acquire (ACE_Time_Value *max_wait=0)

Private Member Functions

 Token_Guard (void)

Private Attributes

ACE_Dev_Poll_Reactor_Tokentoken_
 The Reactor token.

int owner_

Detailed Description

A helper class that helps grabbing, releasing and waiting on tokens for a thread that needs access to the reactor's token.

Definition at line 1174 of file Dev_Poll_Reactor.h.


Constructor & Destructor Documentation

ACE_INLINE ACE_Dev_Poll_Reactor::Token_Guard::Token_Guard ACE_Dev_Poll_Reactor_Token token  ) 
 

Constructor that will grab the token for us.

Definition at line 193 of file Dev_Poll_Reactor.inl.

References ACE_Dev_Poll_Reactor_Token.

00195   : token_ (token),
00196     owner_ (0)
00197 {
00198 }

ACE_INLINE ACE_Dev_Poll_Reactor::Token_Guard::~Token_Guard void   ) 
 

Destructor. This will release the token if it hasn't been released till this point

Definition at line 201 of file Dev_Poll_Reactor.inl.

References owner_.

00202 {
00203   if (this->owner_ == 1)
00204     {
00205       ACE_MT (this->token_.release ());
00206       this->owner_ = 0;
00207     }
00208 }

ACE_Dev_Poll_Reactor::Token_Guard::Token_Guard void   )  [private]
 


Member Function Documentation

int ACE_Dev_Poll_Reactor::Token_Guard::acquire ACE_Time_Value max_wait = 0  ) 
 

A helper method that acquires the token at a high priority, and does wake the current token holder.

Definition at line 2613 of file Dev_Poll_Reactor.cpp.

References ACE_TRACE, ETIME, ACE_OS::gettimeofday(), and owner_.

02614 {
02615   ACE_TRACE ("ACE_Dev_Poll_Reactor::Token_Guard::acquire");
02616 
02617   // Try to grab the token.  If someone if already there, don't wake
02618   // them up, just queue up in the thread pool.
02619   int result = 0;
02620   if (max_wait)
02621     {
02622       ACE_Time_Value tv = ACE_OS::gettimeofday ();
02623       tv += *max_wait;
02624 
02625       ACE_MT (result = this->token_.acquire (0, 0, &tv));
02626     }
02627   else
02628     {
02629       ACE_MT (result = this->token_.acquire ());
02630     }
02631 
02632   // Check for timeouts and errors.
02633   if (result == -1)
02634     {
02635       if (errno == ETIME)
02636         return 0;
02637       else
02638         return -1;
02639     }
02640 
02641   // We got the token and so let us mark ourseleves as owner
02642   this->owner_ = 1;
02643 
02644   return result;
02645 }

int ACE_Dev_Poll_Reactor::Token_Guard::acquire_quietly ACE_Time_Value max_wait = 0  ) 
 

A helper method that acquires the token 1) at a low priority, and 2) wait quietly for the token, not waking another thread. This is appropriate for cases where a thread wants to wait for and dispatch an event, not causing an existing waiter to relinquish the token, and also queueing up behind other threads waiting to modify event records.

Definition at line 2574 of file Dev_Poll_Reactor.cpp.

References ACE_ERROR, ACE_TRACE, ETIME, ACE_OS::gettimeofday(), LM_ERROR, owner_, and polite_sleep_hook().

Referenced by ACE_Dev_Poll_Reactor::handle_events(), and ACE_Dev_Poll_Reactor::work_pending().

02575 {
02576   ACE_TRACE ("ACE_Dev_Poll_Reactor::Token_Guard::acquire_quietly");
02577 
02578   // Acquire the token but don't ping any waiters; just queue up politely.
02579   int result = 0;
02580   if (max_wait)
02581     {
02582       ACE_Time_Value tv = ACE_OS::gettimeofday ();
02583       tv += *max_wait;
02584 
02585       ACE_MT (result = this->token_.acquire_read (&polite_sleep_hook,
02586                                                   0,
02587                                                   &tv));
02588     }
02589   else
02590     {
02591       ACE_MT (result = this->token_.acquire_read (&polite_sleep_hook));
02592     }
02593 
02594   // Check for timeouts and errors.
02595   if (result == -1)
02596     {
02597       if (errno == ETIME)
02598         return 0;
02599       else
02600         {
02601           ACE_ERROR ((LM_ERROR, "%t: %p\n", "token acquire_read"));
02602           return -1;
02603         }
02604     }
02605 
02606   // We got the token and so let us mark ourselves as owner
02607   this->owner_ = 1;
02608 
02609   return result;
02610 }

ACE_INLINE int ACE_Dev_Poll_Reactor::Token_Guard::is_owner void   ) 
 

Returns whether the thread that created this object owns the token or not.

Definition at line 223 of file Dev_Poll_Reactor.inl.

References owner_.

Referenced by ACE_Dev_Poll_Reactor::handle_events(), and ACE_Dev_Poll_Reactor::work_pending().

00224 {
00225   return this->owner_;
00226 }

ACE_INLINE void ACE_Dev_Poll_Reactor::Token_Guard::release_token void   ) 
 

Release the token ..

Definition at line 211 of file Dev_Poll_Reactor.inl.

References owner_.

Referenced by ACE_Dev_Poll_Reactor::dispatch_io_event(), and ACE_Dev_Poll_Reactor::dispatch_timer_handler().

00212 {
00213   if (this->owner_)
00214     {
00215       ACE_MT (this->token_.release ());
00216 
00217       // We are not the owner anymore..
00218       this->owner_ = 0;
00219     }
00220 }


Member Data Documentation

int ACE_Dev_Poll_Reactor::Token_Guard::owner_ [private]
 

Flag that indicate whether the thread that created this object owns the token or not. A value of 0 indicates that this class hasn't got the token (and hence the thread) and a value of 1 vice-versa.

Definition at line 1217 of file Dev_Poll_Reactor.h.

Referenced by acquire(), acquire_quietly(), is_owner(), release_token(), and ~Token_Guard().

ACE_Dev_Poll_Reactor_Token& ACE_Dev_Poll_Reactor::Token_Guard::token_ [private]
 

The Reactor token.

Definition at line 1211 of file Dev_Poll_Reactor.h.


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