Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

OS_Errno.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_Errno.h
00006  *
00007  *  $Id: OS_Errno.h,v 1.1.1.2 2003/02/21 18:36:32 chad Exp $
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/OS_Export.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #if defined (ACE_HAS_H_ERRNO)
00024 void herror (const char *str);
00025 #endif /* ACE_HAS_H_ERRNO */
00026 
00027 #if !defined (ACE_HAS_WINCE)
00028 # include /**/ <errno.h>
00029 #endif /* ACE_HAS_WINCE */
00030 
00031 #if !defined (ACE_WIN32) && !defined (ACE_PSOS) && defined (ACE_LACKS_T_ERRNO)
00032 extern int t_errno;
00033 #endif /* ACE_WIN32 && !ACE_PSOS && ACE_LACKS_T_ERRNO */
00034 
00035 #if !defined (ENOSYS)
00036 # define ENOSYS EFAULT /* Operation not supported or unknown error. */
00037 #endif /* !ENOSYS */
00038 
00039 #if !defined (ENOTSUP)
00040 # define ENOTSUP ENOSYS  /* Operation not supported. */
00041 #endif /* !ENOTSUP */
00042 
00043 #if defined (ACE_HAS_WINCE_BROKEN_ERRNO)
00044 /**
00045  * @class ACE_CE_Errno
00046  *
00047  * Some versions of CE don't support <errno> and some versions'
00048  * implementations are busted.  So we implement our own.
00049  * Our implementation takes up one Tls key, however, it does not
00050  * allocate memory fromt the heap so there's no problem with cleanin
00051  * up the errno when a thread exit.
00052  */
00053 class ACE_OS_Export ACE_CE_Errno
00054 {
00055 public:
00056   ACE_CE_Errno () {}
00057   static void init ();
00058   static void fini ();
00059   static ACE_CE_Errno *instance ();
00060 
00061   operator int (void) const;
00062   int operator= (int);
00063 
00064 private:
00065   static ACE_CE_Errno *instance_;
00066   static DWORD errno_key_;
00067 };
00068 
00069 # define errno (* (ACE_CE_Errno::instance ()))
00070 #endif /* ACE_HAS_WINCE_BROKEN_ERRNO */
00071 
00072 #if defined (ACE_HAS_WINCE_BROKEN_ERRNO)
00073 #  define ACE_ERRNO_TYPE ACE_CE_Errno
00074 #else
00075 #  define ACE_ERRNO_TYPE int
00076 #endif /* ACE_HAS_WINCE */
00077 
00078 /**
00079  * @class ACE_Errno_Guard
00080  *
00081  * @brief Provides a wrapper to improve performance when thread-specific
00082  * errno must be saved and restored in a block of code.
00083  *
00084  * The typical use-case for this is the following:
00085  * int error = errno;
00086  * call_some_function_that_might_change_errno ();
00087  * errno = error;
00088  * This can be replaced with
00089  * {
00090  * ACE_Errno_Guard guard (errno);
00091  * call_some_function_that_might_change_errno ();
00092  * }
00093  * This implementation is more elegant and more efficient since it
00094  * avoids an unnecessary second access to thread-specific storage
00095  * by caching a pointer to the value of errno in TSS.
00096  */
00097 class ACE_OS_Export ACE_Errno_Guard
00098 {
00099 public:
00100   ///  Stash the value of <error> into <error_> and initialize the
00101   ///  <errno_ptr_> to the address of <errno_ref>.
00102   ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref,
00103                    int error);
00104 
00105   ///  Stash the value of <errno> into <error_> and initialize the
00106   ///  <errno_ptr_> to the address of <errno_ref>.
00107   ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref);
00108 
00109   /// Reset the value of <errno> to <error>.
00110   ~ACE_Errno_Guard (void);
00111 
00112 #if defined (ACE_HAS_WINCE_BROKEN_ERRNO)
00113   /// Assign <errno_ref> to <error_>.
00114   int operator= (const ACE_ERRNO_TYPE &errno_ref);
00115 #endif /* ACE_HAS_WINCE_BROKEN_ERRNO */
00116 
00117   /// Assign <error> to <error_>.
00118   int operator= (int error);
00119 
00120   /// Compare <error> with <error_> for equality.
00121   int operator== (int error);
00122 
00123   /// Compare <error> with <error_> for inequality.
00124   int operator!= (int error);
00125 
00126 private:
00127 #if defined (ACE_MT_SAFE)
00128   ACE_ERRNO_TYPE *errno_ptr_;
00129 #endif /* ACE_MT_SAFE */
00130   int error_;
00131 };
00132 
00133 #if defined (ACE_HAS_INLINED_OSCALLS)
00134 # if defined (ACE_INLINE)
00135 #  undef ACE_INLINE
00136 # endif /* ACE_INLINE */
00137 # define ACE_INLINE inline
00138 # include "ace/OS_Errno.inl"
00139 #endif /* ACE_HAS_INLINED_OSCALLS */
00140 
00141 #include "ace/post.h"
00142 #endif /* ACE_OS_ERRNO_H */

Generated on Mon Jun 16 11:20:44 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002