Public Member Functions | Private Member Functions | Private Attributes

ACE_TP_Token_Guard Class Reference

A helper class that helps grabbing, releasing and waiting on tokens for a thread that tries calling handle_events (). More...

#include <TP_Reactor.h>

Collaboration diagram for ACE_TP_Token_Guard:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ACE_TP_Token_Guard (ACE_Select_Reactor_Token &token)
 Constructor that will grab the token for us.
 ~ACE_TP_Token_Guard (void)
void release_token (void)
 Release the token ..
bool is_owner (void)
int acquire_read_token (ACE_Time_Value *max_wait_time=0)
int acquire_token (ACE_Time_Value *max_wait_time=0)

Private Member Functions

 ACE_TP_Token_Guard (void)
 ACE_TP_Token_Guard (const ACE_TP_Token_Guard &)
ACE_TP_Token_Guardoperator= (const ACE_TP_Token_Guard &)

Private Attributes

ACE_Select_Reactor_Tokentoken_
 The Select Reactor token.
bool owner_

Detailed Description

A helper class that helps grabbing, releasing and waiting on tokens for a thread that tries calling handle_events ().

In short, this class will be owned by one thread by creating on the stack. This class gives the status of the ownership of the token and manages the ownership

Definition at line 88 of file TP_Reactor.h.


Constructor & Destructor Documentation

ACE_TP_Token_Guard::ACE_TP_Token_Guard ( ACE_Select_Reactor_Token token  ) 

Constructor that will grab the token for us.

Definition at line 57 of file TP_Reactor.inl.

  : token_ (token),
    owner_ (false)
{
}

ACE_TP_Token_Guard::~ACE_TP_Token_Guard ( void   ) 

Destructor. This will release the token if it hasnt been released till this point

Definition at line 65 of file TP_Reactor.inl.

{
  if (this->owner_)
    {
      ACE_MT (this->token_.release ());
      this->owner_ = false;
    }
}

ACE_TP_Token_Guard::ACE_TP_Token_Guard ( void   )  [private]
ACE_TP_Token_Guard::ACE_TP_Token_Guard ( const ACE_TP_Token_Guard  )  [private]

Member Function Documentation

int ACE_TP_Token_Guard::acquire_read_token ( ACE_Time_Value max_wait_time = 0  ) 

A helper method that grabs the token for us, after which the thread that owns that can do some actual work.

int ACE_TP_Token_Guard::acquire_token ( ACE_Time_Value max_wait_time = 0  ) 

A helper method that grabs the token for us, after which the thread that owns that can do some actual work. This differs from acquire_read_token() as it uses acquire () to get the token instead of acquire_read ()

Definition at line 63 of file TP_Reactor.cpp.

{
  ACE_TRACE ("ACE_TP_Token_Guard::acquire_token");

  // Try to grab the lock.  If someone if already there, don't wake
  // them up, just queue up in the thread pool.
  int result = 0;

  if (max_wait_time)
    {
      ACE_Time_Value tv = ACE_OS::gettimeofday ();
      tv += *max_wait_time;

      ACE_MT (result = this->token_.acquire (0,
                                             0,
                                             &tv));
    }
  else
    {
      ACE_MT (result = this->token_.acquire ());
    }

  // Check for timeouts and errors.
  if (result == -1)
    {
      if (errno == ETIME)
        return 0;
      else
        return -1;
    }

  // We got the token and so let us mark ourselves as owner
  this->owner_ = true;

  return result;
}

bool ACE_TP_Token_Guard::is_owner ( void   ) 

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

Definition at line 87 of file TP_Reactor.inl.

{
  return this->owner_;
}

ACE_TP_Token_Guard& ACE_TP_Token_Guard::operator= ( const ACE_TP_Token_Guard  )  [private]
void ACE_TP_Token_Guard::release_token ( void   ) 

Release the token ..

Definition at line 75 of file TP_Reactor.inl.

{
  if (this->owner_)
    {
      ACE_MT (this->token_.release ());

      // We are not the owner anymore..
      this->owner_ = false;
    }
}


Member Data Documentation

Flag that indicate whether the thread that created this object owns the token or not. A value of false indicates that this class hasnt got the token (and hence the thread) and a value of true vice-versa.

Definition at line 136 of file TP_Reactor.h.

The Select Reactor token.

Definition at line 130 of file TP_Reactor.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines