#include <Thread_Manager.h>
Inheritance diagram for ACE_Thread_Descriptor:
Public Member Functions | |
ACE_Thread_Descriptor (void) | |
ACE_thread_t | self (void) const |
Unique thread id. | |
void | self (ACE_hthread_t &) |
Unique handle to thread (used by Win32 and AIX). | |
void | dump (void) const |
Dump the state of an object. | |
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) |
int | at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
~ACE_Thread_Descriptor (void) | |
Do nothing destructor to keep some compilers happy. | |
void | acquire_release (void) |
void | acquire (void) |
void | release (void) |
void | set_next (ACE_Thread_Descriptor *td) |
ACE_Thread_Descriptor * | get_next (void) const |
Private Member Functions | |
void | reset (ACE_Thread_Manager *tm) |
Reset this thread descriptor. | |
void | at_pop (int apply=1) |
void | at_push (ACE_At_Thread_Exit *cleanup, int is_owner=0) |
void | do_at_exit (void) |
Run the AT_Thread_Exit hooks. | |
void | terminate (void) |
Terminate realize the cleanup process to thread termination. | |
Private Attributes | |
ACE_Log_Msg * | log_msg_ |
ACE_At_Thread_Exit * | at_exit_list_ |
The AT_Thread_Exit list. | |
ACE_Cleanup_Info | cleanup_info_ |
ACE_Thread_Manager * | tm_ |
ACE_DEFAULT_THREAD_MANAGER_LOCK * | sync_ |
Registration lock to prevent premature removal of thread descriptor. | |
bool | terminated_ |
Keep track of termination status. | |
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 232 of file Thread_Manager.h.
|
Definition at line 281 of file Thread_Manager.cpp. References ACE_DEFAULT_THREAD_MANAGER_LOCK, ACE_NEW, and ACE_TRACE.
00283 : log_msg_ (0), 00284 at_exit_list_ (0), 00285 terminated_ (false) 00286 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 00287 { 00288 ACE_TRACE ("ACE_Thread_Descriptor::ACE_Thread_Descriptor"); 00289 ACE_NEW (this->sync_, 00290 ACE_DEFAULT_THREAD_MANAGER_LOCK); 00291 } |
|
Do nothing destructor to keep some compilers happy.
Definition at line 94 of file Thread_Manager.cpp. References sync_.
00095 { 00096 delete this->sync_; 00097 } |
|
Definition at line 315 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, and sync_.
00316 { 00317 // Just try to acquire the lock then release it. 00318 #if defined (ACE_THREAD_MANAGER_USES_SAFE_SPAWN) 00319 if (ACE_BIT_DISABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_SPAWNED)) 00320 #endif /* ACE_THREAD_MANAGER_USES_SAFE_SPAWN */ 00321 { 00322 this->sync_->acquire (); 00323 } 00324 } |
|
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 294 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_BIT_DISABLED, ACE_BIT_ENABLED, and sync_. Referenced by ACE_Log_Msg::thr_desc().
00295 { 00296 // Just try to acquire the lock then release it. 00297 #if defined (ACE_THREAD_MANAGER_USES_SAFE_SPAWN) 00298 if (ACE_BIT_DISABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_SPAWNED)) 00299 #endif /* ACE_THREAD_MANAGER_USES_SAFE_SPAWN */ 00300 { 00301 this->sync_->acquire (); 00302 // Acquire the lock before removing <td> from the thread table. If 00303 // this thread is in the table already, it should simply acquire the 00304 // lock easily. 00305 00306 // Once we get the lock, we must have registered. 00307 ACE_ASSERT (ACE_BIT_ENABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_SPAWNED)); 00308 00309 this->sync_->release (); 00310 // Release the lock before putting it back to freelist. 00311 } 00312 } |
|
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 232 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_, ACE_Cleanup_Info::object_, and ACE_Cleanup_Info::param_.
00235 { 00236 ACE_TRACE ("ACE_Thread_Descriptor::at_exit"); 00237 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT) 00238 this->cleanup_info_.cleanup_hook_ = cleanup_hook; 00239 this->cleanup_info_.object_ = object; 00240 this->cleanup_info_.param_ = param; 00241 #else 00242 // To keep compatibility, when cleanup_hook is null really is a at_pop 00243 // without apply. 00244 if (cleanup_hook == 0) 00245 { 00246 if (this->at_exit_list_!= 0) 00247 this->at_pop(0); 00248 } 00249 else 00250 { 00251 ACE_At_Thread_Exit* cleanup = 0; 00252 ACE_NEW_RETURN (cleanup, 00253 ACE_At_Thread_Exit_Func (object, 00254 cleanup_hook, 00255 param), 00256 -1); 00257 this->at_push (cleanup); 00258 } 00259 #endif /* ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 00260 return 0; 00261 } |
|
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 134 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 143 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 100 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().
00102 { 00103 ACE_TRACE ("ACE_Thread_Descriptor::at_pop"); 00104 // Get first at from at_exit_list 00105 ACE_At_Thread_Exit* at = this->at_exit_list_; 00106 // Remove at from at_exit list 00107 this->at_exit_list_ = at->next_; 00108 // Apply if required 00109 if (apply) 00110 { 00111 at->apply (); 00112 // Do the apply method 00113 at->was_applied (1); 00114 // Mark at has been applied to avoid double apply from 00115 // at destructor 00116 } 00117 // If at is not owner delete at. 00118 if (!at->is_owner ()) 00119 delete at; 00120 } |
|
Push an At_Thread_Exit to at thread termination list and set the ownership of at. Definition at line 123 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().
00125 { 00126 ACE_TRACE ("ACE_Thread_Descriptor::at_push"); 00127 cleanup->is_owner (is_owner); 00128 cleanup->td_ = this; 00129 cleanup->next_ = at_exit_list_; 00130 at_exit_list_ = cleanup; 00131 } |
|
Run the AT_Thread_Exit hooks.
Definition at line 157 of file Thread_Manager.cpp. References ACE_TRACE, at_exit_list_, and at_pop(). Referenced by terminate().
00159 { 00160 ACE_TRACE ("ACE_Thread_Descriptor::do_at_exit"); 00161 while (at_exit_list_!=0) 00162 this->at_pop (); 00163 } |
|
Dump the state of an object.
Definition at line 264 of file Thread_Manager.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.
00265 { 00266 #if defined (ACE_HAS_DUMP) 00267 ACE_TRACE ("ACE_Thread_Descriptor::dump"); 00268 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00269 00270 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nthr_id_ = %d"), this->thr_id_)); 00271 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nthr_handle_ = %d"), this->thr_handle_)); 00272 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ngrp_id_ = %d"), this->grp_id_)); 00273 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nthr_state_ = %d"), this->thr_state_)); 00274 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncleanup_info_.cleanup_hook_ = %x"), this->cleanup_info_.cleanup_hook_)); 00275 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nflags_ = %x\n"), this->flags_)); 00276 00277 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00278 #endif /* ACE_HAS_DUMP */ 00279 } |
|
Definition at line 170 of file Thread_Manager.inl. References ACE_TRACE.
|
|
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 153 of file Thread_Manager.inl.
00155 { 00156 log_msg_ = log_msg; 00157 } |
|
Definition at line 327 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, and sync_.
00328 { 00329 // Just try to acquire the lock then release it. 00330 #if defined (ACE_THREAD_MANAGER_USES_SAFE_SPAWN) 00331 if (ACE_BIT_DISABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_SPAWNED)) 00332 #endif /* ACE_THREAD_MANAGER_USES_SAFE_SPAWN */ 00333 { 00334 this->sync_->release (); 00335 // Release the lock before putting it back to freelist. 00336 } 00337 } |
|
Reset this thread descriptor.
Definition at line 178 of file Thread_Manager.inl. References ACE_TRACE, at_exit_list_, ACE_Cleanup_Info::cleanup_hook_, ACE_Cleanup_Info::object_, ACE_Cleanup_Info::param_, ACE_Thread_Descriptor_Base::reset(), and terminated_.
00179 { 00180 ACE_TRACE ("ACE_Thread_Descriptor::reset"); 00181 this->ACE_Thread_Descriptor_Base::reset (); 00182 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT) 00183 this->cleanup_info_.cleanup_hook_ = 0; 00184 this->cleanup_info_.object_ = 0; 00185 this->cleanup_info_.param_ = 0; 00186 #else /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 00187 this->at_exit_list_ = 0; 00188 // Start the at_exit hook list. 00189 this->tm_ = tm; 00190 // Setup the Thread_Manager. 00191 this->log_msg_ = 0; 00192 this->terminated_ = false; 00193 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 00194 } |
|
Unique handle to thread (used by Win32 and AIX).
Definition at line 145 of file Thread_Manager.inl. References ACE_hthread_t, and ACE_TRACE.
00146 { 00147 ACE_TRACE ("ACE_Thread_Descriptor::self"); 00148 handle = this->thr_handle_; 00149 } |
|
Unique thread id.
Definition at line 136 of file Thread_Manager.inl. References ACE_TRACE. Referenced by ACE_Thread_Manager::remove_thr(), and ACE_Thread_Manager::thr_self().
|
|
Set/get the Definition at line 162 of file Thread_Manager.inl. References ACE_TRACE.
|
|
Terminate realize the cleanup process to thread termination.
Definition at line 166 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_LOG_MSG, ACE_SET_BITS, ACE_TRACE, do_at_exit(), ACE_Thread_Manager::register_as_terminated(), ACE_Thread_Manager::remove_thr(), and terminated_. Referenced by ACE_Thread_Manager::exit().
00168 { 00169 ACE_TRACE ("ACE_Thread_Descriptor::terminate"); 00170 00171 if (!terminated_) 00172 { 00173 ACE_Log_Msg* log_msg = this->log_msg_; 00174 terminated_ = true; 00175 // Run at_exit hooks 00176 this->do_at_exit (); 00177 // We must remove Thread_Descriptor from Thread_Manager list 00178 if (this->tm_ != 0) 00179 { 00180 int close_handle = 0; 00181 00182 #if !defined (ACE_VXWORKS) 00183 // Threads created with THR_DAEMON shouldn't exist here, but 00184 // just to be safe, let's put it here. 00185 00186 if (ACE_BIT_DISABLED (this->thr_state_, ACE_Thread_Manager::ACE_THR_JOINING)) 00187 { 00188 if (ACE_BIT_DISABLED (this->flags_, THR_DETACHED | THR_DAEMON) 00189 || ACE_BIT_ENABLED (this->flags_, THR_JOINABLE)) 00190 { 00191 // Mark thread as terminated. 00192 ACE_SET_BITS (this->thr_state_, ACE_Thread_Manager::ACE_THR_TERMINATED); 00193 tm_->register_as_terminated (this); 00194 // Must copy the information here because td will be 00195 // "freed" below. 00196 } 00197 #if defined (ACE_WIN32) 00198 else 00199 { 00200 close_handle = 1; 00201 } 00202 #endif /* ACE_WIN32 */ 00203 } 00204 #endif /* ! ACE_VXWORKS */ 00205 00206 // Remove thread descriptor from the table. 00207 if (this->tm_ != 0) 00208 tm_->remove_thr (this, close_handle); 00209 } 00210 00211 // Check if we need delete ACE_Log_Msg instance 00212 // If ACE_TSS_cleanup was not executed first log_msg == 0 00213 if (log_msg == 0) 00214 { 00215 // Only inform to ACE_TSS_cleanup that it must delete the log instance 00216 // setting ACE_LOG_MSG thr_desc to 0. 00217 ACE_LOG_MSG->thr_desc (0); 00218 } 00219 else 00220 { 00221 // Thread_Descriptor is the owner of the Log_Msg instance!! 00222 // deleted. 00223 this->log_msg_ = 0; 00224 delete log_msg; 00225 } 00226 } 00227 } |
|
Definition at line 235 of file Thread_Manager.h. |
|
Reimplemented from ACE_Thread_Descriptor_Base. Definition at line 238 of file Thread_Manager.h. |
|
Reimplemented from ACE_Thread_Descriptor_Base. Definition at line 239 of file Thread_Manager.h. |
|
Reimplemented from ACE_Thread_Descriptor_Base. Definition at line 237 of file Thread_Manager.h. |
|
The AT_Thread_Exit list.
Definition at line 337 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.
Definition at line 344 of file Thread_Manager.h. Referenced by ACE_Thread_Manager::exit(), 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 334 of file Thread_Manager.h. |
|
Registration lock to prevent premature removal of thread descriptor.
Definition at line 353 of file Thread_Manager.h. Referenced by acquire(), acquire_release(), ACE_Thread_Manager::append_thr(), release(), and ~ACE_Thread_Descriptor(). |
|
Keep track of termination status.
Definition at line 357 of file Thread_Manager.h. Referenced by reset(), and terminate(). |
|
Pointer to an ACE_Thread_Manager or NULL if there's no ACE_Thread_Manager> Definition at line 349 of file Thread_Manager.h. Referenced by ACE_Thread_Manager::append_thr(), and ACE_Thread_Manager::remove_thr(). |