Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 Methods

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

void thr_mgr (ACE_Thread_Manager *tm)
 Set the <ACE_Thread_Manager>. More...

 ~ACE_Thread_Exit (void)
 Destructor calls the thread-specific exit hooks when a thread exits. More...


Static Public Methods

ACE_Thread_Exit * instance (void)
 Singleton access point. More...

void cleanup (void *instance)
 Cleanup method, used by the <ACE_Object_Manager> to destroy the singleton. More...


Private Attributes

ACE_Thread_Control thread_control_
 Automatically add/remove the thread from the <ACE_Thread_Manager>. More...


Static Private Attributes

u_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 <ACE_TSS> wrapper. When a thread exits the <ACE_TSS::cleanup> function deletes this object, thereby closing it down gracefully.

Definition at line 40 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 68 of file Thread_Exit.cpp.

References ACE_OS_TRACE.

00069 {
00070   ACE_OS_TRACE ("ACE_Thread_Exit::ACE_Thread_Exit");
00071 }

ACE_Thread_Exit::~ACE_Thread_Exit void   
 

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

Definition at line 87 of file Thread_Exit.cpp.

References ACE_OS_TRACE.

00088 {
00089   ACE_OS_TRACE ("ACE_Thread_Exit::~ACE_Thread_Exit");
00090 }


Member Function Documentation

void ACE_Thread_Exit::cleanup void *    instance [static]
 

Cleanup method, used by the <ACE_Object_Manager> to destroy the singleton.

Definition at line 14 of file Thread_Exit.cpp.

References ACE_OS_TRACE, ACE_TSS_TYPE, instance, and is_constructed_.

Referenced by ACE_Thread_Manager::close_singleton.

00015 {
00016   ACE_OS_TRACE ("ACE_Thread_Exit::cleanup");
00017 
00018   delete (ACE_TSS_TYPE (ACE_Thread_Exit) *) instance;
00019 
00020   ACE_Thread_Exit::is_constructed_ = 0;
00021   // All TSS objects have been destroyed.  Reset this flag so
00022   // ACE_Thread_Exit singleton can be created again.
00023 }

ACE_Thread_Exit * ACE_Thread_Exit::instance void    [static]
 

Singleton access point.

Definition at line 30 of file Thread_Exit.cpp.

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

Referenced by cleanup, ACE_Thread_Manager::exit, and ACE_Thread_Adapter::invoke.

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

void ACE_Thread_Exit::thr_mgr ACE_Thread_Manager   tm
 

Set the <ACE_Thread_Manager>.

Definition at line 76 of file Thread_Exit.cpp.

References ACE_OS_TRACE, ACE_Thread_Control::insert, and thread_control_.

Referenced by ACE_Thread_Adapter::invoke.

00077 {
00078   ACE_OS_TRACE ("ACE_Thread_Exit::thr_mgr");
00079 
00080   if (tm != 0)
00081     this->thread_control_.insert (tm, 0);
00082 }


Member Data Documentation

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 11 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 <ACE_Thread_Manager>.

Definition at line 63 of file Thread_Exit.h.

Referenced by thr_mgr.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:57:34 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002