Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Thread_Exit.cpp
blobcc6a8620cbebe213c4948f6bb31becd622b98b51
1 // $Id: Thread_Exit.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/Thread_Exit.h"
4 #include "ace/Managed_Object.h"
5 #include "ace/Thread_Manager.h"
6 #include "ace/Guard_T.h"
8 ACE_RCSID(ace, Thread_Exit, "$Id: Thread_Exit.cpp 80826 2008-03-04 14:51:23Z wotte $")
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 bool ACE_Thread_Exit::is_constructed_ = false;
14 void
15 ACE_Thread_Exit::cleanup (void *instance)
17 ACE_OS_TRACE ("ACE_Thread_Exit::cleanup");
19 delete (ACE_TSS_TYPE (ACE_Thread_Exit) *) instance;
21 // Set the thr_exit_ static to null to keep things from crashing if
22 // ACE::fini() is enabled here.
23 ACE_Thread_Manager::thr_exit_ = 0;
25 ACE_Thread_Exit::is_constructed_ = false;
26 // All TSS objects have been destroyed. Reset this flag so
27 // ACE_Thread_Exit singleton can be created again.
30 // NOTE: this preprocessor directive should match the one in
31 // ACE_Task_Base::svc_run () below. This prevents the two statics
32 // from being defined.
34 ACE_Thread_Exit *
35 ACE_Thread_Exit::instance (void)
37 #if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)
38 ACE_OS_TRACE ("ACE_Thread_Exit::instance");
40 // Determines if we were dynamically allocated.
41 static ACE_TSS_TYPE (ACE_Thread_Exit) * volatile instance_;
43 // Implement the Double Check pattern.
45 if (!ACE_Thread_Exit::is_constructed_)
47 ACE_MT (ACE_Thread_Mutex *lock =
48 ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object
49 (ACE_Object_Manager::ACE_THREAD_EXIT_LOCK);
50 ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, *lock, 0));
52 if (!ACE_Thread_Exit::is_constructed_)
54 ACE_NEW_RETURN (instance_,
55 ACE_TSS_TYPE (ACE_Thread_Exit),
56 0);
58 ACE_Thread_Exit::is_constructed_ = true;
60 ACE_Thread_Manager::set_thr_exit (instance_);
64 return ACE_TSS_GET (instance_, ACE_Thread_Exit);
65 #else
66 return 0;
67 #endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */
70 // Grab hold of the Task * so that we can close() it in the
71 // destructor.
73 ACE_Thread_Exit::ACE_Thread_Exit (void)
75 ACE_OS_TRACE ("ACE_Thread_Exit::ACE_Thread_Exit");
78 // Set the this pointer...
80 void
81 ACE_Thread_Exit::thr_mgr (ACE_Thread_Manager *tm)
83 ACE_OS_TRACE ("ACE_Thread_Exit::thr_mgr");
85 if (tm != 0)
86 this->thread_control_.insert (tm, 0);
89 // When this object is destroyed the Task is automatically closed
90 // down!
92 ACE_Thread_Exit::~ACE_Thread_Exit (void)
94 ACE_OS_TRACE ("ACE_Thread_Exit::~ACE_Thread_Exit");
97 ACE_Thread_Exit_Maybe::ACE_Thread_Exit_Maybe (int flag)
98 : instance_ (0)
100 if (flag)
102 ACE_NEW (instance_, ACE_Thread_Exit);
106 ACE_Thread_Exit_Maybe::~ACE_Thread_Exit_Maybe (void)
108 delete this->instance_;
111 ACE_Thread_Exit *
112 ACE_Thread_Exit_Maybe::operator -> (void) const
114 return this->instance_;
117 ACE_Thread_Exit *
118 ACE_Thread_Exit_Maybe::instance (void) const
120 return this->instance_;
123 ACE_END_VERSIONED_NAMESPACE_DECL