ACE_Thread_Exit Class Reference

Keep exit information for a Thread in thread specific storage. so that the thread-specific exit hooks will get called no matter how the thread exits (e.g., via <ACE_Thread::exit>, C++ or Win32 exception, "falling off the end" of the thread entry point function, etc.). More...

#include <Thread_Exit.h>

Collaboration diagram for ACE_Thread_Exit:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Thread_Exit (void)
 Capture the Thread that will be cleaned up automatically.

void thr_mgr (ACE_Thread_Manager *tm)
 Set the .

 ~ACE_Thread_Exit (void)

Static Public Member Functions

ACE_Thread_Exitinstance (void)
 Singleton access point.

void cleanup (void *instance)

Private Attributes

ACE_Thread_Control thread_control_

Static Private Attributes

unsigned int is_constructed_ = 0

Detailed Description

Keep exit information for a Thread in thread specific storage. so that the thread-specific exit hooks will get called no matter how the thread exits (e.g., via <ACE_Thread::exit>, C++ or Win32 exception, "falling off the end" of the thread entry point function, etc.).

This clever little helper class is stored in thread-specific storage using the wrapper. When a thread exits the <ACE_TSS::cleanup> function deletes this object, thereby closing it down gracefully.

Definition at line 42 of file Thread_Exit.h.


Constructor & Destructor Documentation

ACE_Thread_Exit::ACE_Thread_Exit void   ) 
 

Capture the Thread that will be cleaned up automatically.

Definition at line 73 of file Thread_Exit.cpp.

References ACE_OS_TRACE.

00074 {
00075   ACE_OS_TRACE ("ACE_Thread_Exit::ACE_Thread_Exit");
00076 }

ACE_Thread_Exit::~ACE_Thread_Exit void   ) 
 

Destructor calls the thread-specific exit hooks when a thread exits.

Definition at line 92 of file Thread_Exit.cpp.

References ACE_OS_TRACE.

00093 {
00094   ACE_OS_TRACE ("ACE_Thread_Exit::~ACE_Thread_Exit");
00095 }


Member Function Documentation

void ACE_Thread_Exit::cleanup void *  instance  )  [static]
 

Cleanup method, used by the to destroy the singleton.

Definition at line 15 of file Thread_Exit.cpp.

References ACE_OS_TRACE, ACE_TSS_TYPE, and is_constructed_.

Referenced by ACE_Thread_Manager::close_singleton().

00016 {
00017   ACE_OS_TRACE ("ACE_Thread_Exit::cleanup");
00018 
00019   delete (ACE_TSS_TYPE (ACE_Thread_Exit) *) instance;
00020 
00021   // Set the thr_exit_ static to null to keep things from crashing if
00022   // ACE::fini() is enabled here.
00023   ACE_Thread_Manager::thr_exit_ = 0;
00024 
00025   ACE_Thread_Exit::is_constructed_ = 0;
00026   // All TSS objects have been destroyed.  Reset this flag so
00027   // ACE_Thread_Exit singleton can be created again.
00028 }

ACE_Thread_Exit * ACE_Thread_Exit::instance void   )  [static]
 

Singleton access point.

Definition at line 35 of file Thread_Exit.cpp.

References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_OS_TRACE, ACE_TSS_GET, ACE_TSS_TYPE, is_constructed_, and ACE_Thread_Manager::set_thr_exit().

Referenced by ACE_Thread_Manager::exit(), and ACE_Thread_Adapter::invoke().

00036 {
00037 #if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)
00038   ACE_OS_TRACE ("ACE_Thread_Exit::instance");
00039 
00040   // Determines if we were dynamically allocated.
00041   static ACE_TSS_TYPE (ACE_Thread_Exit) *instance_;
00042 
00043   // Implement the Double Check pattern.
00044 
00045   if (ACE_Thread_Exit::is_constructed_ == 0)
00046     {
00047       ACE_MT (ACE_Thread_Mutex *lock =
00048               ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object
00049                 (ACE_Object_Manager::ACE_THREAD_EXIT_LOCK);
00050               ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, *lock, 0));
00051 
00052       if (ACE_Thread_Exit::is_constructed_ == 0)
00053         {
00054           ACE_NEW_RETURN (instance_,
00055                           ACE_TSS_TYPE (ACE_Thread_Exit),
00056                           0);
00057 
00058           ACE_Thread_Exit::is_constructed_ = 1;
00059 
00060           ACE_Thread_Manager::set_thr_exit (instance_);
00061         }
00062     }
00063 
00064   return ACE_TSS_GET (instance_, ACE_Thread_Exit);
00065 #else
00066   return 0;
00067 #endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */
00068 }

void ACE_Thread_Exit::thr_mgr ACE_Thread_Manager tm  ) 
 

Set the .

Definition at line 81 of file Thread_Exit.cpp.

References ACE_OS_TRACE, ACE_Thread_Control::insert(), and thread_control_.

Referenced by ACE_Thread_Adapter::invoke().

00082 {
00083   ACE_OS_TRACE ("ACE_Thread_Exit::thr_mgr");
00084 
00085   if (tm != 0)
00086     this->thread_control_.insert (tm, 0);
00087 }


Member Data Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL u_int ACE_Thread_Exit::is_constructed_ = 0 [static, private]
 

Used to detect whether we should create a new instance (or not) within the instance method -- we don't trust the instance_ ptr because the destructor may have run (if ACE::fini() was called). See bug #526. We don't follow the singleton pattern due to dependency issues.

Definition at line 12 of file Thread_Exit.cpp.

Referenced by cleanup(), and instance().

ACE_Thread_Control ACE_Thread_Exit::thread_control_ [private]
 

Automatically add/remove the thread from the .

Definition at line 65 of file Thread_Exit.h.

Referenced by thr_mgr().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:30:55 2006 for ACE by doxygen 1.3.6