Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / Thread_Exit.h
blob0f6459c37a46be36eacdbc6667f48877d3707a69
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Thread_Exit.h
7 * @author Carlos O'Ryan <coryan@uci.edu>
8 */
9 //=============================================================================
12 #ifndef ACE_THREAD_EXIT_H
13 #define ACE_THREAD_EXIT_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/config-all.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Thread_Control.h"
24 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 /**
27 * @class ACE_Thread_Exit
29 * @brief Keep exit information for a Thread in thread specific storage.
30 * so that the thread-specific exit hooks will get called no
31 * matter how the thread exits (e.g., via <ACE_Thread::exit>, C++
32 * or Win32 exception, "falling off the end" of the thread entry
33 * point function, etc.).
35 * This clever little helper class is stored in thread-specific
36 * storage using the <ACE_TSS> wrapper. When a thread exits the
37 * <ACE_TSS::cleanup> function deletes this object, thereby
38 * closing it down gracefully.
40 class ACE_Export ACE_Thread_Exit
42 public:
43 /// Capture the Thread that will be cleaned up automatically.
44 ACE_Thread_Exit ();
46 /// Set the ACE_Thread_Manager.
47 void thr_mgr (ACE_Thread_Manager *tm);
49 /// Destructor calls the thread-specific exit hooks when a thread
50 /// exits.
51 ~ACE_Thread_Exit ();
53 /// Singleton access point.
54 static ACE_Thread_Exit *instance ();
56 /// Cleanup method, used by the ACE_Object_Manager to destroy the
57 /// singleton.
58 static void cleanup (void *instance);
60 ACE_ALLOC_HOOK_DECLARE;
62 private:
63 /// Automatically add/remove the thread from the
64 /// ACE_Thread_Manager.
65 ACE_Thread_Control thread_control_;
67 /**
68 * Used to detect whether we should create a new instance (or not)
69 * within the instance method -- we don't trust the instance_ ptr
70 * because the destructor may have run (if ACE::fini() was called).
71 * See bug #526.
72 * We don't follow the singleton pattern due to dependency issues.
74 static bool is_constructed_;
77 /**
78 * @class ACE_Thread_Exit_Maybe
80 * @brief A version of ACE_Thread_Exit that is created dynamically
81 * under the hood if the flag is set to TRUE.
83 * Allows the appearance of a "smart pointer", but is not
84 * always created.
86 class ACE_Export ACE_Thread_Exit_Maybe
88 public:
89 /// Don't create an ACE_Thread_Exit instance by default.
90 ACE_Thread_Exit_Maybe (int flag = 0);
92 /// Destroys the underlying ACE_Thread_Exit instance if it exists.
93 ~ACE_Thread_Exit_Maybe ();
95 /// Delegates to underlying instance.
96 ACE_Thread_Exit * operator -> () const;
98 /// Returns the underlying instance.
99 ACE_Thread_Exit * instance () const;
101 private:
102 /// Holds the underlying instance.
103 ACE_Thread_Exit *instance_;
106 ACE_END_VERSIONED_NAMESPACE_DECL
108 #include /**/ "ace/post.h"
109 #endif /* ACE_THREAD_EXIT_H */