Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Threads / thread_specific.h
blobd5adaca83702807f3eeba637021d123d1dde3e76
1 #ifndef ACE_THREAD_SPECIFIC_H
3 #include "ace/Guard_T.h"
4 #include "ace/Thread_Mutex.h"
6 // Define a class that will be stored in thread-specific data. Note
7 // that as far as this class is concerned it's just a regular C++
8 // class. The ACE_TSS wrapper transparently ensures that objects of
9 // this class will be placed in thread-specific storage. All calls on
10 // ACE_TSS::operator->() are delegated to the appropriate method in
11 // the Errno class.
13 class Errno
15 public:
16 int error () { return this->errno_; }
17 void error (int i) { this->errno_ = i; }
19 int line () { return this->lineno_; }
20 void line (int l) { this->lineno_ = l; }
22 // Errno::flags_ is a static variable, so we've got to protect it
23 // with a mutex since it isn't kept in thread-specific storage.
24 int flags ()
26 ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Errno::lock_, -1);
28 return Errno::flags_;
31 void flags (int f)
33 ACE_GUARD (ACE_Thread_Mutex, ace_mon, Errno::lock_);
35 Errno::flags_ = f;
38 private:
39 // = errno_ and lineno_ will be thread-specific data so they don't
40 // need a lock.
41 int errno_;
42 int lineno_;
44 static int flags_;
45 #if defined (ACE_HAS_THREADS)
46 // flags_ needs a lock.
47 static ACE_Thread_Mutex lock_;
48 #endif /* ACE_HAS_THREADS */
51 #endif /* ACE_THREAD_SPECIFIC_H */