#include <Thread_Manager.h>
Inheritance diagram for ACE_Thread_Descriptor:


Public Methods | |
| ACE_Thread_Descriptor (void) | |
| ACE_thread_t | self (void) const |
| Unique thread id. More... | |
| void | self (ACE_hthread_t &) |
| Unique handle to thread (used by Win32 and AIX). More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
| void | log_msg_cleanup (ACE_Log_Msg *log_msg) |
| int | at_exit (ACE_At_Thread_Exit *cleanup) |
| int | at_exit (ACE_At_Thread_Exit &cleanup) |
| Register an At_Thread_Exit hook and the ownership is retained for the caller. Normally used when the at_exit hook is created in stack. More... | |
| int | at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
| ~ACE_Thread_Descriptor (void) | |
| Do nothing destructor to keep some compilers happy. More... | |
| void | acquire_release (void) |
| ACE_INLINE_FOR_GNUC void | set_next (ACE_Thread_Descriptor *td) |
| ACE_INLINE_FOR_GNUC ACE_Thread_Descriptor * | get_next (void) const |
Private Methods | |
| void | reset (ACE_Thread_Manager *tm) |
| Reset this thread descriptor. More... | |
| void | at_pop (int apply=1) |
| Pop an At_Thread_Exit from at thread termination list, apply the at if apply is true. More... | |
| void | at_push (ACE_At_Thread_Exit *cleanup, int is_owner=0) |
| Push an At_Thread_Exit to at thread termination list and set the ownership of at. More... | |
| void | do_at_exit (void) |
| Run the AT_Thread_Exit hooks. More... | |
| void | terminate (void) |
| terminate realize the cleanup process to thread termination. More... | |
Private Attributes | |
| ACE_Log_Msg * | log_msg_ |
| Thread_Descriptor is the ownership of ACE_Log_Msg if log_msg_!=0 This can occur because ACE_TSS_cleanup was executed before terminate. More... | |
| ACE_At_Thread_Exit * | at_exit_list_ |
| The AT_Thread_Exit list. More... | |
| ACE_Cleanup_Info | cleanup_info_ |
| ACE_Thread_Manager * | tm_ |
| Pointer to an <ACE_Thread_Manager> or NULL if there's no <ACE_Thread_Manager>. More... | |
| ACE_DEFAULT_THREAD_MANAGER_LOCK * | sync_ |
| Registration lock to prevent premature removal of thread descriptor. More... | |
| int | terminated_ |
| Keep track of termination status. More... | |
Friends | |
| class | ACE_At_Thread_Exit |
| class | ACE_Thread_Manager |
| class | ACE_Double_Linked_List< ACE_Thread_Descriptor > |
| class | ACE_Double_Linked_List_Iterator< ACE_Thread_Descriptor > |
Definition at line 226 of file Thread_Manager.h.
|
|
Definition at line 247 of file Thread_Manager.cpp. References ACE_DEFAULT_THREAD_MANAGER_LOCK, ACE_NEW, and ACE_TRACE.
00249 : log_msg_ (0), 00250 at_exit_list_ (0), 00251 terminated_ (0) 00252 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 00253 { 00254 ACE_TRACE ("ACE_Thread_Descriptor::ACE_Thread_Descriptor"); 00255 ACE_NEW (this->sync_, 00256 ACE_DEFAULT_THREAD_MANAGER_LOCK); 00257 } |
|
|
Do nothing destructor to keep some compilers happy.
Definition at line 62 of file Thread_Manager.cpp. References sync_.
00063 {
00064 delete this->sync_;
00065 }
|
|
|
Do nothing but to acquire the thread descriptor's lock and release. This will first check if the thread is registered or not. If it is already registered, there's no need to reacquire the lock again. This is used mainly to get newly spawned thread in synch with thread manager and prevent it from accessing its thread descriptor before it gets fully built. This function is only called from ACE_Log_Msg::thr_desc. Definition at line 260 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_Thread_Manager::ACE_THR_SPAWNED, and sync_. Referenced by ACE_Log_Msg::thr_desc.
00261 {
00262 // Just try to acquire the lock then release it.
00263 #if defined (ACE_THREAD_MANAGER_USES_SAFE_SPAWN)
00264 if (ACE_BIT_DISABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_SPAWNED))
00265 #endif /* ACE_THREAD_MANAGER_USES_SAFE_SPAWN */
00266 {
00267 this->sync_->acquire ();
00268 // Acquire the lock before removing <td> from the thread table. If
00269 // this thread is in the table already, it should simply acquire the
00270 // lock easily.
00271
00272 // Once we get the lock, we must have registered.
00273 ACE_ASSERT (ACE_BIT_ENABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_SPAWNED));
00274
00275 this->sync_->release ();
00276 // Release the lock before putting it back to freelist.
00277 }
00278 }
|
|
||||||||||||||||
|
Register an object (or array) for cleanup at thread termination. "cleanup_hook" points to a (global, or static member) function that is called for the object or array when it to be destroyed. It may perform any necessary cleanup specific for that object or its class. "param" is passed as the second parameter to the "cleanup_hook" function; the first parameter is the object (or array) to be destroyed. Returns 0 on success, non-zero on failure: -1 if virtual memory is exhausted or 1 if the object (or arrayt) had already been registered. Definition at line 200 of file Thread_Manager.cpp. References ACE_CLEANUP_FUNC, ACE_NEW_RETURN, ACE_TRACE, at_exit_list_, at_pop, at_push, ACE_Cleanup_Info::cleanup_hook_, cleanup_info_, ACE_Cleanup_Info::object_, and ACE_Cleanup_Info::param_.
00203 {
00204 ACE_TRACE ("ACE_Thread_Descriptor::at_exit");
00205 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
00206 this->cleanup_info_.cleanup_hook_ = cleanup_hook;
00207 this->cleanup_info_.object_ = object;
00208 this->cleanup_info_.param_ = param;
00209 #else
00210 // To keep compatibility, when cleanup_hook is null really is a at_pop
00211 // without apply.
00212 if (cleanup_hook == 0)
00213 {
00214 if (this->at_exit_list_!= 0)
00215 this->at_pop(0);
00216 }
00217 else
00218 {
00219 ACE_At_Thread_Exit* cleanup;
00220 ACE_NEW_RETURN (cleanup,
00221 ACE_At_Thread_Exit_Func (object,
00222 cleanup_hook,
00223 param),
00224 -1);
00225 this->at_push (cleanup);
00226 }
00227 #endif /* ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
00228 return 0;
00229 }
|
|
|
Register an At_Thread_Exit hook and the ownership is retained for the caller. Normally used when the at_exit hook is created in stack.
Definition at line 102 of file Thread_Manager.cpp. References ACE_TRACE, and at_push.
|
|
|
Register an At_Thread_Exit hook and the ownership is acquire by Thread_Descriptor, this is the usual case when the AT is dynamically allocated. Definition at line 111 of file Thread_Manager.cpp. References ACE_TRACE, and at_push. Referenced by ACE_Thread_Manager::at_exit.
|
|
|
Pop an At_Thread_Exit from at thread termination list, apply the at if apply is true.
Definition at line 68 of file Thread_Manager.cpp. References ACE_TRACE, ACE_At_Thread_Exit::apply, at_exit_list_, ACE_At_Thread_Exit::is_owner, ACE_At_Thread_Exit::next_, and ACE_At_Thread_Exit::was_applied. Referenced by at_exit, ACE_At_Thread_Exit::do_apply, and do_at_exit.
00070 {
00071 ACE_TRACE ("ACE_Thread_Descriptor::at_pop");
00072 // Get first at from at_exit_list
00073 ACE_At_Thread_Exit* at = this->at_exit_list_;
00074 // Remove at from at_exit list
00075 this->at_exit_list_ = at->next_;
00076 // Apply if required
00077 if (apply)
00078 {
00079 at->apply ();
00080 // Do the apply method
00081 at->was_applied (1);
00082 // Mark at has been applied to avoid double apply from
00083 // at destructor
00084 }
00085 // If at is not owner delete at.
00086 if (!at->is_owner ())
00087 delete at;
00088 }
|
|
||||||||||||
|
Push an At_Thread_Exit to at thread termination list and set the ownership of at.
Definition at line 91 of file Thread_Manager.cpp. References ACE_TRACE, at_exit_list_, ACE_At_Thread_Exit::is_owner, ACE_At_Thread_Exit::next_, and ACE_At_Thread_Exit::td_. Referenced by at_exit.
00093 {
00094 ACE_TRACE ("ACE_Thread_Descriptor::at_push");
00095 cleanup->is_owner (is_owner);
00096 cleanup->td_ = this;
00097 cleanup->next_ = at_exit_list_;
00098 at_exit_list_ = cleanup;
00099 }
|
|
|
Run the AT_Thread_Exit hooks.
Definition at line 125 of file Thread_Manager.cpp. References ACE_TRACE, at_exit_list_, and at_pop. Referenced by terminate.
00127 {
00128 ACE_TRACE ("ACE_Thread_Descriptor::do_at_exit");
00129 while (at_exit_list_!=0)
00130 this->at_pop ();
00131 }
|
|
|
Dump the state of an object.
Definition at line 232 of file Thread_Manager.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.
00233 {
00234 ACE_TRACE ("ACE_Thread_Descriptor::dump");
00235 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00236
00237 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nthr_id_ = %d"), this->thr_id_));
00238 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nthr_handle_ = %d"), this->thr_handle_));
00239 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ngrp_id_ = %d"), this->grp_id_));
00240 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nthr_state_ = %d"), this->thr_state_));
00241 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncleanup_info_.cleanup_hook_ = %x"), this->cleanup_info_.cleanup_hook_));
00242 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nflags_ = %x\n"), this->flags_));
00243
00244 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00245 }
|
|
|
Definition at line 185 of file Thread_Manager.i. References ACE_TRACE.
00186 {
00187 ACE_TRACE ("ACE_Thread_Descriptor::get_next");
00188 return ACE_static_cast (ACE_Thread_Descriptor * ACE_CAST_CONST,
00189 this->next_);
00190 }
|
|
|
This cleanup function must be called only for ACE_TSS_cleanup. The ACE_TSS_cleanup delegate Log_Msg instance destruction when Log_Msg cleanup is called before terminate. Definition at line 168 of file Thread_Manager.i. References log_msg_.
00170 {
00171 log_msg_ = log_msg;
00172 }
|
|
|
Reset this thread descriptor.
Definition at line 194 of file Thread_Manager.i. References ACE_TRACE, at_exit_list_, ACE_Cleanup_Info::cleanup_hook_, cleanup_info_, log_msg_, ACE_Cleanup_Info::object_, ACE_Cleanup_Info::param_, ACE_Thread_Descriptor_Base::reset, terminated_, and tm_.
00195 {
00196 ACE_TRACE ("ACE_Thread_Descriptor::reset");
00197 this->ACE_Thread_Descriptor_Base::reset ();
00198 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
00199 this->cleanup_info_.cleanup_hook_ = 0;
00200 this->cleanup_info_.object_ = 0;
00201 this->cleanup_info_.param_ = 0;
00202 #else /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
00203 this->at_exit_list_ = 0;
00204 // Start the at_exit hook list.
00205 this->tm_ = tm;
00206 // Setup the Thread_Manager.
00207 this->log_msg_ = 0;
00208 this->terminated_ = 0;
00209 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
00210 }
|
|
|
Unique handle to thread (used by Win32 and AIX).
Definition at line 160 of file Thread_Manager.i. References ACE_hthread_t, ACE_TRACE, and ACE_Thread_Descriptor_Base::thr_handle_.
00161 {
00162 ACE_TRACE ("ACE_Thread_Descriptor::self");
00163 handle = this->thr_handle_;
00164 }
|
|
|
Unique thread id.
Definition at line 151 of file Thread_Manager.i. References ACE_TRACE, and ACE_Thread_Descriptor_Base::thr_id_. Referenced by ACE_Thread_Manager::remove_thr, and ACE_Thread_Manager::thr_self.
|
|
|
Set/get the <next_> pointer. These are required by the ACE_Free_List. ACE_INLINE is specified here because one version of g++ couldn't grok this code without it. Definition at line 177 of file Thread_Manager.i. References ACE_TRACE, and ACE_Thread_Descriptor_Base::next_.
|
|
|
terminate realize the cleanup process to thread termination.
Definition at line 134 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_LOG_MSG, ACE_SET_BITS, ACE_Thread_Manager::ACE_THR_JOINING, ACE_Thread_Manager::ACE_THR_TERMINATED, ACE_TRACE, do_at_exit, log_msg_, ACE_Thread_Manager::register_as_terminated, ACE_Thread_Manager::remove_thr, terminated_, and tm_. Referenced by ACE_Thread_Manager::exit.
00136 {
00137 ACE_TRACE ("ACE_Thread_Descriptor::terminate");
00138
00139 if (!terminated_)
00140 {
00141 ACE_Log_Msg* log_msg = this->log_msg_;
00142 terminated_ = 1;
00143 // Run at_exit hooks
00144 this->do_at_exit ();
00145 // We must remove Thread_Descriptor from Thread_Manager list
00146 if (this->tm_ != 0)
00147 {
00148 int close_handle = 0;
00149
00150 #if !defined (VXWORKS)
00151 // Threads created with THR_DAEMON shouldn't exist here, but
00152 // just to be safe, let's put it here.
00153
00154 if (ACE_BIT_DISABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_JOINING))
00155 {
00156 if (ACE_BIT_DISABLED (this->flags_, THR_DETACHED | THR_DAEMON)
00157 || ACE_BIT_ENABLED (this->flags_, THR_JOINABLE))
00158 {
00159 // Mark thread as terminated.
00160 ACE_SET_BITS (this->thr_state_, ACE_Thread_Manager::ACE_THR_TERMINATED);
00161 tm_->register_as_terminated (this);
00162 // Must copy the information here because td will be
00163 // "freed" below.
00164 }
00165 #if defined (ACE_WIN32)
00166 else
00167 {
00168 close_handle = 1;
00169 }
00170 #endif /* ACE_WIN32 */
00171 }
00172 #endif /* ! VXWORKS */
00173
00174 // Remove thread descriptor from the table.
00175 if (this->tm_ != 0)
00176 tm_->remove_thr (this, close_handle);
00177 }
00178
00179 // Check if we need delete ACE_Log_Msg instance
00180 // If ACE_TSS_cleanup was not executed first log_msg == 0
00181 if (log_msg == 0)
00182 {
00183 // Only inform to ACE_TSS_cleanup that it must delete the log instance
00184 // setting ACE_LOG_MSG thr_desc to 0.
00185 ACE_LOG_MSG->thr_desc (0);
00186 }
00187 else
00188 {
00189 // Thread_Descriptor is the owner of the Log_Msg instance!!
00190 // deleted.
00191 this->log_msg_ = 0;
00192 delete log_msg;
00193 }
00194 }
00195 }
|
|
|
Definition at line 229 of file Thread_Manager.h. |
|
|
Reimplemented from ACE_Thread_Descriptor_Base. Definition at line 232 of file Thread_Manager.h. |
|
|
Reimplemented from ACE_Thread_Descriptor_Base. Definition at line 233 of file Thread_Manager.h. |
|
|
Reimplemented from ACE_Thread_Descriptor_Base. Definition at line 231 of file Thread_Manager.h. |
|
|
The AT_Thread_Exit list.
Definition at line 330 of file Thread_Manager.h. Referenced by at_exit, at_pop, at_push, do_at_exit, and reset. |
|
|
Stores the cleanup info for a thread. @ Note, this should be generalized to be a stack of <ACE_Cleanup_Info>s. Definition at line 338 of file Thread_Manager.h. Referenced by at_exit, ACE_Thread_Manager::exit, reset, and ACE_Thread_Manager::run_thread_exit_hooks. |
|
|
Thread_Descriptor is the ownership of ACE_Log_Msg if log_msg_!=0 This can occur because ACE_TSS_cleanup was executed before terminate.
Definition at line 327 of file Thread_Manager.h. Referenced by log_msg_cleanup, reset, and terminate. |
|
|
Registration lock to prevent premature removal of thread descriptor.
Definition at line 347 of file Thread_Manager.h. Referenced by acquire_release, ACE_Thread_Manager::append_thr, and ~ACE_Thread_Descriptor. |
|
|
Keep track of termination status.
Definition at line 351 of file Thread_Manager.h. |
|
|
Pointer to an <ACE_Thread_Manager> or NULL if there's no <ACE_Thread_Manager>.
Definition at line 343 of file Thread_Manager.h. Referenced by ACE_Thread_Manager::append_thr, ACE_Thread_Manager::remove_thr, reset, and terminate. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002