diff options
-rw-r--r-- | examples/Threads/thread_specific.cpp | 45 | ||||
-rw-r--r-- | examples/Threads/thread_specific.h | 50 | ||||
-rw-r--r-- | examples/Threads/tss1.cpp | 38 |
3 files changed, 53 insertions, 80 deletions
diff --git a/examples/Threads/thread_specific.cpp b/examples/Threads/thread_specific.cpp index 8baa46f6f8f..48b48bfec61 100644 --- a/examples/Threads/thread_specific.cpp +++ b/examples/Threads/thread_specific.cpp @@ -6,50 +6,7 @@ #if defined (ACE_HAS_THREADS) -// Define a class that will be stored in thread-specific data. Note -// that as far as this class is concerned it's just a regular C++ -// class. The ACE_TSS wrapper transparently ensures that objects of -// this class will be placed in thread-specific storage. All calls on -// ACE_TSS::operator->() are delegated to the appropriate method in -// the Errno class. - -class Errno -{ -public: - int error (void) { return this->errno_; } - void error (int i) { this->errno_ = i; } - - int line (void) { return this->lineno_; } - void line (int l) { this->lineno_ = l; } - - // Errno::flags_ is a static variable, so we've got to protect it - // with a mutex since it isn't kept in thread-specific storage. - int flags (void) - { - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Errno::lock_, -1); - - return Errno::flags_; - } - - void flags (int f) - { - ACE_GUARD (ACE_Thread_Mutex, ace_mon, Errno::lock_); - - Errno::flags_ = f; - } - -private: - // = errno_ and lineno_ will be thread-specific data so they don't - // need a lock. - int errno_; - int lineno_; - - static int flags_; -#if defined (ACE_HAS_THREADS) - // flags_ needs a lock. - static ACE_Thread_Mutex lock_; -#endif /* ACE_HAS_THREADS */ -}; +#include "thread_specific.h" // Static variables. ACE_MT (ACE_Thread_Mutex Errno::lock_); diff --git a/examples/Threads/thread_specific.h b/examples/Threads/thread_specific.h new file mode 100644 index 00000000000..bf031ee7aa9 --- /dev/null +++ b/examples/Threads/thread_specific.h @@ -0,0 +1,50 @@ +// $Id$ + +#ifndef ACE_THREAD_SPECIFIC_H + +// Define a class that will be stored in thread-specific data. Note +// that as far as this class is concerned it's just a regular C++ +// class. The ACE_TSS wrapper transparently ensures that objects of +// this class will be placed in thread-specific storage. All calls on +// ACE_TSS::operator->() are delegated to the appropriate method in +// the Errno class. + +class Errno +{ +public: + int error (void) { return this->errno_; } + void error (int i) { this->errno_ = i; } + + int line (void) { return this->lineno_; } + void line (int l) { this->lineno_ = l; } + + // Errno::flags_ is a static variable, so we've got to protect it + // with a mutex since it isn't kept in thread-specific storage. + int flags (void) + { + ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Errno::lock_, -1); + + return Errno::flags_; + } + + void flags (int f) + { + ACE_GUARD (ACE_Thread_Mutex, ace_mon, Errno::lock_); + + Errno::flags_ = f; + } + +private: + // = errno_ and lineno_ will be thread-specific data so they don't + // need a lock. + int errno_; + int lineno_; + + static int flags_; +#if defined (ACE_HAS_THREADS) + // flags_ needs a lock. + static ACE_Thread_Mutex lock_; +#endif /* ACE_HAS_THREADS */ +}; + +#endif /* ACE_THREAD_SPECIFIC_H */ diff --git a/examples/Threads/tss1.cpp b/examples/Threads/tss1.cpp index cc3c863d1a3..1d0a76c788d 100644 --- a/examples/Threads/tss1.cpp +++ b/examples/Threads/tss1.cpp @@ -27,45 +27,11 @@ #if defined (ACE_HAS_THREADS) +#include "thread_specific.h" + // (Sun C++ 4.2 with -O3 won't link if the following is not const.) static const int iterations = 100; -class Errno -{ -public: - int error (void) { return this->errno_; } - void error (int i) { this->errno_ = i; } - - int line (void) { return this->lineno_; } - void line (int l) { this->lineno_ = l; } - - // Errno::flags_ is a static variable, so we've got to protect it - // with a mutex since it isn't kept in thread-specific storage. - int flags (void) { - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_Mon, Errno::lock_, -1)); - - return Errno::flags_; - } - int flags (int f) - { - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Errno::lock_, -1)); - - Errno::flags_ = f; - return 0; - } - -private: - // = errno_ and lineno_ will be thread-specific data so they don't - // need a lock. - int errno_; - int lineno_; - - static int flags_; -#if defined (ACE_HAS_THREADS) - // flags_ needs a lock. - static ACE_Thread_Mutex lock_; -#endif /* ACE_HAS_THREADS */ -}; // Static variables. ACE_MT (ACE_Thread_Mutex Errno::lock_); |