gnuace: use list of generated files from GENERATED_DIRTY for ADDITIONAL_IDL_TARGETS
[ACE_TAO.git] / ACE / ace / Thread_Exit.cpp
blob0d35cdba213ad30df7071737aa178be29823bc6d
1 #include "ace/Thread_Exit.h"
2 #include "ace/Managed_Object.h"
3 #include "ace/Thread_Manager.h"
4 #include "ace/Guard_T.h"
6 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
8 bool ACE_Thread_Exit::is_constructed_ = false;
10 void
11 ACE_Thread_Exit::cleanup (void *instance)
13 ACE_OS_TRACE ("ACE_Thread_Exit::cleanup");
15 delete (ACE_TSS_TYPE (ACE_Thread_Exit) *) instance;
17 // Set the thr_exit_ static to null to keep things from crashing if
18 // ACE::fini() is enabled here.
19 ACE_Thread_Manager::thr_exit_ = 0;
21 ACE_Thread_Exit::is_constructed_ = false;
22 // All TSS objects have been destroyed. Reset this flag so
23 // ACE_Thread_Exit singleton can be created again.
26 // NOTE: this preprocessor directive should match the one in
27 // ACE_Task_Base::svc_run () below. This prevents the two statics
28 // from being defined.
30 ACE_Thread_Exit *
31 ACE_Thread_Exit::instance (void)
33 #if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)
34 ACE_OS_TRACE ("ACE_Thread_Exit::instance");
36 // Determines if we were dynamically allocated.
37 static ACE_TSS_TYPE (ACE_Thread_Exit) * volatile instance_;
39 // Implement the Double Check pattern.
41 if (!ACE_Thread_Exit::is_constructed_)
43 ACE_MT (ACE_Thread_Mutex *lock =
44 ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object
45 (ACE_Object_Manager::ACE_THREAD_EXIT_LOCK);
46 ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, *lock, 0));
48 if (!ACE_Thread_Exit::is_constructed_)
50 ACE_NEW_RETURN (instance_,
51 ACE_TSS_TYPE (ACE_Thread_Exit),
52 0);
54 ACE_Thread_Exit::is_constructed_ = true;
56 ACE_Thread_Manager::set_thr_exit (instance_);
60 return ACE_TSS_GET (instance_, ACE_Thread_Exit);
61 #else
62 return 0;
63 #endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */
66 // Grab hold of the Task * so that we can close() it in the
67 // destructor.
69 ACE_Thread_Exit::ACE_Thread_Exit (void)
71 ACE_OS_TRACE ("ACE_Thread_Exit::ACE_Thread_Exit");
74 // Set the this pointer...
76 void
77 ACE_Thread_Exit::thr_mgr (ACE_Thread_Manager *tm)
79 ACE_OS_TRACE ("ACE_Thread_Exit::thr_mgr");
81 if (tm != 0)
82 this->thread_control_.insert (tm, 0);
85 // When this object is destroyed the Task is automatically closed
86 // down!
88 ACE_Thread_Exit::~ACE_Thread_Exit (void)
90 ACE_OS_TRACE ("ACE_Thread_Exit::~ACE_Thread_Exit");
93 ACE_ALLOC_HOOK_DEFINE(ACE_Thread_Exit)
95 ACE_Thread_Exit_Maybe::ACE_Thread_Exit_Maybe (int flag)
96 : instance_ (0)
98 if (flag)
100 ACE_NEW (instance_, ACE_Thread_Exit);
104 ACE_Thread_Exit_Maybe::~ACE_Thread_Exit_Maybe (void)
106 delete this->instance_;
109 ACE_Thread_Exit *
110 ACE_Thread_Exit_Maybe::operator -> (void) const
112 return this->instance_;
115 ACE_Thread_Exit *
116 ACE_Thread_Exit_Maybe::instance (void) const
118 return this->instance_;
121 ACE_END_VERSIONED_NAMESPACE_DECL