Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / TSS_Test_Errno.h
blob2964351b743b654b0aa48f5d2e7741284d4d6213
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file TSS_Test_Errno.h
7 * This file contains the definition of Errno. Some compilers need
8 * it in a .h file for template instantiation (such as AIX C Set
9 * ++).
11 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
13 //=============================================================================
16 #include "ace/Guard_T.h"
17 #include "ace/Thread_Mutex.h"
19 /**
20 * @class Errno
22 * @brief Define a simple Errno abstraction
24 * This class gets its own header file to work around AIX C++
25 * compiler "features" related to template instantiation... It is
26 * only used by TSS_Test.cpp.
28 class Errno
30 public:
31 Errno()
33 ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_Mon, *Errno::lock_));
34 created_ += 1;
36 ~Errno()
38 ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_Mon, *Errno::lock_));
39 deleted_ += 1;
42 int error (void) { return this->errno_; }
43 void error (int i) { this->errno_ = i; }
45 int line (void) { return this->lineno_; }
46 void line (int l) { this->lineno_ = l; }
48 // Errno::flags_ is a static variable, so we've got to protect it
49 // with a mutex since it isn't kept in thread-specific storage.
50 int flags (void)
52 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_Mon, *Errno::lock_, -1));
54 return Errno::flags_;
56 int flags (int f)
58 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, *Errno::lock_, -1));
60 Errno::flags_ = f;
61 return 0;
64 static int created (void)
66 return created_;
69 static int deleted (void)
71 return deleted_;
74 #if defined (ACE_HAS_THREADS)
75 static
76 ACE_Thread_Mutex *
77 allocate_lock (void)
79 ACE_NEW_RETURN (Errno::lock_, ACE_Thread_Mutex, 0);
80 return Errno::lock_;
83 static
84 void
85 deallocate_lock () { delete lock_; lock_ = 0; }
86 #endif /* ACE_HAS_THREADS */
88 private:
89 // = errno_ and lineno_ will be thread-specific data so they don't
90 // need a lock.
91 int errno_;
92 int lineno_;
94 static int flags_;
95 static int created_;
96 static int deleted_;
97 #if defined (ACE_HAS_THREADS)
98 // flags_ needs a lock.
99 static ACE_Thread_Mutex *lock_;
100 #endif /* ACE_HAS_THREADS */