3 //=============================================================================
7 * @author 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>.
58 /// Assign @a erro> to error_.
59 int operator= (int error
);
61 /// Compare @a error with error_ for equality.
62 bool operator== (int error
);
64 /// Compare @a error with error_ for inequality.
65 bool operator!= (int error
);
68 ACE_Errno_Guard (const ACE_Errno_Guard
&) = delete;
69 ACE_Errno_Guard
&operator= (const ACE_Errno_Guard
&) = delete;
71 #if defined (ACE_MT_SAFE)
72 ACE_ERRNO_TYPE
*errno_ptr_
;
73 #endif /* ACE_MT_SAFE */
77 ACE_END_VERSIONED_NAMESPACE_DECL
79 // Inlining this class on debug builds with can cause
80 // deadlocks during static initialization. On non debug builds it
81 // causes compilation errors.
82 #if defined (ACE_HAS_INLINED_OSCALLS)
83 # if defined (ACE_INLINE)
85 # endif /* ACE_INLINE */
86 # define ACE_INLINE inline
87 # include "ace/OS_Errno.inl"
88 #endif /* ACE_HAS_INLINED_OSCALLS */
90 #include /**/ "ace/post.h"
91 #endif /* ACE_OS_ERRNO_H */