#include <Thread_Manager.h>
Collaboration diagram for ACE_Thread_Manager:
Public Types | |
typedef int(ACE_Thread_Manager::* | ACE_THR_MEMBER_FUNC )(ACE_Thread_Descriptor *, int) |
enum | { ACE_THR_IDLE = 0x00000000, ACE_THR_SPAWNED = 0x00000001, ACE_THR_RUNNING = 0x00000002, ACE_THR_SUSPENDED = 0x00000004, ACE_THR_CANCELLED = 0x00000008, ACE_THR_TERMINATED = 0x00000010, ACE_THR_JOINING = 0x10000000 } |
Public Member Functions | |
ACE_Thread_Manager (size_t preaolloc=ACE_DEFAULT_THREAD_MANAGER_PREALLOC, size_t lwm=ACE_DEFAULT_THREAD_MANAGER_LWM, size_t inc=ACE_DEFAULT_THREAD_MANAGER_INC, size_t hwm=ACE_DEFAULT_THREAD_MANAGER_HWM) | |
Initialization and termination methods. | |
~ACE_Thread_Manager (void) | |
int | open (size_t size=0) |
No-op. Currently unused. | |
int | close (void) |
int | spawn (ACE_THR_FUNC func, void *arg=0, long flags=THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED, ACE_thread_t *=0, ACE_hthread_t *t_handle=0, long priority=ACE_DEFAULT_THREAD_PRIORITY, int grp_id=-1, void *stack=0, size_t stack_size=0) |
int | spawn_n (size_t n, ACE_THR_FUNC func, void *arg=0, long flags=THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED, long priority=ACE_DEFAULT_THREAD_PRIORITY, int grp_id=-1, ACE_Task_Base *task=0, ACE_hthread_t thread_handles[]=0, void *stack[]=0, size_t stack_size[]=0) |
int | spawn_n (ACE_thread_t thread_ids[], size_t n, ACE_THR_FUNC func, void *arg, long flags, long priority=ACE_DEFAULT_THREAD_PRIORITY, int grp_id=-1, void *stack[]=0, size_t stack_size[]=0, ACE_hthread_t thread_handles[]=0, ACE_Task_Base *task=0) |
ACE_THR_FUNC_RETURN | exit (ACE_THR_FUNC_RETURN status=0, int do_thread_exit=1) |
int | wait (const ACE_Time_Value *timeout=0, bool abandon_detached_threads=false, bool use_absolute_time=true) |
int | join (ACE_thread_t tid, ACE_THR_FUNC_RETURN *status=0) |
Join a thread specified by . Do not wait on a detached thread. | |
int | wait_grp (int grp_id) |
int | thr_self (ACE_hthread_t &) |
ACE_thread_t | thr_self (void) |
ACE_Task_Base * | task (void) |
int | suspend_all (void) |
Suspend all threads. | |
int | suspend (ACE_thread_t) |
Suspend a single thread. | |
int | suspend_grp (int grp_id) |
Suspend a group of threads. | |
int | testsuspend (ACE_thread_t t_id) |
int | resume_all (void) |
Resume all stopped threads. | |
int | resume (ACE_thread_t) |
Resume a single thread. | |
int | resume_grp (int grp_id) |
Resume a group of threads. | |
int | testresume (ACE_thread_t t_id) |
int | kill_all (int signum) |
int | kill (ACE_thread_t, int signum) |
int | kill_grp (int grp_id, int signum) |
int | cancel_all (int async_cancel=0) |
int | cancel (ACE_thread_t, int async_cancel=0) |
int | cancel_grp (int grp_id, int async_cancel=0) |
int | testcancel (ACE_thread_t t_id) |
int | testterminate (ACE_thread_t t_id) |
int | set_grp (ACE_thread_t, int grp_id) |
Set group ids for a particular thread id. | |
int | get_grp (ACE_thread_t, int &grp_id) |
Get group ids for a particular thread id. | |
int | wait_task (ACE_Task_Base *task) |
int | suspend_task (ACE_Task_Base *task) |
int | resume_task (ACE_Task_Base *task) |
int | kill_task (ACE_Task_Base *task, int signum) |
int | cancel_task (ACE_Task_Base *task, int async_cancel=0) |
int | hthread_within (ACE_hthread_t handle) |
int | thread_within (ACE_thread_t tid) |
int | num_tasks_in_group (int grp_id) |
Returns the number of in a group. | |
int | num_threads_in_task (ACE_Task_Base *task) |
Returns the number of threads in an . | |
ssize_t | task_list (int grp_id, ACE_Task_Base *task_list[], size_t n) |
ssize_t | thread_list (ACE_Task_Base *task, ACE_thread_t thread_list[], size_t n) |
ssize_t | hthread_list (ACE_Task_Base *task, ACE_hthread_t hthread_list[], size_t n) |
ssize_t | thread_grp_list (int grp_id, ACE_thread_t thread_list[], size_t n) |
ssize_t | hthread_grp_list (int grp_id, ACE_hthread_t hthread_list[], size_t n) |
ssize_t | task_all_list (ACE_Task_Base *task_list[], size_t n) |
ssize_t | thread_all_list (ACE_thread_t thread_list[], size_t n) |
int | set_grp (ACE_Task_Base *task, int grp_id) |
Set group ids for a particular task. | |
int | get_grp (ACE_Task_Base *task, int &grp_id) |
Get group ids for a particular task. | |
size_t | count_threads (void) const |
int | thr_state (ACE_thread_t id, ACE_UINT32 &state) |
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) |
void | wait_on_exit (int dowait) |
int | wait_on_exit (void) |
void | dump (void) |
Dump the state of an object. | |
Static Public Member Functions | |
ACE_Thread_Manager * | instance (void) |
Get pointer to a process-wide . | |
ACE_Thread_Manager * | instance (ACE_Thread_Manager *) |
void | close_singleton (void) |
Delete the dynamically allocated Singleton. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Member Functions | |
ACE_Thread_Descriptor * | thread_desc_self (void) |
ACE_Thread_Descriptor * | thread_descriptor (ACE_thread_t) |
ACE_Thread_Descriptor * | hthread_descriptor (ACE_hthread_t) |
int | spawn_i (ACE_THR_FUNC func, void *arg, long flags, ACE_thread_t *=0, ACE_hthread_t *t_handle=0, long priority=ACE_DEFAULT_THREAD_PRIORITY, int grp_id=-1, void *stack=0, size_t stack_size=0, ACE_Task_Base *task=0) |
Create a new thread (must be called with locks held). | |
void | run_thread_exit_hooks (int i) |
Run the registered hooks when the thread exits. | |
ACE_Thread_Descriptor * | find_thread (ACE_thread_t t_id) |
ACE_Thread_Descriptor * | find_hthread (ACE_hthread_t h_id) |
ACE_Thread_Descriptor * | find_task (ACE_Task_Base *task, size_t slot=0) |
int | insert_thr (ACE_thread_t t_id, ACE_hthread_t, int grp_id=-1, long flags=0) |
Insert a thread in the table (checks for duplicates). | |
int | append_thr (ACE_thread_t t_id, ACE_hthread_t, ACE_UINT32, int grp_id, ACE_Task_Base *task=0, long flags=0, ACE_Thread_Descriptor *td=0) |
void | remove_thr (ACE_Thread_Descriptor *td, int close_handler) |
Remove thread from the table. | |
void | remove_thr_all (void) |
Remove all threads from the table. | |
int | check_state (ACE_UINT32 state, ACE_thread_t thread, int enable=1) |
int | apply_task (ACE_Task_Base *task, ACE_THR_MEMBER_FUNC, int=0) |
Apply to all members of the table that match the . | |
int | apply_grp (int grp_id, ACE_THR_MEMBER_FUNC func, int arg=0) |
Apply to all members of the table that match the . | |
int | apply_all (ACE_THR_MEMBER_FUNC, int=0) |
Apply to all members of the table. | |
int | join_thr (ACE_Thread_Descriptor *td, int=0) |
Join the thread described in . | |
int | resume_thr (ACE_Thread_Descriptor *td, int=0) |
Resume the thread described in . | |
int | suspend_thr (ACE_Thread_Descriptor *td, int=0) |
Suspend the thread described in . | |
int | kill_thr (ACE_Thread_Descriptor *td, int signum) |
Send signal to the thread described in . | |
int | cancel_thr (ACE_Thread_Descriptor *td, int async_cancel=0) |
Set the cancellation flag for the thread described in . | |
int | register_as_terminated (ACE_Thread_Descriptor *td) |
Register a thread as terminated and put it into the . | |
Static Protected Member Functions | |
int | set_thr_exit (ACE_TSS_TYPE(ACE_Thread_Exit)*ptr) |
Setting the static ACE_TSS_TYPE (ACE_Thread_Exit) *thr_exit_ pointer. | |
Protected Attributes | |
ACE_Double_Linked_List< ACE_Thread_Descriptor > | thr_list_ |
ACE_Double_Linked_List< ACE_Thread_Descriptor_Base > | terminated_thr_list_ |
Collect terminated but not yet joined thread entries. | |
ACE_Unbounded_Queue< ACE_Thread_Descriptor * > | thr_to_be_removed_ |
Collect pointers to thread descriptors of threads to be removed later. | |
int | grp_id_ |
Keeps track of the next group id to assign. | |
int | automatic_wait_ |
ACE_Thread_Mutex | lock_ |
Serialize access to the . | |
ACE_Condition_Thread_Mutex | zero_cond_ |
Keep track of when there are no more threads. | |
ACE_Locked_Free_List< ACE_Thread_Descriptor, ACE_SYNCH_MUTEX > | thread_desc_freelist_ |
Static Private Member Functions | |
ACE_TSS_TYPE (ACE_Thread_Exit)*thr_exit_ | |
Global ACE_TSS (ACE_Thread_Exit) object ptr. | |
Static Private Attributes | |
ACE_Thread_Manager * | thr_mgr_ = 0 |
Pointer to a process-wide . | |
int | delete_thr_mgr_ = 0 |
Must delete the if non-0. | |
Friends | |
class | ACE_Thread_Control |
class | ACE_Thread_Exit |
class | ACE_Thread_Descriptor |
This class allows operations on groups of threads atomically. The default behavior of thread manager is to wait on all threads under it's management when it gets destructed. Therefore, remember to remove a thread from thread manager if you don't want it to wait for the thread. There are also function to disable this default wait-on-exit behavior. However, if your program depends on turning this off to run correctly, you are probably doing something wrong. Rule of thumb, use ACE_Thread to manage your daemon threads. Notice that if there're threads live beyond the scope of , you are sure to have resource leaks in your program. Remember to wait on threads before exiting if that could happen in your programs.
Definition at line 393 of file Thread_Manager.h.
|
Definition at line 405 of file Thread_Manager.h. Referenced by apply_all(), apply_grp(), apply_task(), cancel_all(), cancel_grp(), cancel_task(), kill_grp(), kill_task(), resume_all(), resume_grp(), resume_task(), suspend_all(), suspend_grp(), and suspend_task(). |
|
These are the various states a thread managed by the ACE_Thread_Manager can be in.
Definition at line 410 of file Thread_Manager.h.
00411 { 00412 /// Uninitialized. 00413 ACE_THR_IDLE = 0x00000000, 00414 00415 /// Created but not yet running. 00416 ACE_THR_SPAWNED = 0x00000001, 00417 00418 /// Thread is active (naturally, we don't know if it's actually 00419 /// *running* because we aren't the scheduler...). 00420 ACE_THR_RUNNING = 0x00000002, 00421 00422 /// Thread is suspended. 00423 ACE_THR_SUSPENDED = 0x00000004, 00424 00425 /// Thread has been cancelled (which is an indiction that it needs to 00426 /// terminate...). 00427 ACE_THR_CANCELLED = 0x00000008, 00428 00429 /// Thread has shutdown, but the slot in the thread manager hasn't 00430 /// been reclaimed yet. 00431 ACE_THR_TERMINATED = 0x00000010, 00432 00433 /// Join operation has been invoked on the thread by thread manager. 00434 ACE_THR_JOINING = 0x10000000 00435 }; |
|
Initialization and termination methods. Internally, ACE_Thread_Manager keeps a freelist for caching resources it uses to keep track of managed threads (not the threads themselves.) prealloc, lwm, inc, determine the initial size, the low water mark, increment step, and high water mark of the freelist.
Definition at line 383 of file Thread_Manager.cpp. References ACE_FREE_LIST_WITH_POOL, and ACE_TRACE.
00387 : grp_id_ (1), 00388 automatic_wait_ (1) 00389 #if defined (ACE_HAS_THREADS) 00390 , zero_cond_ (lock_) 00391 #endif /* ACE_HAS_THREADS */ 00392 , thread_desc_freelist_ (ACE_FREE_LIST_WITH_POOL, 00393 prealloc, lwm, hwm, inc) 00394 { 00395 ACE_TRACE ("ACE_Thread_Manager::ACE_Thread_Manager"); 00396 } |
|
Definition at line 478 of file Thread_Manager.cpp. References ACE_TRACE, and close().
|
|
Global ACE_TSS (ACE_Thread_Exit) object ptr.
|
|
Append a thread in the table (adds at the end, growing the table if necessary). Definition at line 818 of file Thread_Manager.cpp. References ACE_hthread_t, ACE_NEW_RETURN, ACE_SET_BITS, ACE_TRACE, ACE_OS_Thread_Descriptor::flags_, ACE_Thread_Descriptor_Base::grp_id_, ACE_Thread_Descriptor::sync_, ACE_Thread_Descriptor_Base::task_, ACE_Thread_Descriptor_Base::thr_handle_, ACE_Thread_Descriptor_Base::thr_id_, thr_list_, ACE_Thread_Descriptor_Base::thr_state_, and ACE_Thread_Descriptor::tm_. Referenced by insert_thr(), and spawn_i().
00825 { 00826 ACE_TRACE ("ACE_Thread_Manager::append_thr"); 00827 ACE_Thread_Descriptor *thr_desc = 0; 00828 00829 if (td == 0) 00830 { 00831 ACE_NEW_RETURN (thr_desc, 00832 ACE_Thread_Descriptor, 00833 -1); 00834 #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT) 00835 thr_desc->tm_ = this; 00836 // Setup the Thread_Manager. 00837 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 00838 } 00839 else 00840 thr_desc = td; 00841 00842 thr_desc->thr_id_ = t_id; 00843 thr_desc->thr_handle_ = t_handle; 00844 thr_desc->grp_id_ = grp_id; 00845 thr_desc->task_ = task; 00846 thr_desc->flags_ = flags; 00847 00848 this->thr_list_.insert_head (thr_desc); 00849 ACE_SET_BITS (thr_desc->thr_state_, thr_state); 00850 thr_desc->sync_->release (); 00851 00852 return 0; 00853 } |
|
Apply to all members of the table.
Definition at line 1376 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_THR_MEMBER_FUNC, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty(), ACE_Double_Linked_List_Iterator_Base< T >::next(), remove_thr(), and thr_to_be_removed_. Referenced by cancel_all(), kill_all(), resume_all(), and suspend_all().
01377 { 01378 ACE_TRACE ("ACE_Thread_Manager::apply_all"); 01379 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01380 ACE_ASSERT (this->thr_to_be_removed_.is_empty ()); 01381 01382 int result = 0; 01383 01384 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01385 !iter.done (); 01386 iter.advance ()) 01387 if ((this->*func)(iter.next (), arg) == -1) 01388 result = -1; 01389 01390 // Must remove threads after we have traversed the thr_list_ to 01391 // prevent clobber thr_list_'s integrity. 01392 01393 if (! this->thr_to_be_removed_.is_empty ()) 01394 { 01395 // Save/restore errno. 01396 ACE_Errno_Guard error (errno); 01397 01398 for (ACE_Thread_Descriptor *td; 01399 this->thr_to_be_removed_.dequeue_head (td) != -1; 01400 ) 01401 this->remove_thr (td, 1); 01402 } 01403 01404 return result; 01405 } |
|
Apply to all members of the table that match the .
Definition at line 1302 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_THR_MEMBER_FUNC, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty(), ACE_Double_Linked_List_Iterator_Base< T >::next(), remove_thr(), and thr_to_be_removed_. Referenced by cancel_grp(), kill_grp(), resume_grp(), and suspend_grp().
01305 { 01306 ACE_TRACE ("ACE_Thread_Manager::apply_grp"); 01307 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_monx, this->lock_, -1)); 01308 ACE_ASSERT (this->thr_to_be_removed_.is_empty ()); 01309 01310 int result = 0; 01311 01312 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01313 !iter.done (); 01314 iter.advance ()) 01315 if (iter.next ()->grp_id_ == grp_id) 01316 if ((this->*func) (iter.next (), arg) == -1) 01317 result = -1; 01318 01319 // Must remove threads after we have traversed the thr_list_ to 01320 // prevent clobber thr_list_'s integrity. 01321 01322 if (! this->thr_to_be_removed_.is_empty ()) 01323 { 01324 // Save/restore errno. 01325 ACE_Errno_Guard error (errno); 01326 01327 for (ACE_Thread_Descriptor *td; 01328 this->thr_to_be_removed_.dequeue_head (td) != -1; 01329 ) 01330 this->remove_thr (td, 1); 01331 } 01332 01333 return result; 01334 } |
|
Apply to all members of the table that match the .
Definition at line 1839 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_THR_MEMBER_FUNC, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty(), ACE_Double_Linked_List_Iterator_Base< T >::next(), remove_thr(), and thr_to_be_removed_. Referenced by cancel_task(), kill_task(), resume_task(), and suspend_task().
01842 { 01843 ACE_TRACE ("ACE_Thread_Manager::apply_task"); 01844 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01845 ACE_ASSERT (this->thr_to_be_removed_.is_empty ()); 01846 01847 int result = 0; 01848 01849 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01850 !iter.done (); 01851 iter.advance ()) 01852 if (iter.next ()->task_ == task 01853 && (this->*func) (iter.next (), arg) == -1) 01854 result = -1; 01855 01856 // Must remove threads after we have traversed the thr_list_ to 01857 // prevent clobber thr_list_'s integrity. 01858 01859 if (! this->thr_to_be_removed_.is_empty ()) 01860 { 01861 // Save/restore errno. 01862 ACE_Errno_Guard error (errno); 01863 01864 for (ACE_Thread_Descriptor *td; 01865 this->thr_to_be_removed_.dequeue_head (td) != -1; 01866 ) 01867 this->remove_thr (td, 1); 01868 } 01869 01870 return result; 01871 } |
|
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. "cleanup_hook", for example, may delete the object (or array). If == 0, the will _NOT_ get cleanup at thread exit. You can use this to cancel the previously added at_exit. Definition at line 276 of file Thread_Manager.inl. References ACE_CLEANUP_FUNC, ACE_Thread_Descriptor::at_exit(), and thread_desc_self().
00279 { 00280 ACE_Thread_Descriptor *td = this->thread_desc_self (); 00281 if (td == 0) 00282 return -1; 00283 else 00284 return td->at_exit (object, 00285 cleanup_hook, 00286 param); 00287 } |
|
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 265 of file Thread_Manager.inl. References ACE_Thread_Descriptor::at_exit(), and thread_desc_self().
00266 { 00267 ACE_Thread_Descriptor *td = this->thread_desc_self (); 00268 if (td == 0) 00269 return -1; 00270 else 00271 return td->at_exit (at); 00272 } |
|
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 255 of file Thread_Manager.inl. References ACE_Thread_Descriptor::at_exit(), and thread_desc_self(). Referenced by ACE_OS_Thread_Adapter::invoke(), ACE_Thread_Adapter::invoke_i(), and ACE_Task_Base::svc_run().
00256 { 00257 ACE_Thread_Descriptor *td = this->thread_desc_self (); 00258 if (td == 0) 00259 return -1; 00260 else 00261 return td->at_exit (at); 00262 } |
|
Cancel a single thread. Definition at line 1148 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, and ACE_TRACE.
01149 { 01150 ACE_TRACE ("ACE_Thread_Manager::cancel"); 01151 ACE_EXECUTE_OP (this->cancel_thr, async_cancel); 01152 } |
|
Cancel's all the threads. Definition at line 1431 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_all(), and cancel_thr().
|
|
Cancel a group of threads. Definition at line 1367 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp(), and cancel_thr().
|
|
Cancel all threads in an . If is non-0, then asynchronously cancel these threads if the OS platform supports cancellation. Otherwise, perform a "cooperative" cancellation. Definition at line 1982 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task(), and cancel_thr().
01984 { 01985 ACE_TRACE ("ACE_Thread_Manager::cancel_task"); 01986 return this->apply_task (task, 01987 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::cancel_thr), 01988 async_cancel); 01989 } |
|
Set the cancellation flag for the thread described in .
Definition at line 1067 of file Thread_Manager.cpp. References ACE_SET_BITS, ACE_THR_CANCELLED, ACE_TRACE, ACE_Thread::cancel(), ACE_Thread_Descriptor_Base::thr_id_, and ACE_Thread_Descriptor_Base::thr_state_. Referenced by cancel_all(), cancel_grp(), and cancel_task().
01068 { 01069 ACE_TRACE ("ACE_Thread_Manager::cancel_thr"); 01070 // Must set the state first and then try to cancel the thread. 01071 ACE_SET_BITS (td->thr_state_, ACE_THR_CANCELLED); 01072 01073 if (async_cancel != 0) 01074 // Note that this call only does something relevant if the OS 01075 // platform supports asynchronous thread cancellation. Otherwise, 01076 // it's a no-op. 01077 return ACE_Thread::cancel (td->thr_id_); 01078 01079 return 0; 01080 } |
|
Efficiently check whether is in a particular . This call updates the TSS cache if possible to speed up subsequent searches. Definition at line 1164 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_FIND, ACE_GUARD_RETURN, ACE_LOG_MSG, ACE_TRACE, ACE_OS::thr_equal(), thr_state(), and ACE_Thread_Descriptor_Base::thr_state_. Referenced by testcancel(), testresume(), testsuspend(), and testterminate().
01167 { 01168 ACE_TRACE ("ACE_Thread_Manager::check_state"); 01169 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01170 01171 ACE_UINT32 thr_state; 01172 01173 int self_check = ACE_OS::thr_equal (id, ACE_OS::thr_self ()); 01174 01175 // If we're checking the state of our thread, try to get the cached 01176 // value out of TSS to avoid lookup. 01177 if (self_check) 01178 { 01179 ACE_Thread_Descriptor *desc = ACE_LOG_MSG->thr_desc (); 01180 if (desc == 0) 01181 return 0; // Always return false. 01182 thr_state = desc->thr_state_; 01183 } 01184 else 01185 { 01186 // Not calling from self, have to look it up from the list. 01187 ACE_FIND (this->find_thread (id), ptr); 01188 if (ptr == 0) 01189 return 0; 01190 thr_state = ptr->thr_state_; 01191 } 01192 if (enable) 01193 return ACE_BIT_ENABLED (thr_state, state); 01194 01195 return ACE_BIT_DISABLED (thr_state, state); 01196 } |
|
Release all resources. By default, this method will wait till all threads exit. However, when called from , most global resources are destroyed and thus, we don't try to wait but just clean up the thread descriptor list. Definition at line 461 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, automatic_wait_, remove_thr_all(), and wait(). Referenced by close_singleton(), and ~ACE_Thread_Manager().
00462 { 00463 ACE_TRACE ("ACE_Thread_Manager::close"); 00464 00465 // Clean up the thread descriptor list. 00466 if (this->automatic_wait_) 00467 this->wait (0, 1); 00468 else 00469 { 00470 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 00471 00472 this->remove_thr_all (); 00473 } 00474 00475 return 0; 00476 } |
|
Delete the dynamically allocated Singleton.
Definition at line 438 of file Thread_Manager.cpp. References ACE_GUARD, ACE_TRACE, ACE_Thread_Exit::cleanup(), close(), delete_thr_mgr_, and thr_mgr_. Referenced by ACE_Object_Manager::fini().
00439 { 00440 ACE_TRACE ("ACE_Thread_Manager::close_singleton"); 00441 00442 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, 00443 *ACE_Static_Object_Lock::instance ())); 00444 00445 if (ACE_Thread_Manager::delete_thr_mgr_) 00446 { 00447 // First, we clean up the thread descriptor list. 00448 ACE_Thread_Manager::thr_mgr_->close (); 00449 delete ACE_Thread_Manager::thr_mgr_; 00450 ACE_Thread_Manager::thr_mgr_ = 0; 00451 ACE_Thread_Manager::delete_thr_mgr_ = 0; 00452 } 00453 00454 ACE_Thread_Exit::cleanup (ACE_Thread_Manager::thr_exit_); 00455 } |
|
Return a count of the current number of threads active in the . Definition at line 315 of file Thread_Manager.inl. References thr_list_.
00316 { 00317 return this->thr_list_.size (); 00318 } |
|
Dump the state of an object.
Definition at line 72 of file Thread_Manager.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_GUARD, ACE_LIB_TEXT, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), grp_id_, LM_DEBUG, ACE_Double_Linked_List_Iterator_Base< T >::next(), and thr_list_.
00073 { 00074 #if defined (ACE_HAS_DUMP) 00075 ACE_TRACE ("ACE_Thread_Manager::dump"); 00076 // Cast away const-ness of this in order to use its non-const lock_. 00077 ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, 00078 ((ACE_Thread_Manager *) this)->lock_)); 00079 00080 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00081 00082 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ngrp_id_ = %d"), this->grp_id_)); 00083 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncurrent_count_ = %d"), this->thr_list_.size ())); 00084 00085 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 00086 !iter.done (); 00087 iter.advance ()) 00088 iter.next ()->dump (); 00089 00090 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00091 #endif /* ACE_HAS_DUMP */ 00092 } |
|
Called to clean up when a thread exits.
Definition at line 1608 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_hthread_t, ACE_SET_BITS, ACE_THR_JOINING, ACE_THR_TERMINATED, ACE_thread_t, ACE_TRACE, ACE_Cleanup_Info::cleanup_hook_, ACE_Thread_Descriptor::cleanup_info_, ACE_Thread::exit(), find_hthread(), find_thread(), ACE_OS_Thread_Descriptor::flags_, ACE_Thread_Exit::instance(), ACE_Cleanup_Info::object_, ACE_Cleanup_Info::param_, register_as_terminated(), remove_thr(), ACE_Thread_Descriptor::terminate(), ACE_OS::thr_self(), and ACE_Thread_Descriptor_Base::thr_state_. Referenced by ACE_Thread_Control::exit().
01609 { 01610 ACE_TRACE ("ACE_Thread_Manager::exit"); 01611 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT) 01612 int close_handle = 0; 01613 #endif /* ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 01614 01615 #if defined (ACE_WIN32) 01616 // Remove detached thread handle. 01617 01618 if (do_thr_exit) 01619 { 01620 #if 0 01621 // @@ This callback is now taken care of by TSS_Cleanup. Do we 01622 // need it anymore? 01623 01624 // On Win32, if we really wants to exit from a thread, we must 01625 // first clean up the thread specific storage. By doing so, 01626 // ACE_Thread_Manager::exit will be called again with 01627 // do_thr_exit = 0 and cleaning up the ACE_Cleanup_Info (but not 01628 // exiting the thread.) After the following call returns, we 01629 // are safe to exit this thread. 01630 delete ACE_Thread_Exit::instance (); 01631 #endif /* 0 */ 01632 ACE_Thread::exit (status); 01633 } 01634 #endif /* ACE_WIN32 */ 01635 01636 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT) 01637 ACE_Cleanup_Info cleanup_info; 01638 01639 // Just hold onto the guard while finding this thread's id and 01640 // copying the exit hook. 01641 { 01642 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0)); 01643 01644 // Find the thread id, but don't use the cache. It might have been 01645 // deleted already. 01646 #if defined (ACE_VXWORKS) && !defined (ACE_HAS_PTHREADS) 01647 ACE_hthread_t id; 01648 ACE_OS::thr_self (id); 01649 ACE_Thread_Descriptor *td = this->find_hthread (id); 01650 #else /* ! ACE_VXWORKS */ 01651 ACE_thread_t id = ACE_OS::thr_self (); 01652 ACE_Thread_Descriptor *td = this->find_thread (id); 01653 #endif /* ! ACE_VXWORKS */ 01654 01655 // Locate thread id. 01656 if (td != 0) 01657 { 01658 // @@ Currently, we have just one hook. This should clearly 01659 // be generalized to support an arbitrary number of hooks. 01660 01661 if (td->cleanup_info_.cleanup_hook_ != 0) 01662 { 01663 // Copy the hook so that we can call it after releasing 01664 // the guard. 01665 cleanup_info = td->cleanup_info_; 01666 td->cleanup_info_.cleanup_hook_ = 0; 01667 } 01668 01669 #if !defined (ACE_VXWORKS) 01670 // Threads created with THR_DAEMON shouldn't exist here, but 01671 // just to be safe, let's put it here. 01672 01673 if (ACE_BIT_DISABLED (td->thr_state_, ACE_THR_JOINING)) 01674 if (ACE_BIT_DISABLED (td->flags_, THR_DETACHED | THR_DAEMON) 01675 || ACE_BIT_ENABLED (td->flags_, THR_JOINABLE)) 01676 { 01677 // Mark thread as terminated. 01678 ACE_SET_BITS (td->thr_state_, ACE_THR_TERMINATED); 01679 this->register_as_terminated (td); 01680 // Must copy the information here because td will be "freed" below. 01681 } 01682 #if defined (ACE_WIN32) 01683 else 01684 { 01685 close_handle = 1; 01686 } 01687 #endif /* ACE_WIN32 */ 01688 #endif /* ! ACE_VXWORKS */ 01689 01690 // Remove thread descriptor from the table. 01691 this->remove_thr (td, close_handle); 01692 } 01693 // Release the guard. 01694 } 01695 01696 // Call the cleanup hook. 01697 if (cleanup_info.cleanup_hook_ != 0) 01698 (*cleanup_info.cleanup_hook_) (cleanup_info.object_, 01699 cleanup_info.param_); 01700 #else /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 01701 // Just hold onto the guard while finding this thread's id and 01702 { 01703 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0)); 01704 01705 // Find the thread id, but don't use the cache. It might have been 01706 // deleted already. 01707 #if defined (ACE_VXWORKS) && !defined (ACE_HAS_PTHREADS) 01708 ACE_hthread_t id; 01709 ACE_OS::thr_self (id); 01710 ACE_Thread_Descriptor* td = this->find_hthread (id); 01711 #else /* ! ACE_VXWORKS */ 01712 ACE_thread_t id = ACE_OS::thr_self (); 01713 ACE_Thread_Descriptor* td = this->find_thread (id); 01714 #endif /* ! ACE_VXWORKS */ 01715 if (td != 0) 01716 { 01717 // @@ We call Thread_Descriptor terminate this realize the cleanup 01718 // process itself. 01719 td->terminate(); 01720 } 01721 } 01722 01723 01724 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 01725 01726 if (do_thr_exit) 01727 { 01728 ACE_Thread::exit (status); 01729 // On reasonable systems <ACE_Thread::exit> should not return. 01730 // However, due to horrible semantics with Win32 thread-specific 01731 // storage this call can return (don't ask...). 01732 } 01733 01734 return 0; 01735 } |
|
Locate the index of the table slot occupied by . Returns -1 if is not in the table doesn't contain . Definition at line 858 of file Thread_Manager.cpp. References ACE_hthread_t, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Double_Linked_List_Iterator_Base< T >::next(), and ACE_OS::thr_cmp(). Referenced by exit(), and insert_thr().
00859 { 00860 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 00861 !iter.done (); 00862 iter.advance ()) 00863 if (ACE_OS::thr_cmp (iter.next ()->thr_handle_, h_id)) 00864 return iter.next (); 00865 00866 return 0; 00867 } |
|
Locate the thread descriptor address of the list occupied by . Returns 0 if is not in the table doesn't contain . Definition at line 1996 of file Thread_Manager.cpp. References ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next(). Referenced by num_tasks_in_group(), and task_list().
01997 { 01998 ACE_TRACE ("ACE_Thread_Manager::find_task"); 01999 02000 size_t i = 0; 02001 02002 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02003 !iter.done (); 02004 iter.advance ()) 02005 { 02006 if (i >= slot) 02007 break; 02008 02009 if (task == iter.next ()->task_) 02010 return iter.next (); 02011 02012 i++; 02013 } 02014 02015 return 0; 02016 } |
|
Locate the index of the table slot occupied by . Returns -1 if is not in the table doesn't contain . Definition at line 873 of file Thread_Manager.cpp. References ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Double_Linked_List_Iterator_Base< T >::next(), and ACE_OS::thr_equal(). Referenced by exit(), insert_thr(), and thread_desc_self().
00874 { 00875 ACE_TRACE ("ACE_Thread_Manager::find_thread"); 00876 00877 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 00878 !iter.done (); 00879 iter.advance ()) 00880 if (ACE_OS::thr_equal (iter.next ()->thr_id_, t_id)) 00881 return iter.next (); 00882 return 0; 00883 } |
|
Get group ids for a particular task.
Definition at line 2317 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, and ACE_TRACE.
02318 { 02319 ACE_TRACE ("ACE_Thread_Manager::get_grp"); 02320 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02321 02322 ACE_FIND (this->find_task (task), ptr); 02323 grp_id = ptr->grp_id_; 02324 return 0; 02325 } |
|
Get group ids for a particular thread id.
Definition at line 1269 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, and ACE_TRACE.
01270 { 01271 ACE_TRACE ("ACE_Thread_Manager::get_grp"); 01272 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01273 01274 ACE_FIND (this->find_thread (t_id), ptr); 01275 01276 if (ptr) 01277 grp_id = ptr->grp_id_; 01278 else 01279 return -1; 01280 return 0; 01281 } |
|
Return a pointer to the thread's Thread_Descriptor, 0 if fail. Definition at line 354 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, ACE_hthread_t, and ACE_TRACE.
00355 { 00356 ACE_TRACE ("ACE_Thread_Manager::hthread_descriptor"); 00357 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0)); 00358 00359 ACE_FIND (this->find_hthread (thr_handle), ptr); 00360 return ptr; 00361 } |
|
Returns in a list of up to thread handles in a group . The caller must allocate memory for . Definition at line 2275 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02278 { 02279 ACE_TRACE ("ACE_Thread_Manager::hthread_grp_list"); 02280 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02281 02282 size_t hthread_count = 0; 02283 02284 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02285 !iter.done (); 02286 iter.advance ()) 02287 { 02288 if (hthread_count >= n) 02289 break; 02290 02291 if (iter.next ()->grp_id_ == grp_id) 02292 { 02293 hthread_list[hthread_count] = iter.next ()->thr_handle_; 02294 hthread_count++; 02295 } 02296 } 02297 02298 return hthread_count; 02299 } |
|
Returns in a list of up to thread handles in an . The caller must allocate memory for . In case of an error, -1 is returned. If no requested values are found, 0 is returned, otherwise correct number of retrieved values are returned. Definition at line 2219 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02222 { 02223 ACE_TRACE ("ACE_Thread_Manager::hthread_list"); 02224 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02225 02226 size_t hthread_count = 0; 02227 02228 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02229 !iter.done (); 02230 iter.advance ()) 02231 { 02232 if (hthread_count >= n) 02233 break; 02234 02235 if (iter.next ()->task_ == task) 02236 { 02237 hthread_list[hthread_count] = iter.next ()->thr_handle_; 02238 hthread_count++; 02239 } 02240 } 02241 02242 return hthread_count; 02243 } |
|
Check if the thread is managed by the thread manager. Return true if the thread is found, false otherwise. Definition at line 1237 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Double_Linked_List_Iterator_Base< T >::next(), and ACE_OS::thr_cmp().
01238 { 01239 ACE_TRACE ("ACE_Thread_Manager::hthread_within"); 01240 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_monx, this->lock_, -1)); 01241 01242 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01243 !iter.done (); 01244 iter.advance ()) 01245 if (ACE_OS::thr_cmp(iter.next ()->thr_handle_, handle)) 01246 return 1; 01247 01248 return 0; 01249 } |
|
Insert a thread in the table (checks for duplicates).
Definition at line 889 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_THR_SPAWNED, ACE_TRACE, append_thr(), find_hthread(), and find_thread(). Referenced by ACE_Thread_Control::ACE_Thread_Control(), and ACE_Thread_Control::insert().
00893 { 00894 ACE_TRACE ("ACE_Thread_Manager::insert_thr"); 00895 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 00896 00897 // Check for duplicates and bail out if we're already registered... 00898 #if defined (ACE_VXWORKS) && !defined (ACE_HAS_PTHREADS) 00899 if (this->find_hthread (t_handle) != 0 ) 00900 return -1; 00901 #else /* ! ACE_VXWORKS */ 00902 if (this->find_thread (t_id) != 0 ) 00903 return -1; 00904 #endif /* ! ACE_VXWORKS */ 00905 00906 if (grp_id == -1) 00907 grp_id = this->grp_id_++; 00908 00909 if (this->append_thr (t_id, 00910 t_handle, 00911 ACE_THR_SPAWNED, 00912 grp_id, 00913 0, 00914 flags) == -1) 00915 return -1; 00916 00917 return grp_id; 00918 } |
|
Set pointer to a process-wide and return existing pointer. Definition at line 423 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, delete_thr_mgr_, and thr_mgr_.
00424 { 00425 ACE_TRACE ("ACE_Thread_Manager::instance"); 00426 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00427 *ACE_Static_Object_Lock::instance (), 0)); 00428 00429 ACE_Thread_Manager *t = ACE_Thread_Manager::thr_mgr_; 00430 // We can't safely delete it since we don't know who created it! 00431 ACE_Thread_Manager::delete_thr_mgr_ = 0; 00432 00433 ACE_Thread_Manager::thr_mgr_ = tm; 00434 return t; 00435 } |
|
Get pointer to a process-wide .
Definition at line 400 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, delete_thr_mgr_, and thr_mgr_. Referenced by ACE_Schedule_All_Threaded_Strategy< SVC_HANDLER >::ACE_Schedule_All_Threaded_Strategy(), and ACE_Task_Base::activate().
00401 { 00402 ACE_TRACE ("ACE_Thread_Manager::instance"); 00403 00404 if (ACE_Thread_Manager::thr_mgr_ == 0) 00405 { 00406 // Perform Double-Checked Locking Optimization. 00407 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00408 *ACE_Static_Object_Lock::instance (), 0)); 00409 00410 if (ACE_Thread_Manager::thr_mgr_ == 0) 00411 { 00412 ACE_NEW_RETURN (ACE_Thread_Manager::thr_mgr_, 00413 ACE_Thread_Manager, 00414 0); 00415 ACE_Thread_Manager::delete_thr_mgr_ = 1; 00416 } 00417 } 00418 00419 return ACE_Thread_Manager::thr_mgr_; 00420 } |
|
Join a thread specified by . Do not wait on a detached thread.
Definition at line 1439 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_SET_BITS, ACE_THR_JOINING, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator< T >::advance_and_remove(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Thread::join(), ACE_Double_Linked_List_Iterator_Base< T >::next(), ACE_OS::thr_equal(), and ACE_Thread_Descriptor_Base::thr_handle_.
01440 { 01441 ACE_TRACE ("ACE_Thread_Manager::join"); 01442 01443 ACE_Thread_Descriptor_Base tdb; 01444 int found = 0; 01445 01446 { 01447 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01448 01449 #if !defined (ACE_VXWORKS) 01450 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor_Base> biter (this->terminated_thr_list_); 01451 !biter.done (); 01452 biter.advance ()) 01453 if (ACE_OS::thr_equal (biter.next ()->thr_id_, tid)) 01454 { 01455 ACE_Thread_Descriptor_Base *tdb = biter.advance_and_remove (0); 01456 # if defined (_AIX) 01457 // The AIX xlC compiler does not match the proper function here - it 01458 // confuses ACE_Thread::join(ACE_thread_t, ACE_thread_t *, void **=0) and 01459 // ACE_Thread::join(ACE_hthread_t, void **=0). At least at 3.1.4.7 and .8. 01460 // The 2nd arg is ignored for pthreads anyway. 01461 01462 // And, g++ on AIX needs the three-arg thr_join, also, to pick up the 01463 // proper version from the AIX libraries. 01464 if (ACE_Thread::join (tdb->thr_handle_, 01465 &tdb->thr_handle_, 01466 status) == -1) 01467 # else /* ! _AIX */ 01468 if (ACE_Thread::join (tdb->thr_handle_, status) == -1) 01469 # endif /* ! _AIX */ 01470 return -1; 01471 01472 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH) 01473 // Must explicitly detach threads. Threads without THR_DETACHED 01474 // were detached in ACE_OS::thr_create (). 01475 ::pthread_detach (&tdb->thr_handle_); 01476 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */ 01477 01478 delete tdb; 01479 return 0; 01480 // return immediately if we've found the thread we want to join. 01481 } 01482 #endif /* !ACE_VXWORKS */ 01483 01484 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01485 !iter.done (); 01486 iter.advance ()) 01487 // If threads are created as THR_DETACHED or THR_DAEMON, we 01488 // can't help much. 01489 if (ACE_OS::thr_equal (iter.next ()->thr_id_,tid) && 01490 (ACE_BIT_DISABLED (iter.next ()->flags_, THR_DETACHED | THR_DAEMON) 01491 || ACE_BIT_ENABLED (iter.next ()->flags_, THR_JOINABLE))) 01492 { 01493 tdb = *iter.next (); 01494 ACE_SET_BITS (iter.next ()->thr_state_, ACE_THR_JOINING); 01495 found = 1; 01496 break; 01497 } 01498 01499 if (found == 0) 01500 return -1; 01501 // Didn't find the thread we want or the thread is not joinable. 01502 } 01503 01504 # if defined (_AIX) 01505 // The AIX xlC compiler does not match the proper function here - it 01506 // confuses ACE_Thread::join(ACE_thread_t, ACE_thread_t *, void **=0) and 01507 // ACE_Thread::join(ACE_hthread_t, void **=0). At least at 3.1.4.7 and .8. 01508 // The 2nd arg is ignored for pthreads anyway. 01509 01510 // And, g++ on AIX needs the three-arg thr_join, also, to pick up the 01511 // proper version from the AIX libraries. 01512 if (ACE_Thread::join (tdb.thr_handle_, &tdb.thr_handle_, status) == -1) 01513 # else /* ! _AIX */ 01514 if (ACE_Thread::join (tdb.thr_handle_, status) == -1) 01515 # endif /* ! _AIX */ 01516 return -1; 01517 01518 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH) 01519 // Must explicitly detach threads. Threads without THR_DETACHED 01520 // were detached in ACE_OS::thr_create (). 01521 01522 ::pthread_detach (&tdb.thr_handle_); 01523 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */ 01524 return 0; 01525 } |
|
Join the thread described in .
Definition at line 1015 of file Thread_Manager.cpp. References ACE_TRACE, ACE_Thread::join(), and ACE_Thread_Descriptor_Base::thr_handle_.
01016 { 01017 ACE_TRACE ("ACE_Thread_Manager::join_thr"); 01018 int result = ACE_Thread::join (td->thr_handle_); 01019 if (result != 0) 01020 { 01021 // Since the thread are being joined, we should 01022 // let it remove itself from the list. 01023 01024 // this->remove_thr (td); 01025 errno = result; 01026 return -1; 01027 } 01028 01029 return 0; 01030 } |
|
Definition at line 1157 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, and ACE_TRACE.
01158 { 01159 ACE_TRACE ("ACE_Thread_Manager::kill"); 01160 ACE_EXECUTE_OP (this->kill_thr, signum); 01161 } |
|
Send to all stopped threads. Not supported on platforms that do not have advanced signal support, such as Win32. Send the to a single thread. Not supported on platforms that do not have advanced signal support, such as Win32. Send to a group of threads, not supported on platforms that do not have advanced signal support, such as Win32. Definition at line 1424 of file Thread_Manager.cpp. References ACE_TRACE, apply_all(), and kill_thr().
|
|
Definition at line 1357 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp(), and kill_thr().
|
|
Send a signal to all threads in an . Definition at line 1973 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task(), and kill_thr().
01974 { 01975 ACE_TRACE ("ACE_Thread_Manager::kill_task"); 01976 return this->apply_task (task, 01977 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::kill_thr)); 01978 } |
|
Send signal to the thread described in .
Definition at line 1083 of file Thread_Manager.cpp. References ACE_thread_t, ACE_TRACE, ENOTSUP, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::enqueue_tail(), ACE_Thread::kill(), ACE_Thread_Descriptor_Base::thr_id_, and thr_to_be_removed_. Referenced by kill_all(), kill_grp(), and kill_task().
01084 { 01085 ACE_TRACE ("ACE_Thread_Manager::kill_thr"); 01086 01087 ACE_thread_t tid = td->thr_id_; 01088 #if defined (ACE_VXWORKS) && !defined (ACE_HAS_PTHREADS) 01089 // Skip over the ID-allocated marker, if present. 01090 tid += tid[0] == ACE_THR_ID_ALLOCATED ? 1 : 0; 01091 #endif /* ACE_VXWORKS */ 01092 01093 int const result = ACE_Thread::kill (tid, signum); 01094 01095 if (result != 0) 01096 { 01097 // Only remove a thread from us when there is a "real" error. 01098 if (errno != ENOTSUP) 01099 this->thr_to_be_removed_.enqueue_tail (td); 01100 01101 return -1; 01102 } 01103 01104 return 0; 01105 } |
|
Returns the number of in a group.
Definition at line 2021 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), find_task(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02022 { 02023 ACE_TRACE ("ACE_Thread_Manager::num_tasks_in_group"); 02024 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02025 02026 int tasks_count = 0; 02027 size_t i = 0; 02028 02029 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02030 !iter.done (); 02031 iter.advance ()) 02032 { 02033 if (iter.next ()->grp_id_ == grp_id 02034 && this->find_task (iter.next ()->task_, i) == 0 02035 && iter.next ()->task_ != 0) 02036 tasks_count++; 02037 02038 i++; 02039 } 02040 return tasks_count; 02041 } |
|
Returns the number of threads in an .
Definition at line 2046 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02047 { 02048 ACE_TRACE ("ACE_Thread_Manager::num_threads_in_task"); 02049 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02050 02051 int threads_count = 0; 02052 02053 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02054 !iter.done (); 02055 iter.advance ()) 02056 if (iter.next ()->task_ == task) 02057 threads_count++; 02058 02059 return threads_count; 02060 } |
|
No-op. Currently unused.
Definition at line 247 of file Thread_Manager.inl.
00248 { 00249 // Currently no-op. 00250 return 0; 00251 } |
|
Register a thread as terminated and put it into the .
Definition at line 302 of file Thread_Manager.inl. References ACE_NEW_RETURN, and terminated_thr_list_. Referenced by exit(), and ACE_Thread_Descriptor::terminate().
00303 { 00304 #if defined (ACE_VXWORKS) 00305 ACE_UNUSED_ARG (td); 00306 #else /* ! ACE_VXWORKS */ 00307 ACE_Thread_Descriptor_Base *tdb = 0; 00308 ACE_NEW_RETURN (tdb, ACE_Thread_Descriptor_Base (*td), -1); 00309 this->terminated_thr_list_.insert_tail (tdb); 00310 #endif /* ! ACE_VXWORKS */ 00311 return 0; 00312 } |
|
Remove thread from the table.
Definition at line 949 of file Thread_Manager.cpp. References ACE_thread_t, ACE_TRACE, ACE_Locked_Free_List< ACE_Thread_Descriptor, ACE_SYNCH_MUTEX >::add(), ACE_Condition_Thread_Mutex::broadcast(), ACE_Thread_Descriptor::self(), ACE_Thread_Descriptor_Base::thr_handle_, thr_list_, thread_desc_freelist_, ACE_Thread_Descriptor::tm_, and zero_cond_. Referenced by apply_all(), apply_grp(), apply_task(), exit(), remove_thr_all(), ACE_Thread_Descriptor::terminate(), and wait().
00951 { 00952 ACE_TRACE ("ACE_Thread_Manager::remove_thr"); 00953 00954 #if defined (ACE_VXWORKS) && !defined (ACE_HAS_PTHREADS) 00955 ACE_thread_t tid = td->self (); 00956 #endif /* ACE_VXWORKS */ 00957 00958 #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT) 00959 td->tm_ = 0; 00960 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */ 00961 this->thr_list_.remove (td); 00962 00963 #if defined (ACE_VXWORKS) && !defined (ACE_HAS_PTHREADS) 00964 // Delete the thread ID, if the ACE_Thread_Manager allocated it. 00965 if (tid && tid[0] == ACE_THR_ID_ALLOCATED) 00966 { 00967 delete [] tid; 00968 } 00969 #endif /* ACE_VXWORKS */ 00970 00971 #if defined (ACE_WIN32) 00972 if (close_handler != 0) 00973 ::CloseHandle (td->thr_handle_); 00974 #else 00975 ACE_UNUSED_ARG (close_handler); 00976 #endif /* ACE_WIN32 */ 00977 00978 this->thread_desc_freelist_.add (td); 00979 00980 #if defined (ACE_HAS_THREADS) 00981 // Tell all waiters when there are no more threads left in the pool. 00982 if (this->thr_list_.size () == 0) 00983 this->zero_cond_.broadcast (); 00984 #endif /* ACE_HAS_THREADS */ 00985 } |
|
Remove all threads from the table.
Definition at line 990 of file Thread_Manager.cpp. References remove_thr(), and thr_list_. Referenced by close(), and wait().
00991 { 00992 ACE_Thread_Descriptor *td = 0; 00993 00994 while ((td = this->thr_list_.delete_head ()) != 0) 00995 { 00996 this->remove_thr (td, 1); 00997 } 00998 } |
|
Resume a single thread.
Definition at line 1139 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, and ACE_TRACE.
01140 { 01141 ACE_TRACE ("ACE_Thread_Manager::resume"); 01142 ACE_EXECUTE_OP (this->resume_thr, 0); 01143 } |
|
Resume all stopped threads.
Definition at line 1410 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_all(), and resume_thr(). Referenced by ACE_Schedule_All_Threaded_Strategy< SVC_HANDLER >::resume().
|
|
Resume a group of threads.
Definition at line 1347 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp(), and resume_thr().
|
|
Resume all threads in an ACE_Task. Definition at line 1963 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task(), and resume_thr(). Referenced by ACE_Task_Base::resume().
01964 { 01965 ACE_TRACE ("ACE_Thread_Manager::resume_task"); 01966 return this->apply_task (task, 01967 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::resume_thr)); 01968 } |
|
Resume the thread described in .
Definition at line 1050 of file Thread_Manager.cpp. References ACE_CLR_BITS, ACE_THR_SUSPENDED, ACE_TRACE, ENOTSUP, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::enqueue_tail(), ACE_Thread::resume(), ACE_Thread_Descriptor_Base::thr_handle_, ACE_Thread_Descriptor_Base::thr_state_, and thr_to_be_removed_. Referenced by resume_all(), resume_grp(), and resume_task().
01051 { 01052 ACE_TRACE ("ACE_Thread_Manager::resume_thr"); 01053 01054 int const result = ACE_Thread::resume (td->thr_handle_); 01055 if (result == -1) { 01056 if (errno != ENOTSUP) 01057 this->thr_to_be_removed_.enqueue_tail (td); 01058 return -1; 01059 } 01060 else { 01061 ACE_CLR_BITS (td->thr_state_, ACE_THR_SUSPENDED); 01062 return 0; 01063 } 01064 } |
|
Run the registered hooks when the thread exits.
Definition at line 923 of file Thread_Manager.cpp. References ACE_TRACE, ACE_Cleanup_Info::cleanup_hook_, ACE_Thread_Descriptor::cleanup_info_, ACE_Cleanup_Info::object_, ACE_Cleanup_Info::param_, and thread_desc_self().
00924 { 00925 #if 0 // currently unused! 00926 ACE_TRACE ("ACE_Thread_Manager::run_thread_exit_hooks"); 00927 00928 // @@ Currently, we have just one hook. This should clearly be 00929 // generalized to support an arbitrary number of hooks. 00930 00931 ACE_Thread_Descriptor *td = this->thread_desc_self (); 00932 if (td != 0 && td->cleanup_info.cleanup_hook_ != 0) 00933 { 00934 (*td->cleanup_info_.cleanup_hook_) 00935 (td->cleanup_info_.object_, 00936 td->cleanup_info_.param_); 00937 00938 td->cleanup_info_.cleanup_hook_ = 0; 00939 } 00940 ACE_UNUSED_ARG (i); 00941 #else 00942 ACE_UNUSED_ARG (i); 00943 #endif /* 0 */ 00944 } |
|
Set group ids for a particular task.
Definition at line 2302 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02303 { 02304 ACE_TRACE ("ACE_Thread_Manager::set_grp"); 02305 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02306 02307 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02308 !iter.done (); 02309 iter.advance ()) 02310 if (iter.next ()->task_ == task) 02311 iter.next ()->grp_id_ = grp_id; 02312 02313 return 0; 02314 } |
|
Set group ids for a particular thread id.
Definition at line 1286 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, and ACE_TRACE. Referenced by ACE_Task_Base::grp_id().
01287 { 01288 ACE_TRACE ("ACE_Thread_Manager::set_grp"); 01289 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01290 01291 ACE_FIND (this->find_thread (t_id), ptr); 01292 if (ptr) 01293 ptr->grp_id_ = grp_id; 01294 else 01295 return -1; 01296 return 0; 01297 } |
|
Setting the static ACE_TSS_TYPE (ACE_Thread_Exit) *thr_exit_ pointer.
Referenced by ACE_Thread_Exit::instance(). |
|
Create a new thread, which executes with argument . Returns: on success a unique group id that can be used to control other threads added to the same group. On failure, returns -1. Definition at line 698 of file Thread_Manager.cpp. References ACE_CLR_BITS, ACE_DEFAULT_THREAD_PRIORITY, ACE_GUARD_RETURN, ACE_hthread_t, ACE_TRACE, and spawn_i(). Referenced by ACE_Event_Handler::register_stdin_handler().
00707 { 00708 ACE_TRACE ("ACE_Thread_Manager::spawn"); 00709 00710 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 00711 00712 if (grp_id == -1) 00713 grp_id = this->grp_id_++; // Increment the group id. 00714 00715 if (priority != ACE_DEFAULT_THREAD_PRIORITY) 00716 ACE_CLR_BITS (flags, THR_INHERIT_SCHED); 00717 00718 if (this->spawn_i (func, 00719 args, 00720 flags, 00721 t_id, 00722 t_handle, 00723 priority, 00724 grp_id, 00725 stack, 00726 stack_size, 00727 0) == -1) 00728 return -1; 00729 00730 return grp_id; 00731 } |
|
Create a new thread (must be called with locks held).
Definition at line 564 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_BIT_DISABLED, ACE_hthread_t, ACE_NEW_RETURN, ACE_THR_SPAWNED, ACE_THREAD_ADAPTER_NAME, ACE_thread_t, ACE_TRACE, append_thr(), ACE_Auto_Basic_Ptr< X >::get(), ACE_Auto_Basic_Ptr< X >::release(), ACE_Auto_Basic_Ptr< X >::reset(), and ACE_Thread::spawn(). Referenced by spawn(), and spawn_n().
00574 { 00575 // First, threads created by Thread Manager should not be daemon threads. 00576 // Using assertion is probably a bit too strong. However, it helps 00577 // finding this kind of error as early as possible. Perhaps we can replace 00578 // assertion by returning error. 00579 ACE_ASSERT (ACE_BIT_DISABLED (flags, THR_DAEMON)); 00580 00581 // Create a new thread running <func>. *Must* be called with the 00582 // <lock_> held... 00583 // Get a "new" Thread Descriptor from the freelist. 00584 auto_ptr<ACE_Thread_Descriptor> new_thr_desc (this->thread_desc_freelist_.remove ()); 00585 00586 // Reset thread descriptor status 00587 new_thr_desc->reset (this); 00588 00589 ACE_Thread_Adapter *thread_args = 0; 00590 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) 00591 ACE_NEW_RETURN (thread_args, 00592 ACE_Thread_Adapter (func, 00593 args, 00594 (ACE_THR_C_FUNC) ACE_THREAD_ADAPTER_NAME, 00595 this, 00596 new_thr_desc.get (), 00597 ACE_OS_Object_Manager::seh_except_selector(), 00598 ACE_OS_Object_Manager::seh_except_handler()), 00599 -1); 00600 # else 00601 ACE_NEW_RETURN (thread_args, 00602 ACE_Thread_Adapter (func, 00603 args, 00604 (ACE_THR_C_FUNC) ACE_THREAD_ADAPTER_NAME, 00605 this, 00606 new_thr_desc.get ()), 00607 -1); 00608 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ 00609 00610 ACE_TRACE ("ACE_Thread_Manager::spawn_i"); 00611 ACE_hthread_t thr_handle; 00612 00613 #if defined (ACE_VXWORKS) && !defined (ACE_HAS_PTHREADS) 00614 // On VxWorks, ACE_thread_t is char *. If t_id is 0, allocate space 00615 // for ACE_OS::thr_create () to store the task name. If t_id is not 00616 // 0, and it doesn't point to a 0 char *, then the non-zero char * 00617 // will be used for the task name in ACE_OS::thr_create (). If t_id 00618 // is not 0, but does point to a 0 char *, the t_id will be set to 00619 // point to the task name in the TCB in ACE_OS::thr_create (). 00620 if (t_id == 0) 00621 { 00622 ACE_NEW_RETURN (t_id, 00623 char*, 00624 -1); 00625 ACE_NEW_RETURN (*t_id, 00626 char[16], 00627 -1); 00628 // Mark the thread ID to show that the ACE_Thread_Manager 00629 // allocated it. 00630 (*t_id)[0] = ACE_THR_ID_ALLOCATED; 00631 (*t_id)[1] = '\0'; 00632 } 00633 #else /* ! ACE_VXWORKS */ 00634 ACE_thread_t thr_id; 00635 if (t_id == 0) 00636 t_id = &thr_id; 00637 #endif /* ! ACE_VXWORKS */ 00638 00639 new_thr_desc->sync_->acquire (); 00640 // Acquire the <sync_> lock to block the spawned thread from 00641 // removing this Thread Descriptor before it gets put into our 00642 // thread table. 00643 00644 int const result = ACE_Thread::spawn (func, 00645 args, 00646 flags, 00647 t_id, 00648 &thr_handle, 00649 priority, 00650 stack, 00651 stack_size, 00652 thread_args); 00653 00654 if (result != 0) 00655 { 00656 // _Don't_ clobber errno here! result is either 0 or -1, and 00657 // ACE_OS::thr_create () already set errno! D. Levine 28 Mar 1997 00658 // errno = result; 00659 ACE_Errno_Guard guard (errno); // Lock release may smash errno 00660 new_thr_desc->sync_->release (); 00661 return -1; 00662 } 00663 00664 #if defined (ACE_HAS_WTHREADS) 00665 // Have to duplicate handle if client asks for it. 00666 // @@ How are thread handles implemented on AIX? Do they 00667 // also need to be duplicated? 00668 if (t_handle != 0) 00669 # if defined (ACE_HAS_WINCE) 00670 *t_handle = thr_handle; 00671 # else /* ! ACE_HAS_WINCE */ 00672 (void) ::DuplicateHandle (::GetCurrentProcess (), 00673 thr_handle, 00674 ::GetCurrentProcess (), 00675 t_handle, 00676 0, 00677 TRUE, 00678 DUPLICATE_SAME_ACCESS); 00679 # endif /* ! ACE_HAS_WINCE */ 00680 #else /* ! ACE_HAS_WTHREADS */ 00681 if (t_handle != 0) 00682 *t_handle = thr_handle; 00683 #endif /* ! ACE_HAS_WTHREADS */ 00684 00685 // append_thr also put the <new_thr_desc> into Thread_Manager's 00686 // double-linked list. Only after this point, can we manipulate 00687 // double-linked list from a spawned thread's context. 00688 return this->append_thr (*t_id, 00689 thr_handle, 00690 ACE_THR_SPAWNED, 00691 grp_id, 00692 task, 00693 flags, 00694 new_thr_desc.release ()); 00695 } |
|
Spawn N new threads, which execute with argument . If != 0 the thread_ids of successfully spawned threads will be placed into the buffer (which must be the same size as ). If != 0 it is assumed to be an array of pointers to the base of the stacks to use for the threads being spawned. If != 0 it is assumed to be an array of values indicating how big each of the corresponding s are. If != 0 it is assumed to be an array of thread_handles that will be assigned the values of the thread handles being spawned. Threads in Thread_Manager can be manipulated in groups based on or using functions such as kill_grp() or cancel_task(). If is assigned, the newly spawned threads are added into the group. Otherwise, the Thread_Manager assigns these threads with a grp_id. You should choose either assigning everytime, or let the Thread_Manager handles it for you consistently. The argument is usually assigned by <ACE_Task_Base::activate>. It associates the newly spawned threads with an ACE_Task instance, which defaults to .
Definition at line 776 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_TRACE, and spawn_i().
00787 { 00788 ACE_TRACE ("ACE_Thread_Manager::spawn_n"); 00789 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 00790 00791 if (grp_id == -1) 00792 grp_id = this->grp_id_++; // Increment the group id. 00793 00794 for (size_t i = 0; i < n; i++) 00795 { 00796 // @@ What should happen if this fails?! e.g., should we try to 00797 // cancel the other threads that we've already spawned or what? 00798 if (this->spawn_i (func, 00799 args, 00800 flags, 00801 thread_ids == 0 ? 0 : &thread_ids[i], 00802 thread_handles == 0 ? 0 : &thread_handles[i], 00803 priority, 00804 grp_id, 00805 stack == 0 ? 0 : stack[i], 00806 stack_size == 0 ? 0 : stack_size[i], 00807 task) == -1) 00808 return -1; 00809 } 00810 00811 return grp_id; 00812 } |
|
Spawn N new threads, which execute with argument . If != 0 the thread_ids of successfully spawned threads will be placed into the buffer (which must be the same size as ). If != 0 it is assumed to be an array of pointers to the base of the stacks to use for the threads being spawned. If != 0 it is assumed to be an array of values indicating how big each of the corresponding s are. If != 0 it is assumed to be an array of thread_handles that will be assigned the values of the thread handles being spawned. Threads in Thread_Manager can be manipulated in groups based on or using functions such as kill_grp() or cancel_task(). If is assigned, the newly spawned threads are added into the group. Otherwise, the Thread_Manager assigns these threads with a grp_id. You should choose either assigning everytime, or let the Thread_Manager handles it for you consistently. The argument is usually assigned by <ACE_Task_Base::activate>. It associates the newly spawned threads with an ACE_Task instance, which defaults to .
Definition at line 736 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_TRACE, and spawn_i(). Referenced by ACE_Task_Base::activate().
00746 { 00747 ACE_TRACE ("ACE_Thread_Manager::spawn_n"); 00748 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 00749 00750 if (grp_id == -1) 00751 grp_id = this->grp_id_++; // Increment the group id. 00752 00753 for (size_t i = 0; i < n; i++) 00754 { 00755 // @@ What should happen if this fails?! e.g., should we try to 00756 // cancel the other threads that we've already spawned or what? 00757 if (this->spawn_i (func, 00758 args, 00759 flags, 00760 0, 00761 thread_handles == 0 ? 0 : &thread_handles[i], 00762 priority, 00763 grp_id, 00764 stack == 0 ? 0 : stack[i], 00765 stack_size == 0 ? 0 : stack_size[i], 00766 task) == -1) 00767 return -1; 00768 } 00769 00770 return grp_id; 00771 } |
|
Suspend a single thread.
Definition at line 1130 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, and ACE_TRACE.
01131 { 01132 ACE_TRACE ("ACE_Thread_Manager::suspend"); 01133 ACE_EXECUTE_OP (this->suspend_thr, 0); 01134 } |
|
Suspend all threads.
Definition at line 1417 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_all(), and suspend_thr(). Referenced by ACE_Schedule_All_Threaded_Strategy< SVC_HANDLER >::suspend().
|
|
Suspend a group of threads.
Definition at line 1337 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp(), and suspend_thr().
|
|
Suspend all threads in an ACE_Task. Definition at line 1954 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task(), and suspend_thr(). Referenced by ACE_Task_Base::suspend().
01955 { 01956 ACE_TRACE ("ACE_Thread_Manager::suspend_task"); 01957 return this->apply_task (task, 01958 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::suspend_thr)); 01959 } |
|
Suspend the thread described in .
Definition at line 1033 of file Thread_Manager.cpp. References ACE_SET_BITS, ACE_THR_SUSPENDED, ACE_TRACE, ENOTSUP, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::enqueue_tail(), ACE_Thread::suspend(), ACE_Thread_Descriptor_Base::thr_handle_, ACE_Thread_Descriptor_Base::thr_state_, and thr_to_be_removed_. Referenced by suspend_all(), suspend_grp(), and suspend_task().
01034 { 01035 ACE_TRACE ("ACE_Thread_Manager::suspend_thr"); 01036 01037 int const result = ACE_Thread::suspend (td->thr_handle_); 01038 if (result == -1) { 01039 if (errno != ENOTSUP) 01040 this->thr_to_be_removed_.enqueue_tail (td); 01041 return -1; 01042 } 01043 else { 01044 ACE_SET_BITS (td->thr_state_, ACE_THR_SUSPENDED); 01045 return 0; 01046 } 01047 } |
|
Returns a pointer to the current we're executing in if this thread is indeed running in an , else return 0. Definition at line 234 of file Thread_Manager.inl. References ACE_TRACE, ACE_Thread_Descriptor_Base::task(), and thread_desc_self().
00235 { 00236 ACE_TRACE ("ACE_Thread_Manager::task"); 00237 00238 ACE_Thread_Descriptor *td = this->thread_desc_self () ; 00239 00240 if (td == 0) 00241 return 0; 00242 else 00243 return td->task (); 00244 } |
|
Returns a list of ACE_Task_Base pointers corresponding to the tasks that have active threads managed by this instance.
Definition at line 2065 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02067 { 02068 ACE_TRACE ("ACE_Thread_Manager::task_all_list"); 02069 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02070 02071 size_t task_list_count = 0; 02072 02073 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02074 !iter.done (); 02075 iter.advance ()) 02076 { 02077 if (task_list_count >= n) 02078 break; 02079 02080 ACE_Task_Base *task_p = iter.next ()->task_; 02081 if (0 != task_p) 02082 { 02083 // This thread has a task pointer; see if it's already in the 02084 // list. Don't add duplicates. 02085 size_t i = 0; 02086 for (; i < task_list_count; ++i) 02087 if (task_list[i] == task_p) 02088 break; 02089 if (i == task_list_count) // No match - add this one 02090 task_list[task_list_count++] = task_p; 02091 } 02092 } 02093 02094 return task_list_count; 02095 } |
|
Returns a list of ACE_Task_Base pointers corresponding to the tasks that have active threads in a specified thread group.
Definition at line 2156 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), find_task(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02159 { 02160 ACE_TRACE ("ACE_Thread_Manager::task_list"); 02161 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02162 02163 ACE_Task_Base **task_list_iterator = task_list; 02164 size_t task_list_count = 0; 02165 size_t i = 0; 02166 02167 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02168 !iter.done (); 02169 iter.advance ()) 02170 { 02171 if (task_list_count >= n) 02172 break; 02173 02174 if (iter.next ()->grp_id_ == grp_id 02175 && this->find_task (iter.next ()->task_, i) == 0) 02176 { 02177 task_list_iterator[task_list_count] = iter.next ()->task_; 02178 task_list_count++; 02179 } 02180 02181 i++; 02182 } 02183 02184 return task_list_count; 02185 } |
|
True if is cancelled, else false. Always return false if is not managed by the Thread_Manager. Definition at line 1228 of file Thread_Manager.cpp. References ACE_THR_CANCELLED, ACE_TRACE, and check_state().
01229 { 01230 ACE_TRACE ("ACE_Thread_Manager::testcancel"); 01231 return this->check_state (ACE_THR_CANCELLED, t_id); 01232 } |
|
True if is active (i.e., resumed), else false. Always return false if is not managed by the Thread_Manager. Definition at line 1219 of file Thread_Manager.cpp. References ACE_THR_SUSPENDED, ACE_TRACE, and check_state().
01220 { 01221 ACE_TRACE ("ACE_Thread_Manager::testresume"); 01222 return this->check_state (ACE_THR_SUSPENDED, t_id, 0); 01223 } |
|
True if is inactive (i.e., suspended), else false. Always return false if is not managed by the Thread_Manager. Definition at line 1210 of file Thread_Manager.cpp. References ACE_THR_SUSPENDED, ACE_TRACE, and check_state().
01211 { 01212 ACE_TRACE ("ACE_Thread_Manager::testsuspend"); 01213 return this->check_state (ACE_THR_SUSPENDED, t_id); 01214 } |
|
True if has terminated (i.e., is no longer running), but the slot in the thread manager hasn't been reclaimed yet, else false. Always return false if is not managed by the Thread_Manager. Definition at line 1201 of file Thread_Manager.cpp. References ACE_THR_TERMINATED, ACE_TRACE, and check_state().
01202 { 01203 ACE_TRACE ("ACE_Thread_Manager::testterminate"); 01204 return this->check_state (ACE_THR_TERMINATED, t_id); 01205 } |
|
Return the unique ID of the thread. This is not strictly necessary (because a thread can always just call <ACE_Thread::self>). However, we put it here to be complete. Definition at line 227 of file Thread_Manager.inl. References ACE_TRACE, and ACE_Thread::self().
00228 { 00229 ACE_TRACE ("ACE_Thread_Manager::thr_self"); 00230 return ACE_Thread::self (); 00231 } |
|
Return the "real" handle to the calling thread, caching it if necessary in TSS to speed up subsequent lookups. This is necessary since on some platforms (e.g., Win32) we can't get this handle via direct method calls. Notice that you should *not* close the handle passed back from this method. It is used internally by Thread Manager. On the other hand, you *have to* use this internal thread handle when working on Thread_Manager. Return -1 if fail. Definition at line 366 of file Thread_Manager.cpp. References ACE_hthread_t, ACE_TRACE, ACE_Thread_Descriptor::self(), and thread_desc_self().
00367 { 00368 ACE_TRACE ("ACE_Thread_Manager::thr_self"); 00369 00370 ACE_Thread_Descriptor *desc = 00371 this->thread_desc_self (); 00372 00373 if (desc == 0) 00374 return -1; 00375 else 00376 desc->self (self); 00377 00378 return 0; 00379 } |
|
Get the state of the thread. Returns false if the thread is not managed by this thread manager. Definition at line 2124 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, ACE_LOG_MSG, ACE_TRACE, ACE_OS::thr_equal(), and ACE_Thread_Descriptor_Base::thr_state_. Referenced by check_state().
02126 { 02127 ACE_TRACE ("ACE_Thread_Manager::thr_state"); 02128 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02129 02130 int self_check = ACE_OS::thr_equal (id, ACE_OS::thr_self ()); 02131 02132 // If we're checking the state of our thread, try to get the cached 02133 // value out of TSS to avoid lookup. 02134 if (self_check) 02135 { 02136 ACE_Thread_Descriptor *desc = ACE_LOG_MSG->thr_desc (); 02137 if (desc == 0) 02138 return 0; // Always return false. 02139 state = desc->thr_state_; 02140 } 02141 else 02142 { 02143 // Not calling from self, have to look it up from the list. 02144 ACE_FIND (this->find_thread (id), ptr); 02145 if (ptr == 0) 02146 return 0; 02147 state = ptr->thr_state_; 02148 } 02149 02150 return 1; 02151 } |
|
Returns in a list of up to thread ids. The caller must allocate the memory for . In case of an error, -1 is returned. If no requested values are found, 0 is returned, otherwise correct number of retrieved values are returned. Definition at line 2100 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02102 { 02103 ACE_TRACE ("ACE_Thread_Manager::thread_all_list"); 02104 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02105 02106 size_t thread_count = 0; 02107 02108 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02109 !iter.done (); 02110 iter.advance ()) 02111 { 02112 if (thread_count >= n) 02113 break; 02114 02115 thread_list[thread_count] = iter.next ()->thr_id_; 02116 thread_count ++; 02117 } 02118 02119 return thread_count; 02120 } |
|
Get a pointer to the calling thread's own thread_descriptor. This must be called from a spawn thread. This function will fetch the info from TSS. Definition at line 197 of file Thread_Manager.inl. References ACE_LOG_MSG, ACE_thread_t, find_thread(), and ACE_OS::thr_self(). Referenced by at_exit(), run_thread_exit_hooks(), task(), and thr_self().
00198 { 00199 // This method must be called with lock held. 00200 00201 // Try to get it from cache. 00202 ACE_Thread_Descriptor *desc = ACE_LOG_MSG->thr_desc (); 00203 00204 #if 1 00205 // ACE_ASSERT (desc != 0); 00206 // Thread descriptor should always get cached. 00207 #else 00208 if (desc == 0) 00209 { 00210 ACE_thread_t id = ACE_OS::thr_self (); 00211 00212 desc = this->find_thread (id); 00213 00214 // Thread descriptor adapter might not have been put into the 00215 // list yet. 00216 if (desc != 0) 00217 // Update the TSS cache. 00218 ACE_LOG_MSG->thr_desc (desc); 00219 } 00220 #endif 00221 return desc; 00222 } |
|
Return a pointer to the thread's Thread_Descriptor, 0 if fail. Definition at line 344 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, and ACE_TRACE.
00345 { 00346 ACE_TRACE ("ACE_Thread_Manager::thread_descriptor"); 00347 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0)); 00348 00349 ACE_FIND (this->find_thread (thr_id), ptr); 00350 return ptr; 00351 } |
|
Returns in a list of up to thread ids in a group . The caller must allocate the memory for . In case of an error, -1 is returned. If no requested values are found, 0 is returned, otherwise correct number of retrieved values are returned. Definition at line 2246 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02249 { 02250 ACE_TRACE ("ACE_Thread_Manager::thread_grp_list"); 02251 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02252 02253 size_t thread_count = 0; 02254 02255 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02256 !iter.done (); 02257 iter.advance ()) 02258 { 02259 if (thread_count >= n) 02260 break; 02261 02262 if (iter.next ()->grp_id_ == grp_id) 02263 { 02264 thread_list[thread_count] = iter.next ()->thr_id_; 02265 thread_count++; 02266 } 02267 } 02268 02269 return thread_count; 02270 } |
|
Returns in a list of up to thread ids in an . The caller must allocate the memory for . In case of an error, -1 is returned. If no requested values are found, 0 is returned, otherwise correct number of retrieved values are returned. Definition at line 2190 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), and ACE_Double_Linked_List_Iterator_Base< T >::next().
02193 { 02194 ACE_TRACE ("ACE_Thread_Manager::thread_list"); 02195 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 02196 02197 size_t thread_count = 0; 02198 02199 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 02200 !iter.done (); 02201 iter.advance ()) 02202 { 02203 if (thread_count >= n) 02204 break; 02205 02206 if (iter.next ()->task_ == task) 02207 { 02208 thread_list[thread_count] = iter.next ()->thr_id_; 02209 thread_count++; 02210 } 02211 } 02212 02213 return thread_count; 02214 } |
|
Definition at line 1252 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Double_Linked_List_Iterator_Base< T >::next(), and ACE_OS::thr_equal().
01253 { 01254 ACE_TRACE ("ACE_Thread_Manager::thread_within"); 01255 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_monx, this->lock_, -1)); 01256 01257 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01258 !iter.done (); 01259 iter.advance ()) 01260 if (ACE_OS::thr_equal (iter.next ()->thr_id_, tid)) 01261 return 1; 01262 01263 return 0; 01264 } |
|
Block until there are no more threads running in this thread manager or
ACE_Object_Manager is shutting down (as a result of program rundown via ACE::fini() ), it will not wait for any threads to complete. If you must wait for threads spawned by this thread manager to complete and you are in a ACE rundown situation (such as your object is being destroyed by the ACE_Object_Manager ) you can use wait_grp() instead.
Definition at line 1740 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_SET_BITS, ACE_THR_JOINING, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List< T >::delete_head(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::enqueue_tail(), ACE_OS_Thread_Descriptor::flags_, ACE_OS::gettimeofday(), ACE_Double_Linked_List< T >::insert_tail(), ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty(), ACE_Thread::join(), ACE_Double_Linked_List_Iterator_Base< T >::next(), remove_thr(), remove_thr_all(), ACE_Object_Manager::shutting_down(), terminated_thr_list_, ACE_Thread_Descriptor_Base::thr_handle_, thr_list_, thr_to_be_removed_, ACE_Condition_Thread_Mutex::wait(), and zero_cond_. Referenced by close().
01743 { 01744 ACE_TRACE ("ACE_Thread_Manager::wait"); 01745 01746 ACE_Time_Value local_timeout; 01747 // Check to see if we're using absolute time or not. 01748 if (use_absolute_time == false && timeout != 0) 01749 { 01750 local_timeout = *timeout; 01751 local_timeout += ACE_OS::gettimeofday (); 01752 timeout = &local_timeout; 01753 } 01754 01755 #if !defined (ACE_VXWORKS) 01756 ACE_Double_Linked_List<ACE_Thread_Descriptor_Base> term_thr_list_copy; 01757 #endif /* ACE_VXWORKS */ 01758 01759 #if defined (ACE_HAS_THREADS) 01760 { 01761 // Just hold onto the guard while waiting. 01762 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01763 01764 if (ACE_Object_Manager::shutting_down () != 1) 01765 { 01766 // Program is not shutting down. Perform a normal wait on threads. 01767 if (abandon_detached_threads != 0) 01768 { 01769 ACE_ASSERT (this->thr_to_be_removed_.is_empty ()); 01770 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> 01771 iter (this->thr_list_); 01772 !iter.done (); 01773 iter.advance ()) 01774 if (ACE_BIT_ENABLED (iter.next ()->flags_, 01775 THR_DETACHED | THR_DAEMON) 01776 && ACE_BIT_DISABLED (iter.next ()->flags_, THR_JOINABLE)) 01777 { 01778 this->thr_to_be_removed_.enqueue_tail (iter.next ()); 01779 ACE_SET_BITS (iter.next ()->thr_state_, ACE_THR_JOINING); 01780 } 01781 01782 if (! this->thr_to_be_removed_.is_empty ()) 01783 { 01784 ACE_Thread_Descriptor *td; 01785 while (this->thr_to_be_removed_.dequeue_head (td) != -1) 01786 this->remove_thr (td, 1); 01787 } 01788 } 01789 01790 while (this->thr_list_.size () > 0) 01791 if (this->zero_cond_.wait (timeout) == -1) 01792 return -1; 01793 } 01794 else 01795 // Program is shutting down, no chance to wait on threads. 01796 // Therefore, we'll just remove threads from the list. 01797 this->remove_thr_all (); 01798 01799 #if !defined (ACE_VXWORKS) 01800 ACE_Thread_Descriptor_Base* item = 0; 01801 while ((item = this->terminated_thr_list_.delete_head ()) != 0) 01802 { 01803 term_thr_list_copy.insert_tail (item); 01804 } 01805 #endif /* ACE_VXWORKS */ 01806 // Release the guard, giving other threads a chance to run. 01807 } 01808 01809 #if !defined (ACE_VXWORKS) 01810 // @@ VxWorks doesn't support thr_join (yet.) We are working 01811 //on our implementation. Chorus'es thr_join seems broken. 01812 ACE_Thread_Descriptor_Base *item = 0; 01813 01814 while ((item = term_thr_list_copy.delete_head ()) != 0) 01815 { 01816 if (ACE_BIT_DISABLED (item->flags_, THR_DETACHED | THR_DAEMON) 01817 || ACE_BIT_ENABLED (item->flags_, THR_JOINABLE)) 01818 // Detached handles shouldn't reached here. 01819 ACE_Thread::join (item->thr_handle_); 01820 01821 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH) 01822 // Must explicitly detach threads. Threads without 01823 // THR_DETACHED were detached in ACE_OS::thr_create (). 01824 ::pthread_detach (&item->thr_handle_); 01825 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */ 01826 delete item; 01827 } 01828 01829 #endif /* ! ACE_VXWORKS */ 01830 #else 01831 ACE_UNUSED_ARG (timeout); 01832 ACE_UNUSED_ARG (abandon_detached_threads); 01833 #endif /* ACE_HAS_THREADS */ 01834 01835 return 0; 01836 } |
|
Block until there are no more threads running in a group. Returns 0 on success and -1 on failure. Notice that wait_grp will not wait on detached threads. Definition at line 1530 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_SET_BITS, ACE_THR_JOINING, ACE_TRACE, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator< T >::advance_and_remove(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Thread::join(), ACE_Double_Linked_List_Iterator_Base< T >::next(), terminated_thr_list_, and ACE_Thread_Descriptor_Base::thr_handle_. Referenced by ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler().
01531 { 01532 ACE_TRACE ("ACE_Thread_Manager::wait_grp"); 01533 01534 int copy_count = 0; 01535 ACE_Thread_Descriptor_Base *copy_table = 0; 01536 01537 // We have to make sure that while we wait for these threads to 01538 // exit, we do not have the lock. Therefore we make a copy of all 01539 // interesting entries and let go of the lock. 01540 { 01541 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01542 01543 #if !defined (ACE_VXWORKS) 01544 ACE_NEW_RETURN (copy_table, 01545 ACE_Thread_Descriptor_Base [this->thr_list_.size () 01546 + this->terminated_thr_list_.size ()], 01547 -1); 01548 #else 01549 ACE_NEW_RETURN (copy_table, 01550 ACE_Thread_Descriptor_Base [this->thr_list_.size ()], 01551 -1); 01552 #endif /* ACE_VXWORKS */ 01553 01554 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01555 !iter.done (); 01556 iter.advance ()) 01557 // If threads are created as THR_DETACHED or THR_DAEMON, we 01558 // can't help much. 01559 if (iter.next ()->grp_id_ == grp_id && 01560 (ACE_BIT_DISABLED (iter.next ()->flags_, THR_DETACHED | THR_DAEMON) 01561 || ACE_BIT_ENABLED (iter.next ()->flags_, THR_JOINABLE))) 01562 { 01563 ACE_SET_BITS (iter.next ()->thr_state_, ACE_THR_JOINING); 01564 copy_table[copy_count++] = *iter.next (); 01565 } 01566 01567 #if !defined (ACE_VXWORKS) 01568 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor_Base> biter (this->terminated_thr_list_); 01569 !biter.done (); 01570 biter.advance ()) 01571 // If threads are created as THR_DETACHED or THR_DAEMON, we 01572 // can't help much. 01573 if (biter.next ()->grp_id_ == grp_id) 01574 { 01575 ACE_Thread_Descriptor_Base *tdb = biter.advance_and_remove (0); 01576 copy_table[copy_count++] = *tdb; 01577 delete tdb; 01578 } 01579 #endif /* !ACE_VXWORKS */ 01580 } 01581 01582 // Now actually join() with all the threads in this group. 01583 int result = 0; 01584 01585 for (int i = 0; 01586 i < copy_count && result != -1; 01587 i++) 01588 { 01589 if (ACE_Thread::join (copy_table[i].thr_handle_) == -1) 01590 result = -1; 01591 01592 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH) 01593 // Must explicitly detach threads. Threads without THR_DETACHED 01594 // were detached in ACE_OS::thr_create (). 01595 ::pthread_detach (©_table[i].thr_handle_); 01596 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */ 01597 } 01598 01599 delete [] copy_table; 01600 01601 return result; 01602 } |
|
Definition at line 296 of file Thread_Manager.inl. References automatic_wait_.
00297 { 00298 return this->automatic_wait_; 00299 } |
|
Access function to determine whether the Thread_Manager will wait for its thread to exit or not when being closing down. Definition at line 290 of file Thread_Manager.inl. References automatic_wait_.
00291 { 00292 this->automatic_wait_ = do_wait; 00293 } |
|
Block until there are no more threads running in a specified task. This method will not wait for either detached or daemon threads; the threads must have been spawned with the
Definition at line 1876 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_SET_BITS, ACE_THR_JOINING, ACE_Double_Linked_List_Iterator< T >::advance(), ACE_Double_Linked_List_Iterator< T >::advance_and_remove(), ACE_Double_Linked_List_Iterator_Base< T >::done(), ACE_Thread::join(), ACE_Double_Linked_List_Iterator_Base< T >::next(), terminated_thr_list_, and ACE_Thread_Descriptor_Base::thr_handle_. Referenced by ACE_Task_Base::wait().
01877 { 01878 int copy_count = 0; 01879 ACE_Thread_Descriptor_Base *copy_table = 0; 01880 01881 // We have to make sure that while we wait for these threads to 01882 // exit, we do not have the lock. Therefore we make a copy of all 01883 // interesting entries and let go of the lock. 01884 { 01885 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); 01886 01887 #if !defined (ACE_VXWORKS) 01888 ACE_NEW_RETURN (copy_table, 01889 ACE_Thread_Descriptor_Base [this->thr_list_.size () 01890 + this->terminated_thr_list_.size ()], 01891 -1); 01892 #else 01893 ACE_NEW_RETURN (copy_table, 01894 ACE_Thread_Descriptor_Base [this->thr_list_.size ()], 01895 -1); 01896 #endif /* ACE_VXWORKS */ 01897 01898 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_); 01899 !iter.done (); 01900 iter.advance ()) 01901 // If threads are created as THR_DETACHED or THR_DAEMON, we 01902 // can't wait on them here. 01903 if (iter.next ()->task_ == task && 01904 (ACE_BIT_DISABLED (iter.next ()->flags_, 01905 THR_DETACHED | THR_DAEMON) 01906 || ACE_BIT_ENABLED (iter.next ()->flags_, 01907 THR_JOINABLE))) 01908 { 01909 ACE_SET_BITS (iter.next ()->thr_state_, 01910 ACE_THR_JOINING); 01911 copy_table[copy_count++] = *iter.next (); 01912 } 01913 01914 #if !defined (ACE_VXWORKS) 01915 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor_Base> titer (this->terminated_thr_list_); 01916 !titer.done (); 01917 titer.advance ()) 01918 // If threads are created as THR_DETACHED or THR_DAEMON, we can't help much here. 01919 if (titer.next ()->task_ == task) 01920 { 01921 ACE_Thread_Descriptor_Base *tdb = 01922 titer.advance_and_remove (0); 01923 copy_table[copy_count++] = *tdb; 01924 delete tdb; 01925 } 01926 #endif /* ACE_VXWORKS */ 01927 } 01928 01929 // Now to do the actual work 01930 int result = 0; 01931 01932 for (int i = 0; 01933 i < copy_count && result != -1; 01934 i++) 01935 { 01936 if (ACE_Thread::join (copy_table[i].thr_handle_) == -1) 01937 result = -1; 01938 01939 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH) 01940 // Must explicitly detach threads. Threads without THR_DETACHED 01941 // were detached in ACE_OS::thr_create (). 01942 ::pthread_detach (©_table[i].thr_handle_); 01943 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */ 01944 } 01945 01946 delete [] copy_table; 01947 01948 return result; 01949 } |
|
Definition at line 396 of file Thread_Manager.h. |
|
Definition at line 401 of file Thread_Manager.h. |
|
Definition at line 399 of file Thread_Manager.h. |
|
Declare the dynamic allocation hooks.
Definition at line 978 of file Thread_Manager.h. |
|
Set if we want the Thread_Manager to wait on all threads before being closed, reset otherwise. Definition at line 1123 of file Thread_Manager.h. Referenced by close(), and wait_on_exit(). |
|
Must delete the if non-0.
Definition at line 56 of file Thread_Manager.cpp. Referenced by close_singleton(), and instance(). |
|
Keeps track of the next group id to assign.
Definition at line 1119 of file Thread_Manager.h. Referenced by dump(). |
|
Serialize access to the .
Definition at line 1128 of file Thread_Manager.h. |
|
Collect terminated but not yet joined thread entries.
Definition at line 1112 of file Thread_Manager.h. Referenced by register_as_terminated(), wait(), wait_grp(), and wait_task(). |
|
Keeping a list of thread descriptors within the thread manager. Double-linked list enables us to cache the entries in TSS and adding/removing thread descriptor entries without affecting other thread's descriptor entries. Definition at line 1108 of file Thread_Manager.h. Referenced by append_thr(), count_threads(), dump(), remove_thr(), remove_thr_all(), and wait(). |
|
Pointer to a process-wide .
Definition at line 52 of file Thread_Manager.cpp. Referenced by close_singleton(), and instance(). |
|
Collect pointers to thread descriptors of threads to be removed later.
Definition at line 1116 of file Thread_Manager.h. Referenced by apply_all(), apply_grp(), apply_task(), kill_thr(), resume_thr(), suspend_thr(), and wait(). |
|
Definition at line 1134 of file Thread_Manager.h. Referenced by remove_thr(). |
|
Keep track of when there are no more threads.
Definition at line 1131 of file Thread_Manager.h. Referenced by remove_thr(), and wait(). |