3 //=============================================================================
7 * @author (Originally in OS.h)Doug Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
11 #ifndef ACE_OS_ERRNO_H
12 #define ACE_OS_ERRNO_H
13 #include /**/ "ace/pre.h"
15 #include /**/ "ace/ACE_export.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ace/OS_NS_errno.h"
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 * @class ACE_Errno_Guard
28 * @brief Provides a wrapper to improve performance when thread-specific
29 * errno must be saved and restored in a block of code.
31 * The typical use-case for this is the following:
33 * call_some_function_that_might_change_errno ();
35 * This can be replaced with
37 * ACE_Errno_Guard guard (errno);
38 * call_some_function_that_might_change_errno ();
40 * This implementation is more elegant and more efficient since it
41 * avoids an unnecessary second access to thread-specific storage
42 * by caching a pointer to the value of errno in TSS.
44 class ACE_Export ACE_Errno_Guard
47 /// Stash the value of @a error into @c error_ and initialize the
48 /// @c errno_ptr_ to the address of @a errno_ref.
49 ACE_Errno_Guard (ACE_ERRNO_TYPE
&errno_ref
,
52 /// Initialize the @c errno_ptr_ to the address of @a errno_ref.
53 ACE_Errno_Guard (ACE_ERRNO_TYPE
&errno_ref
);
55 /// Reset the value of @c errno to <error>.
56 ~ACE_Errno_Guard (void);
58 #if defined (ACE_HAS_WINCE_BROKEN_ERRNO)
59 /// Assign @a errno_ref to <error_>.
60 int operator= (const ACE_ERRNO_TYPE
&errno_ref
);
61 #endif /* ACE_HAS_WINCE_BROKEN_ERRNO */
63 /// Assign <error> to <error_>.
64 int operator= (int error
);
66 /// Compare <error> with <error_> for equality.
67 bool operator== (int error
);
69 /// Compare <error> with <error_> for inequality.
70 bool operator!= (int error
);
74 ACE_Errno_Guard (const ACE_Errno_Guard
&);
75 ACE_Errno_Guard
&operator= (const ACE_Errno_Guard
&);
77 #if defined (ACE_MT_SAFE)
78 ACE_ERRNO_TYPE
*errno_ptr_
;
79 #endif /* ACE_MT_SAFE */
83 ACE_END_VERSIONED_NAMESPACE_DECL
85 // Inlining this class on debug builds with gcc on Solaris can cause
86 // deadlocks during static initialization. On non debug builds it
87 // causes compilation errors.
88 #if defined (ACE_HAS_INLINED_OSCALLS) && \
89 (!defined (__GNUG__) || !defined (__sun__))
90 # if defined (ACE_INLINE)
92 # endif /* ACE_INLINE */
93 # define ACE_INLINE inline
94 # include "ace/OS_Errno.inl"
95 #endif /* ACE_HAS_INLINED_OSCALLS */
97 #include /**/ "ace/post.h"
98 #endif /* ACE_OS_ERRNO_H */