Public Member Functions | Private Member Functions | Private Attributes

ACE_Errno_Guard Class Reference

Provides a wrapper to improve performance when thread-specific errno must be saved and restored in a block of code. More...

#include <OS_Errno.h>

List of all members.

Public Member Functions

 ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref, int error)
 ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref)
 Initialize the errno_ptr_ to the address of errno_ref.
 ~ACE_Errno_Guard (void)
 Reset the value of errno to <error>.
int operator= (int error)
 Assign <error> to <error_>.
bool operator== (int error)
 Compare <error> with <error_> for equality.
bool operator!= (int error)
 Compare <error> with <error_> for inequality.

Private Member Functions

 ACE_Errno_Guard (const ACE_Errno_Guard &)
ACE_Errno_Guardoperator= (const ACE_Errno_Guard &)

Private Attributes

int error_

Detailed Description

Provides a wrapper to improve performance when thread-specific errno must be saved and restored in a block of code.

The typical use-case for this is the following: int error = errno; call_some_function_that_might_change_errno (); errno = error; This can be replaced with { ACE_Errno_Guard guard (errno); call_some_function_that_might_change_errno (); } This implementation is more elegant and more efficient since it avoids an unnecessary second access to thread-specific storage by caching a pointer to the value of errno in TSS.

Definition at line 46 of file OS_Errno.h.


Constructor & Destructor Documentation

ACE_Errno_Guard::ACE_Errno_Guard ( ACE_ERRNO_TYPE &  errno_ref,
int  error 
)

Stash the value of error into error_ and initialize the errno_ptr_ to the address of errno_ref.

Definition at line 8 of file OS_Errno.inl.

  :
#if defined (ACE_MT_SAFE)
    errno_ptr_ (&errno_ref),
#endif /* ACE_MT_SAFE */
    error_ (error)
{
#if !defined(ACE_MT_SAFE)
  ACE_UNUSED_ARG (errno_ref);
#endif /* ACE_MT_SAFE */
}

ACE_Errno_Guard::ACE_Errno_Guard ( ACE_ERRNO_TYPE &  errno_ref  ) 

Initialize the errno_ptr_ to the address of errno_ref.

Definition at line 22 of file OS_Errno.inl.

  :
#if defined (ACE_MT_SAFE)
    errno_ptr_ (&errno_ref),
#endif /* ACE_MT_SAFE */
    error_ (errno_ref)
{
}

ACE_Errno_Guard::~ACE_Errno_Guard ( void   ) 

Reset the value of errno to <error>.

Definition at line 32 of file OS_Errno.inl.

{
#if defined (ACE_MT_SAFE)
  *errno_ptr_ = this->error_;
#else
  errno = this->error_;
#endif /* ACE_MT_SAFE */
}

ACE_Errno_Guard::ACE_Errno_Guard ( const ACE_Errno_Guard  )  [private]

Member Function Documentation

bool ACE_Errno_Guard::operator!= ( int  error  ) 

Compare <error> with <error_> for inequality.

Definition at line 62 of file OS_Errno.inl.

{
  return this->error_ != error;
}

ACE_Errno_Guard& ACE_Errno_Guard::operator= ( const ACE_Errno_Guard  )  [private]
int ACE_Errno_Guard::operator= ( int  error  ) 

Assign <error> to <error_>.

Definition at line 50 of file OS_Errno.inl.

{
  return this->error_ = error;
}

bool ACE_Errno_Guard::operator== ( int  error  ) 

Compare <error> with <error_> for equality.

Definition at line 56 of file OS_Errno.inl.

{
  return this->error_ == error;
}


Member Data Documentation

int ACE_Errno_Guard::error_ [private]

Definition at line 82 of file OS_Errno.h.


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