00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file OS_Errno.h 00006 * 00007 * $Id: OS_Errno.h 80826 2008-03-04 14:51:23Z wotte $ 00008 * 00009 * @author (Originally in OS.h)Doug Schmidt <schmidt@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_OS_ERRNO_H 00014 #define ACE_OS_ERRNO_H 00015 #include /**/ "ace/pre.h" 00016 00017 #include /**/ "ace/ACE_export.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #include "ace/OS_NS_errno.h" 00024 00025 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00026 00027 /** 00028 * @class ACE_Errno_Guard 00029 * 00030 * @brief Provides a wrapper to improve performance when thread-specific 00031 * errno must be saved and restored in a block of code. 00032 * 00033 * The typical use-case for this is the following: 00034 * int error = errno; 00035 * call_some_function_that_might_change_errno (); 00036 * errno = error; 00037 * This can be replaced with 00038 * { 00039 * ACE_Errno_Guard guard (errno); 00040 * call_some_function_that_might_change_errno (); 00041 * } 00042 * This implementation is more elegant and more efficient since it 00043 * avoids an unnecessary second access to thread-specific storage 00044 * by caching a pointer to the value of errno in TSS. 00045 */ 00046 class ACE_Export ACE_Errno_Guard 00047 { 00048 public: 00049 /// Stash the value of <error> into <error_> and initialize the 00050 /// <errno_ptr_> to the address of <errno_ref>. 00051 ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref, 00052 int error); 00053 00054 /// Stash the value of @c errno into <error_> and initialize the 00055 /// <errno_ptr_> to the address of <errno_ref>. 00056 ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref); 00057 00058 /// Reset the value of @c errno to <error>. 00059 ~ACE_Errno_Guard (void); 00060 00061 #if defined (ACE_HAS_WINCE_BROKEN_ERRNO) 00062 /// Assign <errno_ref> to <error_>. 00063 int operator= (const ACE_ERRNO_TYPE &errno_ref); 00064 #endif /* ACE_HAS_WINCE_BROKEN_ERRNO */ 00065 00066 /// Assign <error> to <error_>. 00067 int operator= (int error); 00068 00069 /// Compare <error> with <error_> for equality. 00070 bool operator== (int error); 00071 00072 /// Compare <error> with <error_> for inequality. 00073 bool operator!= (int error); 00074 00075 private: 00076 // Prevent copying 00077 ACE_Errno_Guard (const ACE_Errno_Guard &); 00078 ACE_Errno_Guard &operator= (const ACE_Errno_Guard &); 00079 00080 #if defined (ACE_MT_SAFE) 00081 ACE_ERRNO_TYPE *errno_ptr_; 00082 #endif /* ACE_MT_SAFE */ 00083 int error_; 00084 }; 00085 00086 ACE_END_VERSIONED_NAMESPACE_DECL 00087 00088 // Inlining this class on debug builds with gcc on Solaris can cause 00089 // deadlocks during static initialization. On non debug builds it 00090 // causes compilation errors. 00091 #if defined (ACE_HAS_INLINED_OSCALLS) && \ 00092 (!defined (__GNUG__) || !defined (__sun__)) 00093 # if defined (ACE_INLINE) 00094 # undef ACE_INLINE 00095 # endif /* ACE_INLINE */ 00096 # define ACE_INLINE inline 00097 # include "ace/OS_Errno.inl" 00098 #endif /* ACE_HAS_INLINED_OSCALLS */ 00099 00100 #include /**/ "ace/post.h" 00101 #endif /* ACE_OS_ERRNO_H */