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;
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.
31 ACE_Thread_Exit::instance ()
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
),
54 ACE_Thread_Exit::is_constructed_
= true;
56 ACE_Thread_Manager::set_thr_exit (instance_
);
60 return ACE_TSS_GET (instance_
, ACE_Thread_Exit
);
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
69 ACE_Thread_Exit::ACE_Thread_Exit ()
71 ACE_OS_TRACE ("ACE_Thread_Exit::ACE_Thread_Exit");
74 // Set the this pointer...
77 ACE_Thread_Exit::thr_mgr (ACE_Thread_Manager
*tm
)
79 ACE_OS_TRACE ("ACE_Thread_Exit::thr_mgr");
82 this->thread_control_
.insert (tm
, 0);
85 // When this object is destroyed the Task is automatically closed
88 ACE_Thread_Exit::~ACE_Thread_Exit ()
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
)
100 ACE_NEW (instance_
, ACE_Thread_Exit
);
104 ACE_Thread_Exit_Maybe::~ACE_Thread_Exit_Maybe ()
106 delete this->instance_
;
110 ACE_Thread_Exit_Maybe::operator -> () const
112 return this->instance_
;
116 ACE_Thread_Exit_Maybe::instance () const
118 return this->instance_
;
121 ACE_END_VERSIONED_NAMESPACE_DECL