#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 Methods | |
| 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. More... | |
| virtual | ~ACE_Thread_Manager (void) |
| int | open (size_t size=0) |
| No-op. Currently unused. More... | |
| int | close (void) |
| int | spawn (ACE_THR_FUNC func, void *args=0, long flags=THR_NEW_LWP|THR_JOINABLE, 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 *args=0, long flags=THR_NEW_LWP|THR_JOINABLE, 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 *args, 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, int abandon_detached_threads=0) |
| int | join (ACE_thread_t tid, ACE_THR_FUNC_RETURN *status=0) |
| Join a thread specified by <tid>. Do not wait on a detached thread. More... | |
| 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. More... | |
| int | suspend (ACE_thread_t) |
| Suspend a single thread. More... | |
| int | suspend_grp (int grp_id) |
| Suspend a group of threads. More... | |
| int | testsuspend (ACE_thread_t t_id) |
| int | resume_all (void) |
| Resume all stopped threads. More... | |
| int | resume (ACE_thread_t) |
| Resume a single thread. More... | |
| int | resume_grp (int grp_id) |
| Resume a group of threads. More... | |
| 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 | set_grp (ACE_thread_t, int grp_id) |
| Set group ids for a particular thread id. More... | |
| int | get_grp (ACE_thread_t, int &grp_id) |
| Get group ids for a particular thread id. More... | |
| 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) |
| Check if the thread is managed by the thread manager. Return true if the thread is found, false otherwise. More... | |
| int | thread_within (ACE_thread_t tid) |
| int | num_tasks_in_group (int grp_id) |
| Returns the number of <ACE_Task_Base> in a group. More... | |
| int | num_threads_in_task (ACE_Task_Base *task) |
| Returns the number of threads in an <ACE_Task_Base>. More... | |
| 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. More... | |
| int | get_grp (ACE_Task_Base *task, int &grp_id) |
| Get group ids for a particular task. More... | |
| size_t | count_threads (void) const |
| Return a count of the current number of threads active in the <Thread_Manager>. More... | |
| int | at_exit (ACE_At_Thread_Exit *cleanup) |
| int | at_exit (ACE_At_Thread_Exit &cleanup) |
| Register an At_Thread_Exit hook and the ownership is retained for the caller. Normally used when the at_exit hook is created in stack. More... | |
| int | at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
| void | wait_on_exit (int dowait) |
| Access function to determine whether the Thread_Manager will wait for its thread to exit or not when being closing down. More... | |
| int | wait_on_exit (void) |
| void | dump (void) |
| Dump the state of an object. More... | |
Static Public Methods | |
| ACE_Thread_Manager * | instance (void) |
| Get pointer to a process-wide <ACE_Thread_Manager>. More... | |
| ACE_Thread_Manager * | instance (ACE_Thread_Manager *) |
| Set pointer to a process-wide <ACE_Thread_Manager> and return existing pointer. More... | |
| void | close_singleton (void) |
| Delete the dynamically allocated Singleton. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Protected Methods | |
| ACE_Thread_Descriptor * | thread_desc_self (void) |
| ACE_Thread_Descriptor * | thread_descriptor (ACE_thread_t) |
| Return a pointer to the thread's Thread_Descriptor, 0 if fail. More... | |
| ACE_Thread_Descriptor * | hthread_descriptor (ACE_hthread_t) |
| Return a pointer to the thread's Thread_Descriptor, 0 if fail. More... | |
| virtual int | spawn_i (ACE_THR_FUNC func, void *args, 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). More... | |
| void | run_thread_exit_hooks (int i) |
| Run the registered hooks when the thread exits. More... | |
| ACE_Thread_Descriptor * | find_thread (ACE_thread_t t_id) |
| Locate the index of the table slot occupied by <t_id>. Returns -1 if <t_id> is not in the table doesn't contain <t_id>. More... | |
| ACE_Thread_Descriptor * | find_hthread (ACE_hthread_t h_id) |
| Locate the index of the table slot occupied by <h_id>. Returns -1 if <h_id> is not in the table doesn't contain <h_id>. More... | |
| 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). More... | |
| 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) |
| Append a thread in the table (adds at the end, growing the table if necessary). More... | |
| void | remove_thr (ACE_Thread_Descriptor *td, int close_handler) |
| Remove thread from the table. More... | |
| void | remove_thr_all (void) |
| Remove all threads from the table. More... | |
| 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 <func> to all members of the table that match the <task>. More... | |
| int | apply_grp (int grp_id, ACE_THR_MEMBER_FUNC func, int arg=0) |
| Apply <func> to all members of the table that match the <grp_id>. More... | |
| int | apply_all (ACE_THR_MEMBER_FUNC, int=0) |
| Apply <func> to all members of the table. More... | |
| int | join_thr (ACE_Thread_Descriptor *td, int=0) |
| Join the thread described in <tda>. More... | |
| int | resume_thr (ACE_Thread_Descriptor *td, int=0) |
| Resume the thread described in <tda>. More... | |
| int | suspend_thr (ACE_Thread_Descriptor *td, int=0) |
| Suspend the thread described in <tda>. More... | |
| int | kill_thr (ACE_Thread_Descriptor *td, int signum) |
| Send signal <signum> to the thread described in <tda>. More... | |
| int | cancel_thr (ACE_Thread_Descriptor *td, int async_cancel=0) |
| Set the cancellation flag for the thread described in <tda>. More... | |
| int | register_as_terminated (ACE_Thread_Descriptor *td) |
| Register a thread as terminated and put it into the <terminated_thr_list_>. More... | |
Static Protected Methods | |
| int | set_thr_exit (ACE_TSS_TYPE(ACE_Thread_Exit)*ptr) |
| Setting the static ACE_TSS_TYPE (ACE_Thread_Exit) *thr_exit_ pointer. More... | |
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. More... | |
| ACE_Unbounded_Queue< ACE_Thread_Descriptor * > | thr_to_be_removed_ |
| Collect pointers to thread descriptors of threads to be removed later. More... | |
| int | grp_id_ |
| Keeps track of the next group id to assign. More... | |
| int | automatic_wait_ |
| Set if we want the Thread_Manager to wait on all threads before being closed, reset otherwise. More... | |
| ACE_Thread_Mutex | lock_ |
| Serialize access to the <zero_cond_>. More... | |
| ACE_Condition_Thread_Mutex | zero_cond_ |
| Keep track of when there are no more threads. More... | |
Static Private Methods | |
| ACE_TSS_TYPE (ACE_Thread_Exit)*thr_exit_ | |
| Global ACE_TSS (ACE_Thread_Exit) object ptr. More... | |
Private Attributes | |
| ACE_Locked_Free_List< ACE_Thread_Descriptor, ACE_SYNCH_MUTEX > | thread_desc_freelist_ |
Static Private Attributes | |
| ACE_Thread_Manager * | thr_mgr_ = 0 |
| Pointer to a process-wide <ACE_Thread_Manager>. More... | |
| int | delete_thr_mgr_ = 0 |
| Must delete the <thr_mgr_> if non-0. More... | |
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 <main>, you are sure to have resource leaks in your program. Remember to wait on threads before exiting <main> if that could happen in your programs.
Definition at line 387 of file Thread_Manager.h.
|
|
Definition at line 399 of file Thread_Manager.h. Referenced by cancel_all, cancel_grp, cancel_task, kill_grp, kill_task, resume_all, resume_grp, resume_task, suspend_all, suspend_grp, and suspend_task. |
|
|
Definition at line 404 of file Thread_Manager.h.
00405 {
00406 /// Uninitialized.
00407 ACE_THR_IDLE = 0x00000000,
00408
00409 /// Created but not yet running.
00410 ACE_THR_SPAWNED = 0x00000001,
00411
00412 /// Thread is active (naturally, we don't know if it's actually
00413 /// *running* because we aren't the scheduler...).
00414 ACE_THR_RUNNING = 0x00000002,
00415
00416 /// Thread is suspended.
00417 ACE_THR_SUSPENDED = 0x00000004,
00418
00419 /// Thread has been cancelled (which is an indiction that it needs to
00420 /// terminate...).
00421 ACE_THR_CANCELLED = 0x00000008,
00422
00423 /// Thread has shutdown, but the slot in the thread manager hasn't
00424 /// been reclaimed yet.
00425 ACE_THR_TERMINATED = 0x00000010,
00426
00427 /// Join operation has been invoked on the thread by thread manager.
00428 ACE_THR_JOINING = 0x10000000
00429 };
|
|
||||||||||||||||||||
|
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, @hwm determine the initial size, the low water mark, increment step, and high water mark of the freelist.
Definition at line 324 of file Thread_Manager.cpp. References ACE_FREE_LIST_WITH_POOL, and ACE_TRACE.
00328 : grp_id_ (1), 00329 automatic_wait_ (1) 00330 #if defined (ACE_HAS_THREADS) 00331 , zero_cond_ (lock_) 00332 #endif /* ACE_HAS_THREADS */ 00333 , thread_desc_freelist_ (ACE_FREE_LIST_WITH_POOL, 00334 prealloc, lwm, hwm, inc) 00335 { 00336 ACE_TRACE ("ACE_Thread_Manager::ACE_Thread_Manager"); 00337 } |
|
|
Definition at line 419 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 751 of file Thread_Manager.cpp. References ACE_hthread_t, ACE_NEW_RETURN, ACE_SET_BITS, ACE_thread_t, ACE_TRACE, ACE_OS_Thread_Descriptor::flags_, ACE_Thread_Descriptor_Base::grp_id_, ACE_Double_Linked_List< ACE_Thread_Descriptor >::insert_head, 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.
00758 {
00759 ACE_TRACE ("ACE_Thread_Manager::append_thr");
00760 ACE_Thread_Descriptor *thr_desc;
00761
00762 if (td == 0)
00763 {
00764 ACE_NEW_RETURN (thr_desc,
00765 ACE_Thread_Descriptor,
00766 -1);
00767 #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
00768 thr_desc->tm_ = this;
00769 // Setup the Thread_Manager.
00770 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
00771 }
00772 else
00773 thr_desc = td;
00774
00775 thr_desc->thr_id_ = t_id;
00776 thr_desc->thr_handle_ = t_handle;
00777 thr_desc->grp_id_ = grp_id;
00778 thr_desc->task_ = task;
00779 thr_desc->flags_ = flags;
00780
00781 this->thr_list_.insert_head (thr_desc);
00782 ACE_SET_BITS (thr_desc->thr_state_, thr_state);
00783 thr_desc->sync_->release ();
00784
00785 return 0;
00786 }
|
|
||||||||||||
|
Apply <func> to all members of the table.
Definition at line 1317 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head, ACE_Double_Linked_List_Iterator_Base::done, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty, ACE_Double_Linked_List_Iterator_Base::next, remove_thr, and thr_to_be_removed_. Referenced by cancel_all, kill_all, resume_all, and suspend_all.
01318 {
01319 ACE_TRACE ("ACE_Thread_Manager::apply_all");
01320 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01321 ACE_ASSERT (this->thr_to_be_removed_.is_empty ());
01322
01323 int result = 0;
01324
01325 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01326 !iter.done ();
01327 iter.advance ())
01328 if ((this->*func)(iter.next (), arg) == -1)
01329 result = -1;
01330
01331 // Must remove threads after we have traversed the thr_list_ to
01332 // prevent clobber thr_list_'s integrity.
01333
01334 if (! this->thr_to_be_removed_.is_empty ())
01335 {
01336 // Save/restore errno.
01337 ACE_Errno_Guard error (errno);
01338
01339 for (ACE_Thread_Descriptor *td;
01340 this->thr_to_be_removed_.dequeue_head (td) != -1;
01341 )
01342 this->remove_thr (td, 1);
01343 }
01344
01345 return result;
01346 }
|
|
||||||||||||||||
|
Apply <func> to all members of the table that match the <grp_id>.
Definition at line 1243 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head, ACE_Double_Linked_List_Iterator_Base::done, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty, ACE_Double_Linked_List_Iterator_Base::next, remove_thr, and thr_to_be_removed_. Referenced by cancel_grp, kill_grp, resume_grp, and suspend_grp.
01246 {
01247 ACE_TRACE ("ACE_Thread_Manager::apply_grp");
01248 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_monx, this->lock_, -1));
01249 ACE_ASSERT (this->thr_to_be_removed_.is_empty ());
01250
01251 int result = 0;
01252
01253 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01254 !iter.done ();
01255 iter.advance ())
01256 if (iter.next ()->grp_id_ == grp_id)
01257 if ((this->*func) (iter.next (), arg) == -1)
01258 result = -1;
01259
01260 // Must remove threads after we have traversed the thr_list_ to
01261 // prevent clobber thr_list_'s integrity.
01262
01263 if (! this->thr_to_be_removed_.is_empty ())
01264 {
01265 // Save/restore errno.
01266 ACE_Errno_Guard error (errno);
01267
01268 for (ACE_Thread_Descriptor *td;
01269 this->thr_to_be_removed_.dequeue_head (td) != -1;
01270 )
01271 this->remove_thr (td, 1);
01272 }
01273
01274 return result;
01275 }
|
|
||||||||||||||||
|
Apply <func> to all members of the table that match the <task>.
Definition at line 1774 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head, ACE_Double_Linked_List_Iterator_Base::done, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty, ACE_Double_Linked_List_Iterator_Base::next, remove_thr, and thr_to_be_removed_. Referenced by cancel_task, kill_task, resume_task, and suspend_task.
01777 {
01778 ACE_TRACE ("ACE_Thread_Manager::apply_task");
01779 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01780 ACE_ASSERT (this->thr_to_be_removed_.is_empty ());
01781
01782 int result = 0;
01783
01784 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01785 !iter.done ();
01786 iter.advance ())
01787 if (iter.next ()->task_ == task
01788 && (this->*func) (iter.next (), arg) == -1)
01789 result = -1;
01790
01791 // Must remove threads after we have traversed the thr_list_ to
01792 // prevent clobber thr_list_'s integrity.
01793
01794 if (! this->thr_to_be_removed_.is_empty ())
01795 {
01796 // Save/restore errno.
01797 ACE_Errno_Guard error (errno);
01798
01799 for (ACE_Thread_Descriptor *td;
01800 this->thr_to_be_removed_.dequeue_head (td) != -1;
01801 )
01802 this->remove_thr (td, 1);
01803 }
01804
01805 return result;
01806 }
|
|
||||||||||||||||
|
Definition at line 292 of file Thread_Manager.i. References ACE_CLEANUP_FUNC, ACE_Thread_Descriptor::at_exit, and thread_desc_self.
00295 {
00296 ACE_Thread_Descriptor *td = this->thread_desc_self ();
00297 if (td == 0)
00298 return -1;
00299 else
00300 return td->at_exit (object,
00301 cleanup_hook,
00302 param);
00303 }
|
|
|
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 281 of file Thread_Manager.i. References ACE_Thread_Descriptor::at_exit, and thread_desc_self.
00282 {
00283 ACE_Thread_Descriptor *td = this->thread_desc_self ();
00284 if (td == 0)
00285 return -1;
00286 else
00287 return td->at_exit (at);
00288 }
|
|
|
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 271 of file Thread_Manager.i. 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.
00272 {
00273 ACE_Thread_Descriptor *td = this->thread_desc_self ();
00274 if (td == 0)
00275 return -1;
00276 else
00277 return td->at_exit (at);
00278 }
|
|
||||||||||||
|
Cancel a single thread. Definition at line 1098 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, ACE_thread_t, and ACE_TRACE.
01099 {
01100 ACE_TRACE ("ACE_Thread_Manager::cancel");
01101 ACE_EXECUTE_OP (this->cancel_thr, async_cancel);
01102 }
|
|
|
Cancel's all the threads. Definition at line 1372 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_all, and cancel_thr.
01373 {
01374 ACE_TRACE ("ACE_Thread_Manager::cancel_all");
01375 return this->apply_all (ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::cancel_thr),
01376 async_cancel);
01377 }
|
|
||||||||||||
|
Cancel a group of threads. Definition at line 1308 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp, and cancel_thr.
01309 {
01310 ACE_TRACE ("ACE_Thread_Manager::cancel_grp");
01311 return this->apply_grp (grp_id,
01312 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::cancel_thr),
01313 async_cancel);
01314 }
|
|
||||||||||||
|
Cancel all threads in an <ACE_Task>. If <async_cancel> is non-0, then asynchronously cancel these threads if the OS platform supports cancellation. Otherwise, perform a "cooperative" cancellation. Definition at line 1917 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task, and cancel_thr.
01919 {
01920 ACE_TRACE ("ACE_Thread_Manager::cancel_task");
01921 return this->apply_task (task,
01922 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::cancel_thr),
01923 async_cancel);
01924 }
|
|
||||||||||||
|
Set the cancellation flag for the thread described in <tda>.
Definition at line 1013 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.
01014 {
01015 ACE_TRACE ("ACE_Thread_Manager::cancel_thr");
01016 // Must set the state first and then try to cancel the thread.
01017 ACE_SET_BITS (td->thr_state_, ACE_THR_CANCELLED);
01018
01019 if (async_cancel != 0)
01020 // Note that this call only does something relevant if the OS
01021 // platform supports asynchronous thread cancellation. Otherwise,
01022 // it's a no-op.
01023 return ACE_Thread::cancel (td->thr_id_);
01024
01025 return 0;
01026 }
|
|
||||||||||||||||
|
Efficiently check whether <thread> is in a particular <state>. This call updates the TSS cache if possible to speed up subsequent searches. Definition at line 1114 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_FIND, ACE_GUARD_RETURN, ACE_LOG_MSG, ACE_MT, ACE_thread_t, ACE_TRACE, ACE_OS::thr_equal, ACE_OS::thr_self, and ACE_Thread_Descriptor_Base::thr_state_. Referenced by testcancel, testresume, and testsuspend.
01117 {
01118 ACE_TRACE ("ACE_Thread_Manager::check_state");
01119 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01120
01121 ACE_UINT32 thr_state;
01122
01123 int self_check = ACE_OS::thr_equal (id, ACE_OS::thr_self ());
01124
01125 // If we're checking the state of our thread, try to get the cached
01126 // value out of TSS to avoid lookup.
01127 if (self_check)
01128 {
01129 ACE_Thread_Descriptor *desc = ACE_LOG_MSG->thr_desc ();
01130 if (desc == 0)
01131 return 0; // Always return false.
01132 thr_state = desc->thr_state_;
01133 }
01134 else
01135 {
01136 // Not calling from self, have to look it up from the list.
01137 ACE_FIND (this->find_thread (id), ptr);
01138 if (ptr == 0)
01139 return 0;
01140 thr_state = ptr->thr_state_;
01141 }
01142 if (enable)
01143 return ACE_BIT_ENABLED (thr_state, state);
01144
01145 return ACE_BIT_DISABLED (thr_state, state);
01146 }
|
|
|
Release all resources. By default, this method will wait till all threads exit. However, when called from <close_singleton>, most global resources are destroyed and thus, we don't try to wait but just clean up the thread descriptor list. Definition at line 402 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, automatic_wait_, remove_thr_all, and wait. Referenced by close_singleton, and ~ACE_Thread_Manager.
00403 {
00404 ACE_TRACE ("ACE_Thread_Manager::close");
00405
00406 // Clean up the thread descriptor list.
00407 if (this->automatic_wait_)
00408 this->wait (0, 1);
00409 else
00410 {
00411 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00412
00413 this->remove_thr_all ();
00414 }
00415
00416 return 0;
00417 }
|
|
|
Delete the dynamically allocated Singleton.
Definition at line 379 of file Thread_Manager.cpp. References ACE_GUARD, ACE_MT, ACE_TRACE, ACE_Thread_Exit::cleanup, close, delete_thr_mgr_, ACE_Static_Object_Lock::instance, and thr_mgr_. Referenced by ACE_Object_Manager::fini.
00380 {
00381 ACE_TRACE ("ACE_Thread_Manager::close_singleton");
00382
00383 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00384 *ACE_Static_Object_Lock::instance ()));
00385
00386 if (ACE_Thread_Manager::delete_thr_mgr_)
00387 {
00388 // First, we clean up the thread descriptor list.
00389 ACE_Thread_Manager::thr_mgr_->close ();
00390 delete ACE_Thread_Manager::thr_mgr_;
00391 ACE_Thread_Manager::thr_mgr_ = 0;
00392 ACE_Thread_Manager::delete_thr_mgr_ = 0;
00393 }
00394
00395 ACE_Thread_Exit::cleanup (ACE_Thread_Manager::thr_exit_);
00396 }
|
|
|
Return a count of the current number of threads active in the <Thread_Manager>.
Definition at line 331 of file Thread_Manager.i. References ACE_Double_Linked_List< ACE_Thread_Descriptor >::size, and thr_list_.
|
|
|
Dump the state of an object.
Definition at line 42 of file Thread_Manager.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_GUARD, ACE_LIB_TEXT, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, LM_DEBUG, lock_, and ACE_Double_Linked_List_Iterator_Base::next.
00043 {
00044 ACE_TRACE ("ACE_Thread_Manager::dump");
00045 // Cast away const-ness of this in order to use its non-const lock_.
00046 ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon,
00047 ((ACE_Thread_Manager *) this)->lock_));
00048
00049 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00050
00051 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ngrp_id_ = %d"), this->grp_id_));
00052 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncurrent_count_ = %d"), this->thr_list_.size ()));
00053
00054 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
00055 !iter.done ();
00056 iter.advance ())
00057 iter.next ()->dump ();
00058
00059 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00060 }
|
|
||||||||||||
|
Called to clean up when a thread exits.
Definition at line 1558 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, 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.
01559 {
01560 ACE_TRACE ("ACE_Thread_Manager::exit");
01561 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
01562 int close_handle = 0;
01563 #endif /* ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
01564
01565 #if defined (ACE_WIN32)
01566 // Remove detached thread handle.
01567
01568 if (do_thr_exit)
01569 {
01570 #if 0
01571 // @@ This callback is now taken care of by TSS_Cleanup. Do we
01572 // need it anymore?
01573
01574 // On Win32, if we really wants to exit from a thread, we must
01575 // first clean up the thread specific storage. By doing so,
01576 // ACE_Thread_Manager::exit will be called again with
01577 // do_thr_exit = 0 and cleaning up the ACE_Cleanup_Info (but not
01578 // exiting the thread.) After the following call returns, we
01579 // are safe to exit this thread.
01580 delete ACE_Thread_Exit::instance ();
01581 #endif /* 0 */
01582 ACE_Thread::exit (status);
01583 }
01584 #endif /* ACE_WIN32 */
01585
01586 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
01587 ACE_Cleanup_Info cleanup_info;
01588
01589 // Just hold onto the guard while finding this thread's id and
01590 // copying the exit hook.
01591 {
01592 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
01593
01594 // Find the thread id, but don't use the cache. It might have been
01595 // deleted already.
01596 #if defined (VXWORKS)
01597 ACE_hthread_t id;
01598 ACE_OS::thr_self (id);
01599 ACE_Thread_Descriptor *td = this->find_hthread (id);
01600 #else /* ! VXWORKS */
01601 ACE_thread_t id = ACE_OS::thr_self ();
01602 ACE_Thread_Descriptor *td = this->find_thread (id);
01603 #endif /* ! VXWORKS */
01604
01605 // Locate thread id.
01606 if (td != 0)
01607 {
01608 // @@ Currently, we have just one hook. This should clearly
01609 // be generalized to support an arbitrary number of hooks.
01610
01611 if (td->cleanup_info_.cleanup_hook_ != 0)
01612 {
01613 // Copy the hook so that we can call it after releasing
01614 // the guard.
01615 cleanup_info = td->cleanup_info_;
01616 td->cleanup_info_.cleanup_hook_ = 0;
01617 }
01618
01619 #if !defined (VXWORKS)
01620 // Threads created with THR_DAEMON shouldn't exist here, but
01621 // just to be safe, let's put it here.
01622
01623 if (ACE_BIT_DISABLED (td->thr_state_, ACE_THR_JOINING))
01624 if (ACE_BIT_DISABLED (td->flags_, THR_DETACHED | THR_DAEMON)
01625 || ACE_BIT_ENABLED (td->flags_, THR_JOINABLE))
01626 {
01627 // Mark thread as terminated.
01628 ACE_SET_BITS (td->thr_state_, ACE_THR_TERMINATED);
01629 this->register_as_terminated (td);
01630 // Must copy the information here because td will be "freed" below.
01631 }
01632 #if defined (ACE_WIN32)
01633 else
01634 {
01635 close_handle = 1;
01636 }
01637 #endif /* ACE_WIN32 */
01638 #endif /* ! VXWORKS */
01639
01640 // Remove thread descriptor from the table.
01641 this->remove_thr (td, close_handle);
01642 }
01643 // Release the guard.
01644 }
01645
01646 // Call the cleanup hook.
01647 if (cleanup_info.cleanup_hook_ != 0)
01648 (*cleanup_info.cleanup_hook_) (cleanup_info.object_,
01649 cleanup_info.param_);
01650 #else /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
01651 // Just hold onto the guard while finding this thread's id and
01652 {
01653 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
01654
01655 // Find the thread id, but don't use the cache. It might have been
01656 // deleted already.
01657 #if defined (VXWORKS)
01658 ACE_hthread_t id;
01659 ACE_OS::thr_self (id);
01660 ACE_Thread_Descriptor* td = this->find_hthread (id);
01661 #else /* ! VXWORKS */
01662 ACE_thread_t id = ACE_OS::thr_self ();
01663 ACE_Thread_Descriptor* td = this->find_thread (id);
01664 #endif /* ! VXWORKS */
01665 if (td != 0)
01666 {
01667 // @@ We call Thread_Descriptor terminate this realize the cleanup
01668 // process itself.
01669 td->terminate();
01670 }
01671 }
01672
01673
01674 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
01675
01676 if (do_thr_exit)
01677 {
01678 ACE_Thread::exit (status);
01679 // On reasonable systems <ACE_Thread::exit> should not return.
01680 // However, due to horrible semantics with Win32 thread-specific
01681 // storage this call can return (don't ask...).
01682 }
01683
01684 return 0;
01685 }
|
|
|
Locate the index of the table slot occupied by <h_id>. Returns -1 if <h_id> is not in the table doesn't contain <h_id>.
Definition at line 791 of file Thread_Manager.cpp. References ACE_hthread_t, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, ACE_Double_Linked_List_Iterator_Base::next, and ACE_OS::thr_cmp. Referenced by exit, and insert_thr.
00792 {
00793 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
00794 !iter.done ();
00795 iter.advance ())
00796 if (ACE_OS::thr_cmp (iter.next ()->thr_handle_, h_id))
00797 return iter.next ();
00798
00799 return 0;
00800 }
|
|
||||||||||||
|
Locate the thread descriptor address of the list occupied by <task>. Returns 0 if <task> is not in the table doesn't contain <task>. Definition at line 1931 of file Thread_Manager.cpp. References ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, and ACE_Double_Linked_List_Iterator_Base::next. Referenced by num_tasks_in_group, and task_list.
01932 {
01933 ACE_TRACE ("ACE_Thread_Manager::find_task");
01934
01935 size_t i = 0;
01936
01937 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01938 !iter.done ();
01939 iter.advance ())
01940 {
01941 if (i >= slot)
01942 break;
01943
01944 if (task == iter.next ()->task_)
01945 return iter.next ();
01946
01947 i++;
01948 }
01949
01950 return 0;
01951 }
|
|
|
Locate the index of the table slot occupied by <t_id>. Returns -1 if <t_id> is not in the table doesn't contain <t_id>.
Definition at line 806 of file Thread_Manager.cpp. References ACE_thread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, ACE_Double_Linked_List_Iterator_Base::next, and ACE_OS::thr_equal. Referenced by exit, insert_thr, and thread_desc_self.
00807 {
00808 ACE_TRACE ("ACE_Thread_Manager::find_thread");
00809
00810 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
00811 !iter.done ();
00812 iter.advance ())
00813 if (ACE_OS::thr_equal (iter.next ()->thr_id_, t_id))
00814 return iter.next ();
00815 return 0;
00816 }
|
|
||||||||||||
|
Get group ids for a particular task.
Definition at line 2221 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, ACE_MT, and ACE_TRACE.
02222 {
02223 ACE_TRACE ("ACE_Thread_Manager::get_grp");
02224 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02225
02226 ACE_FIND (this->find_task (task), ptr);
02227 grp_id = ptr->grp_id_;
02228 return 0;
02229 }
|
|
||||||||||||
|
Get group ids for a particular thread id.
Definition at line 1210 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, ACE_MT, ACE_thread_t, and ACE_TRACE.
01211 {
01212 ACE_TRACE ("ACE_Thread_Manager::get_grp");
01213 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01214
01215 ACE_FIND (this->find_thread (t_id), ptr);
01216
01217 if (ptr)
01218 grp_id = ptr->grp_id_;
01219 else
01220 return -1;
01221 return 0;
01222 }
|
|
|
Return a pointer to the thread's Thread_Descriptor, 0 if fail.
Definition at line 295 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, and ACE_TRACE.
00296 {
00297 ACE_TRACE ("ACE_Thread_Manager::hthread_descriptor");
00298 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
00299
00300 ACE_FIND (this->find_hthread (thr_handle), ptr);
00301 return ptr;
00302 }
|
|
||||||||||||||||
|
Returns in <hthread_list> a list of up to <n> thread handles in a group <grp_id>. The caller must allocate memory for <hthread_list>. Definition at line 2179 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, hthread_list, and ACE_Double_Linked_List_Iterator_Base::next.
02182 {
02183 ACE_TRACE ("ACE_Thread_Manager::hthread_grp_list");
02184 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02185
02186 size_t hthread_count = 0;
02187
02188 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02189 !iter.done ();
02190 iter.advance ())
02191 {
02192 if (hthread_count >= n)
02193 break;
02194
02195 if (iter.next ()->grp_id_ == grp_id)
02196 {
02197 hthread_list[hthread_count] = iter.next ()->thr_handle_;
02198 hthread_count++;
02199 }
02200 }
02201
02202 return hthread_count;
02203 }
|
|
||||||||||||||||
|
Returns in <hthread_list> a list of up to <n> thread handles in an <ACE_Task_Base>. The caller must allocate memory for <hthread_list>. 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 2123 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, hthread_list, and ACE_Double_Linked_List_Iterator_Base::next. Referenced by hthread_grp_list, and hthread_list.
02126 {
02127 ACE_TRACE ("ACE_Thread_Manager::hthread_list");
02128 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02129
02130 size_t hthread_count = 0;
02131
02132 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02133 !iter.done ();
02134 iter.advance ())
02135 {
02136 if (hthread_count >= n)
02137 break;
02138
02139 if (iter.next ()->task_ == task)
02140 {
02141 hthread_list[hthread_count] = iter.next ()->thr_handle_;
02142 hthread_count++;
02143 }
02144 }
02145
02146 return hthread_count;
02147 }
|
|
|
Check if the thread is managed by the thread manager. Return true if the thread is found, false otherwise.
Definition at line 1178 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, ACE_Double_Linked_List_Iterator_Base::next, and ACE_OS::thr_cmp.
01179 {
01180 ACE_TRACE ("ACE_Thread_Manager::hthread_within");
01181 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_monx, this->lock_, -1));
01182
01183 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01184 !iter.done ();
01185 iter.advance ())
01186 if (ACE_OS::thr_cmp(iter.next ()->thr_handle_, handle))
01187 return 1;
01188
01189 return 0;
01190 }
|
|
||||||||||||||||||||
|
Insert a thread in the table (checks for duplicates).
Definition at line 822 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, ACE_THR_SPAWNED, ACE_thread_t, ACE_TRACE, append_thr, find_hthread, find_thread, and grp_id_. Referenced by ACE_Thread_Control::ACE_Thread_Control, and ACE_Thread_Control::insert.
00826 {
00827 ACE_TRACE ("ACE_Thread_Manager::insert_thr");
00828 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00829
00830 // Check for duplicates and bail out if we're already registered...
00831 #if defined (VXWORKS)
00832 if (this->find_hthread (t_handle) != 0 )
00833 return -1;
00834 #else /* ! VXWORKS */
00835 if (this->find_thread (t_id) != 0 )
00836 return -1;
00837 #endif /* ! VXWORKS */
00838
00839 if (grp_id == -1)
00840 grp_id = this->grp_id_++;
00841
00842 if (this->append_thr (t_id,
00843 t_handle,
00844 ACE_THR_SPAWNED,
00845 grp_id,
00846 0,
00847 flags) == -1)
00848 return -1;
00849
00850 return grp_id;
00851 }
|
|
|
Set pointer to a process-wide <ACE_Thread_Manager> and return existing pointer.
Definition at line 364 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, delete_thr_mgr_, ACE_Static_Object_Lock::instance, and thr_mgr_.
00365 {
00366 ACE_TRACE ("ACE_Thread_Manager::instance");
00367 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00368 *ACE_Static_Object_Lock::instance (), 0));
00369
00370 ACE_Thread_Manager *t = ACE_Thread_Manager::thr_mgr_;
00371 // We can't safely delete it since we don't know who created it!
00372 ACE_Thread_Manager::delete_thr_mgr_ = 0;
00373
00374 ACE_Thread_Manager::thr_mgr_ = tm;
00375 return t;
00376 }
|
|
|
Get pointer to a process-wide <ACE_Thread_Manager>.
Definition at line 341 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_NEW_RETURN, ACE_TRACE, delete_thr_mgr_, ACE_Static_Object_Lock::instance, and thr_mgr_. Referenced by ACE_Schedule_All_Threaded_Strategy::ACE_Schedule_All_Threaded_Strategy, and ACE_Task_Base::activate.
00342 {
00343 ACE_TRACE ("ACE_Thread_Manager::instance");
00344
00345 if (ACE_Thread_Manager::thr_mgr_ == 0)
00346 {
00347 // Perform Double-Checked Locking Optimization.
00348 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00349 *ACE_Static_Object_Lock::instance (), 0));
00350
00351 if (ACE_Thread_Manager::thr_mgr_ == 0)
00352 {
00353 ACE_NEW_RETURN (ACE_Thread_Manager::thr_mgr_,
00354 ACE_Thread_Manager,
00355 0);
00356 ACE_Thread_Manager::delete_thr_mgr_ = 1;
00357 }
00358 }
00359
00360 return ACE_Thread_Manager::thr_mgr_;
00361 }
|
|
||||||||||||
|
Join a thread specified by <tid>. Do not wait on a detached thread.
Definition at line 1380 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_MT, ACE_SET_BITS, ACE_THR_JOINING, ACE_thread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator::advance_and_remove, ACE_Double_Linked_List_Iterator_Base::done, ACE_Thread::join, ACE_Double_Linked_List_Iterator_Base::next, ACE_OS::thr_equal, and ACE_Thread_Descriptor_Base::thr_handle_.
01381 {
01382 ACE_TRACE ("ACE_Thread_Manager::join");
01383
01384 ACE_Thread_Descriptor_Base tdb;
01385 int found = 0;
01386
01387 {
01388 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01389
01390 #if !defined (VXWORKS)
01391 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor_Base> biter (this->terminated_thr_list_);
01392 !biter.done ();
01393 biter.advance ())
01394 if (ACE_OS::thr_equal (biter.next ()->thr_id_, tid))
01395 {
01396 ACE_Thread_Descriptor_Base *tdb = biter.advance_and_remove (0);
01397 # if defined (_AIX)
01398 // The AIX xlC compiler does not match the proper function here - it
01399 // confuses ACE_Thread::join(ACE_thread_t, ACE_thread_t *, void **=0) and
01400 // ACE_Thread::join(ACE_hthread_t, void **=0). At least at 3.1.4.7 and .8.
01401 // The 2nd arg is ignored for pthreads anyway.
01402
01403 // And, g++ on AIX needs the three-arg thr_join, also, to pick up the
01404 // proper version from the AIX libraries.
01405 if (ACE_Thread::join (tdb->thr_handle_,
01406 &tdb->thr_handle_,
01407 status) == -1)
01408 # else /* ! _AIX */
01409 if (ACE_Thread::join (tdb->thr_handle_, status) == -1)
01410 # endif /* ! _AIX */
01411 return -1;
01412
01413 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH)
01414 // Must explicitly detach threads. Threads without THR_DETACHED
01415 // were detached in ACE_OS::thr_create ().
01416 ::pthread_detach (&tdb->thr_handle_);
01417 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */
01418
01419 delete tdb;
01420 return 0;
01421 // return immediately if we've found the thread we want to join.
01422 }
01423 #endif /* !VXWORKS */
01424
01425 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01426 !iter.done ();
01427 iter.advance ())
01428 // If threads are created as THR_DETACHED or THR_DAEMON, we
01429 // can't help much.
01430 if (ACE_OS::thr_equal (iter.next ()->thr_id_,tid) &&
01431 (ACE_BIT_DISABLED (iter.next ()->flags_, THR_DETACHED | THR_DAEMON)
01432 || ACE_BIT_ENABLED (iter.next ()->flags_, THR_JOINABLE)))
01433 {
01434 tdb = *iter.next ();
01435 ACE_SET_BITS (iter.next ()->thr_state_, ACE_THR_JOINING);
01436 found = 1;
01437 break;
01438 }
01439
01440 if (found == 0)
01441 return -1;
01442 // Didn't find the thread we want or the thread is not joinable.
01443 }
01444
01445 # if defined (_AIX)
01446 // The AIX xlC compiler does not match the proper function here - it
01447 // confuses ACE_Thread::join(ACE_thread_t, ACE_thread_t *, void **=0) and
01448 // ACE_Thread::join(ACE_hthread_t, void **=0). At least at 3.1.4.7 and .8.
01449 // The 2nd arg is ignored for pthreads anyway.
01450
01451 // And, g++ on AIX needs the three-arg thr_join, also, to pick up the
01452 // proper version from the AIX libraries.
01453 if (ACE_Thread::join (tdb.thr_handle_, &tdb.thr_handle_, status) == -1)
01454 # else /* ! _AIX */
01455 if (ACE_Thread::join (tdb.thr_handle_, status) == -1)
01456 # endif /* ! _AIX */
01457 return -1;
01458
01459 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH)
01460 // Must explicitly detach threads. Threads without THR_DETACHED
01461 // were detached in ACE_OS::thr_create ().
01462
01463 # if defined (HPUX_10)
01464 // HP-UX DCE threads' pthread_detach will smash thr_id if it's just given
01465 // as an argument. Since the thread handle is still needed, give
01466 // pthread_detach a junker to scribble on.
01467 ACE_thread_t junker;
01468 cma_handle_assign(&tdb.thr_handle_, &junker);
01469 ::pthread_detach (&junker);
01470 # else
01471 ::pthread_detach (&tdb.thr_handle_);
01472 #endif /* HPUX_10 */
01473 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */
01474 return 0;
01475 }
|
|
||||||||||||
|
Join the thread described in <tda>.
Definition at line 961 of file Thread_Manager.cpp. References ACE_TRACE, ACE_Thread::join, and ACE_Thread_Descriptor_Base::thr_handle_.
00962 {
00963 ACE_TRACE ("ACE_Thread_Manager::join_thr");
00964 int result = ACE_Thread::join (td->thr_handle_);
00965 if (result != 0)
00966 {
00967 // Since the thread are being joined, we should
00968 // let it remove itself from the list.
00969
00970 // this->remove_thr (td);
00971 errno = result;
00972 return -1;
00973 }
00974
00975 return 0;
00976 }
|
|
||||||||||||
|
Definition at line 1107 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, ACE_thread_t, and ACE_TRACE.
01108 {
01109 ACE_TRACE ("ACE_Thread_Manager::kill");
01110 ACE_EXECUTE_OP (this->kill_thr, signum);
01111 }
|
|
|
Send <signum> to all stopped threads. Not supported on platforms that do not have advanced signal support, such as Win32. Send the <signum> to a single thread. Not supported on platforms that do not have advanced signal support, such as Win32. Send <signum> to a group of threads, not supported on platforms that do not have advanced signal support, such as Win32. Definition at line 1365 of file Thread_Manager.cpp. References ACE_TRACE, apply_all, and kill_thr.
01366 {
01367 ACE_TRACE ("ACE_Thread_Manager::kill_all");
01368 return this->apply_all (&ACE_Thread_Manager::kill_thr, sig);
01369 }
|
|
||||||||||||
|
Definition at line 1298 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp, and kill_thr.
01299 {
01300 ACE_TRACE ("ACE_Thread_Manager::kill_grp");
01301 return this->apply_grp (grp_id,
01302 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::kill_thr), signum);
01303 }
|
|
||||||||||||
|
Send a signal <signum> to all threads in an <ACE_Task>. Definition at line 1908 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task, and kill_thr.
01909 {
01910 ACE_TRACE ("ACE_Thread_Manager::kill_task");
01911 return this->apply_task (task,
01912 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::kill_thr));
01913 }
|
|
||||||||||||
|
Send signal <signum> to the thread described in <tda>.
Definition at line 1029 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.
01030 {
01031 ACE_TRACE ("ACE_Thread_Manager::kill_thr");
01032
01033 ACE_thread_t tid = td->thr_id_;
01034 #if defined (VXWORKS)
01035 // Skip over the ID-allocated marker, if present.
01036 tid += tid[0] == ACE_THR_ID_ALLOCATED ? 1 : 0;
01037 #endif /* VXWORKS */
01038
01039 int result = ACE_Thread::kill (tid, signum);
01040
01041 if (result != 0)
01042 {
01043 // Only remove a thread from us when there is a "real" error.
01044 if (errno != ENOTSUP)
01045 this->thr_to_be_removed_.enqueue_tail (td);
01046
01047 return -1;
01048 }
01049 #if defined (CHORUS)
01050 else if (signum == SIGTHREADKILL)
01051 this->thr_to_be_removed_.enqueue_tail (td);
01052 #endif /* CHORUS */
01053
01054 return 0;
01055 }
|
|
|
Returns the number of <ACE_Task_Base> in a group.
Definition at line 1956 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, find_task, and ACE_Double_Linked_List_Iterator_Base::next.
01957 {
01958 ACE_TRACE ("ACE_Thread_Manager::num_tasks_in_group");
01959 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01960
01961 int tasks_count = 0;
01962 size_t i = 0;
01963
01964 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01965 !iter.done ();
01966 iter.advance ())
01967 {
01968 if (iter.next ()->grp_id_ == grp_id
01969 && this->find_task (iter.next ()->task_, i) == 0
01970 && iter.next ()->task_ != 0)
01971 tasks_count++;
01972
01973 i++;
01974 }
01975 return tasks_count;
01976 }
|
|
|
Returns the number of threads in an <ACE_Task_Base>.
Definition at line 1981 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, and ACE_Double_Linked_List_Iterator_Base::next.
01982 {
01983 ACE_TRACE ("ACE_Thread_Manager::num_threads_in_task");
01984 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01985
01986 int threads_count = 0;
01987
01988 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01989 !iter.done ();
01990 iter.advance ())
01991 if (iter.next ()->task_ == task)
01992 threads_count++;
01993
01994 return threads_count;
01995 }
|
|
|
No-op. Currently unused.
Definition at line 263 of file Thread_Manager.i.
00264 {
00265 // Currently no-op.
00266 return 0;
00267 }
|
|
|
Register a thread as terminated and put it into the <terminated_thr_list_>.
Definition at line 318 of file Thread_Manager.i. References ACE_NEW_RETURN, ACE_Double_Linked_List< ACE_Thread_Descriptor_Base >::insert_tail, and terminated_thr_list_. Referenced by exit, and ACE_Thread_Descriptor::terminate.
00319 {
00320 #if defined (VXWORKS)
00321 ACE_UNUSED_ARG (td);
00322 #else /* ! VXWORKS */
00323 ACE_Thread_Descriptor_Base *tdb;
00324 ACE_NEW_RETURN (tdb, ACE_Thread_Descriptor_Base (*td), -1);
00325 this->terminated_thr_list_.insert_tail (tdb);
00326 #endif /* ! VXWORKS */
00327 return 0;
00328 }
|
|
||||||||||||
|
Remove thread from the table.
Definition at line 882 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_Double_Linked_List< ACE_Thread_Descriptor >::remove, ACE_Thread_Descriptor::self, ACE_Double_Linked_List< ACE_Thread_Descriptor >::size, 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, ACE_Thread_Descriptor::terminate, and wait.
00884 {
00885 ACE_TRACE ("ACE_Thread_Manager::remove_thr");
00886
00887 #if defined (VXWORKS)
00888 ACE_thread_t tid = td->self ();
00889 #endif /* VXWORKS */
00890
00891 #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
00892 td->tm_ = 0;
00893 #endif /* !ACE_USE_ONE_SHOT_AT_THREAD_EXIT */
00894 this->thr_list_.remove (td);
00895
00896 #if defined (VXWORKS)
00897 // Delete the thread ID, if the ACE_Thread_Manager allocated it.
00898 if (tid && tid[0] == ACE_THR_ID_ALLOCATED)
00899 {
00900 delete [] tid;
00901 }
00902 #endif /* VXWORKS */
00903
00904 #if defined (ACE_WIN32)
00905 if (close_handler != 0)
00906 ::CloseHandle (td->thr_handle_);
00907 #else
00908 ACE_UNUSED_ARG (close_handler);
00909 #endif /* ACE_WIN32 */
00910
00911 #if 1
00912
00913 this->thread_desc_freelist_.add (td);
00914 #else
00915 delete td;
00916 #endif /* 1 */
00917
00918 #if defined (ACE_HAS_THREADS)
00919 // Tell all waiters when there are no more threads left in the pool.
00920 if (this->thr_list_.size () == 0)
00921 this->zero_cond_.broadcast ();
00922 #endif /* ACE_HAS_THREADS */
00923 }
|
|
|
Remove all threads from the table.
Definition at line 929 of file Thread_Manager.cpp. References ACE_Double_Linked_List< ACE_Thread_Descriptor >::delete_head, ACE_Thread_Descriptor_Base::thr_handle_, and thr_list_. Referenced by close, and wait.
00930 {
00931 ACE_Thread_Descriptor *td;
00932
00933 while ((td = this->thr_list_.delete_head ()) != 0)
00934 {
00935 #if defined (ACE_WIN32)
00936 // We need to let go handles if we want to let the threads
00937 // run wild.
00938 // @@ Do we need to close down AIX thread handles too?
00939 ::CloseHandle (td->thr_handle_);
00940 #endif /* ACE_WIN32 */
00941 delete td;
00942 }
00943
00944 }
|
|
|
Resume a single thread.
Definition at line 1089 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, ACE_thread_t, and ACE_TRACE.
01090 {
01091 ACE_TRACE ("ACE_Thread_Manager::resume");
01092 ACE_EXECUTE_OP (this->resume_thr, 0);
01093 }
|
|
|
Resume all stopped threads.
Definition at line 1351 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_all, and resume_thr. Referenced by ACE_Schedule_All_Threaded_Strategy::resume.
01352 {
01353 ACE_TRACE ("ACE_Thread_Manager::resume_all");
01354 return this->apply_all (ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::resume_thr));
01355 }
|
|
|
Resume a group of threads.
Definition at line 1288 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp, and resume_thr.
01289 {
01290 ACE_TRACE ("ACE_Thread_Manager::resume_grp");
01291 return this->apply_grp (grp_id,
01292 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::resume_thr));
01293 }
|
|
|
Resume all threads in an ACE_Task. Definition at line 1898 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task, and resume_thr. Referenced by ACE_Task_Base::resume.
01899 {
01900 ACE_TRACE ("ACE_Thread_Manager::resume_task");
01901 return this->apply_task (task,
01902 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::resume_thr));
01903 }
|
|
||||||||||||
|
Resume the thread described in <tda>.
Definition at line 996 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.
00997 {
00998 ACE_TRACE ("ACE_Thread_Manager::resume_thr");
00999
01000 int result = ACE_Thread::resume (td->thr_handle_);
01001 if (result == -1) {
01002 if (errno != ENOTSUP)
01003 this->thr_to_be_removed_.enqueue_tail (td);
01004 return -1;
01005 }
01006 else {
01007 ACE_CLR_BITS (td->thr_state_, ACE_THR_SUSPENDED);
01008 return 0;
01009 }
01010 }
|
|
|
Run the registered hooks when the thread exits.
Definition at line 856 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.
00857 {
00858 #if 0 // currently unused!
00859 ACE_TRACE ("ACE_Thread_Manager::run_thread_exit_hooks");
00860
00861 // @@ Currently, we have just one hook. This should clearly be
00862 // generalized to support an arbitrary number of hooks.
00863
00864 ACE_Thread_Descriptor *td = this->thread_desc_self ();
00865 if (td != 0 && td->cleanup_info.cleanup_hook_ != 0)
00866 {
00867 (*td->cleanup_info_.cleanup_hook_)
00868 (td->cleanup_info_.object_,
00869 td->cleanup_info_.param_);
00870
00871 td->cleanup_info_.cleanup_hook_ = 0;
00872 }
00873 ACE_UNUSED_ARG (i);
00874 #else
00875 ACE_UNUSED_ARG (i);
00876 #endif /* 0 */
00877 }
|
|
||||||||||||
|
Set group ids for a particular task.
Definition at line 2206 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, and ACE_Double_Linked_List_Iterator_Base::next.
02207 {
02208 ACE_TRACE ("ACE_Thread_Manager::set_grp");
02209 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02210
02211 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02212 !iter.done ();
02213 iter.advance ())
02214 if (iter.next ()->task_ == task)
02215 iter.next ()->grp_id_ = grp_id;
02216
02217 return 0;
02218 }
|
|
||||||||||||
|
Set group ids for a particular thread id.
Definition at line 1227 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, ACE_MT, ACE_thread_t, and ACE_TRACE. Referenced by ACE_Task_Base::grp_id.
01228 {
01229 ACE_TRACE ("ACE_Thread_Manager::set_grp");
01230 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01231
01232 ACE_FIND (this->find_thread (t_id), ptr);
01233 if (ptr)
01234 ptr->grp_id_ = grp_id;
01235 else
01236 return -1;
01237 return 0;
01238 }
|
|
|
Setting the static ACE_TSS_TYPE (ACE_Thread_Exit) *thr_exit_ pointer.
Referenced by ACE_Thread_Exit::instance. |
|
||||||||||||||||||||||||||||||||||||||||
|
Create a new thread, which executes <func>. 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 642 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, ACE_thread_t, ACE_TRACE, grp_id_, and spawn_i. Referenced by ACE_Event_Handler::register_stdin_handler.
00651 {
00652 ACE_TRACE ("ACE_Thread_Manager::spawn");
00653
00654 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00655
00656 if (grp_id == -1)
00657 grp_id = this->grp_id_++; // Increment the group id.
00658
00659 if (this->spawn_i (func, args, flags, t_id, t_handle,
00660 priority, grp_id, stack, stack_size) == -1)
00661 return -1;
00662
00663 return grp_id;
00664 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Create a new thread (must be called with locks held).
Definition at line 505 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_BIT_DISABLED, ACE_hthread_t, ACE_NEW_RETURN, ACE_THR_SPAWNED, ACE_thread_t, ACE_TRACE, append_thr, ACE_Auto_Basic_Ptr::get, ACE_Auto_Basic_Ptr::release, ACE_Auto_Basic_Ptr::reset, and ACE_Thread::spawn. Referenced by spawn, and spawn_n.
00515 {
00516 // First, threads created by Thread Manager should not be daemon threads.
00517 // Using assertion is probably a bit too strong. However, it helps
00518 // finding this kind of error as early as possible. Perhaps we can replace
00519 // assertion by returning error.
00520 ACE_ASSERT (ACE_BIT_DISABLED (flags, THR_DAEMON));
00521
00522 // Create a new thread running <func>. *Must* be called with the
00523 // <lock_> held...
00524 // Get a "new" Thread Descriptor from the freelist.
00525 auto_ptr<ACE_Thread_Descriptor> new_thr_desc (this->thread_desc_freelist_.remove ());
00526
00527 // Reset thread descriptor status
00528 new_thr_desc->reset (this);
00529
00530 ACE_Thread_Adapter *thread_args = 0;
00531 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00532 ACE_NEW_RETURN (thread_args,
00533 ACE_Thread_Adapter (func,
00534 args,
00535 (ACE_THR_C_FUNC) ace_thread_adapter,
00536 this,
00537 new_thr_desc.get (),
00538 ACE_OS_Object_Manager::seh_except_selector(),
00539 ACE_OS_Object_Manager::seh_except_handler()),
00540 -1);
00541 #else
00542 ACE_NEW_RETURN (thread_args,
00543 ACE_Thread_Adapter (func,
00544 args,
00545 (ACE_THR_C_FUNC) ace_thread_adapter,
00546 this,
00547 new_thr_desc.get ()),
00548 -1);
00549 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00550
00551 ACE_TRACE ("ACE_Thread_Manager::spawn_i");
00552 ACE_hthread_t thr_handle;
00553
00554 #if defined (VXWORKS)
00555 // On VxWorks, ACE_thread_t is char *. If t_id is 0, allocate space
00556 // for ACE_OS::thr_create () to store the task name. If t_id is not
00557 // 0, and it doesn't point to a 0 char *, then the non-zero char *
00558 // will be used for the task name in ACE_OS::thr_create (). If t_id
00559 // is not 0, but does point to a 0 char *, the t_id will be set to
00560 // point to the task name in the TCB in ACE_OS::thr_create ().
00561 if (t_id == 0)
00562 {
00563 char *thr_id;
00564 ACE_NEW_RETURN (thr_id,
00565 char[16],
00566 -1);
00567 // Mark the thread ID to show that the ACE_Thread_Manager
00568 // allocated it.
00569 thr_id[0] = ACE_THR_ID_ALLOCATED;
00570 thr_id[1] = '\0';
00571 t_id = &thr_id;
00572 }
00573 #else /* ! VXWORKS */
00574 ACE_thread_t thr_id;
00575 if (t_id == 0)
00576 t_id = &thr_id;
00577 #endif /* ! VXWORKS */
00578
00579 new_thr_desc->sync_->acquire ();
00580 // Acquire the <sync_> lock to block the spawned thread from
00581 // removing this Thread Descriptor before it gets put into our
00582 // thread table.
00583
00584 int result = ACE_Thread::spawn (func,
00585 args,
00586 flags,
00587 t_id,
00588 &thr_handle,
00589 priority,
00590 stack,
00591 stack_size,
00592 thread_args);
00593
00594 if (result != 0)
00595 {
00596 // _Don't_ clobber errno here! result is either 0 or -1, and
00597 // ACE_OS::thr_create () already set errno! D. Levine 28 Mar 1997
00598 // errno = result;
00599 ACE_Errno_Guard guard (errno); // Lock release may smash errno
00600 new_thr_desc->sync_->release ();
00601 return -1;
00602 }
00603 else
00604 {
00605 #if defined (ACE_HAS_WTHREADS)
00606 // Have to duplicate handle if client asks for it.
00607 // @@ How are thread handles implemented on AIX? Do they
00608 // also need to be duplicated?
00609 if (t_handle != 0)
00610 # if defined (ACE_HAS_WINCE)
00611 *t_handle = thr_handle;
00612 # else /* ! ACE_HAS_WINCE */
00613 (void) ::DuplicateHandle (::GetCurrentProcess (),
00614 thr_handle,
00615 ::GetCurrentProcess (),
00616 t_handle,
00617 0,
00618 TRUE,
00619 DUPLICATE_SAME_ACCESS);
00620 # endif /* ! ACE_HAS_WINCE */
00621 #elif defined (VXWORKS)
00622 if (t_handle != 0)
00623 *t_handle = thr_handle;
00624 #else /* ! ACE_HAS_WTHREADS && ! VXWORKS */
00625 ACE_UNUSED_ARG (t_handle);
00626 #endif /* ! ACE_HAS_WTHREADS && ! VXWORKS */
00627
00628 // append_thr also put the <new_thr_desc> into Thread_Manager's
00629 // double-linked list. Only after this point, can we manipulate
00630 // double-linked list from a spawned thread's context.
00631 return this->append_thr (*t_id,
00632 thr_handle,
00633 ACE_THR_SPAWNED,
00634 grp_id,
00635 task,
00636 flags,
00637 new_thr_desc.release ());
00638 }
00639 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Spawn N new threads, which execute <func> with argument <arg>. If <thread_ids> != 0 the thread_ids of successfully spawned threads will be placed into the <thread_ids> buffer (which must be the same size as <n>). If <stack> != 0 it is assumed to be an array of <n> pointers to the base of the stacks to use for the threads being spawned. If <stack_size> != 0 it is assumed to be an array of <n> values indicating how big each of the corresponding <stack>s are. If <thread_handles> != 0 it is assumed to be an array of <n> 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 <grp_id> or <task> using functions such as kill_grp() or cancel_task(). If <grp_id> is assigned, the newly spawned threads are added into the group. Otherwise, the Thread_Manager assigns these <n> threads with a grp_id. You should choose either assigning <grp_id> everytime, or let the Thread_Manager handles it for you consistently. The argument <task> is usually assigned by <ACE_Task_Base::activate>. It associates the newly spawned threads with an ACE_Task instance, which defaults to <this>.
Definition at line 709 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, ACE_thread_t, ACE_TRACE, grp_id_, and spawn_i.
00720 {
00721 ACE_TRACE ("ACE_Thread_Manager::spawn_n");
00722 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00723
00724 if (grp_id == -1)
00725 grp_id = this->grp_id_++; // Increment the group id.
00726
00727 for (size_t i = 0; i < n; i++)
00728 {
00729 // @@ What should happen if this fails?! e.g., should we try to
00730 // cancel the other threads that we've already spawned or what?
00731 if (this->spawn_i (func,
00732 args,
00733 flags,
00734 thread_ids == 0 ? 0 : &thread_ids[i],
00735 thread_handles == 0 ? 0 : &thread_handles[i],
00736 priority,
00737 grp_id,
00738 stack == 0 ? 0 : stack[i],
00739 stack_size == 0 ? 0 : stack_size[i],
00740 task) == -1)
00741 return -1;
00742 }
00743
00744 return grp_id;
00745 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Spawn N new threads, which execute <func> with argument <arg>. If <thread_ids> != 0 the thread_ids of successfully spawned threads will be placed into the <thread_ids> buffer (which must be the same size as <n>). If <stack> != 0 it is assumed to be an array of <n> pointers to the base of the stacks to use for the threads being spawned. If <stack_size> != 0 it is assumed to be an array of <n> values indicating how big each of the corresponding <stack>s are. If <thread_handles> != 0 it is assumed to be an array of <n> 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 <grp_id> or <task> using functions such as kill_grp() or cancel_task(). If <grp_id> is assigned, the newly spawned threads are added into the group. Otherwise, the Thread_Manager assigns these <n> threads with a grp_id. You should choose either assigning <grp_id> everytime, or let the Thread_Manager handles it for you consistently. The argument <task> is usually assigned by <ACE_Task_Base::activate>. It associates the newly spawned threads with an ACE_Task instance, which defaults to <this>.
Definition at line 669 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_hthread_t, ACE_MT, ACE_TRACE, grp_id_, and spawn_i. Referenced by ACE_Task_Base::activate.
00679 {
00680 ACE_TRACE ("ACE_Thread_Manager::spawn_n");
00681 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00682
00683 if (grp_id == -1)
00684 grp_id = this->grp_id_++; // Increment the group id.
00685
00686 for (size_t i = 0; i < n; i++)
00687 {
00688 // @@ What should happen if this fails?! e.g., should we try to
00689 // cancel the other threads that we've already spawned or what?
00690 if (this->spawn_i (func,
00691 args,
00692 flags,
00693 0,
00694 thread_handles == 0 ? 0 : &thread_handles[i],
00695 priority,
00696 grp_id,
00697 stack == 0 ? 0 : stack[i],
00698 stack_size == 0 ? 0 : stack_size[i],
00699 task) == -1)
00700 return -1;
00701 }
00702
00703 return grp_id;
00704 }
|
|
|
Suspend a single thread.
Definition at line 1080 of file Thread_Manager.cpp. References ACE_EXECUTE_OP, ACE_thread_t, and ACE_TRACE.
01081 {
01082 ACE_TRACE ("ACE_Thread_Manager::suspend");
01083 ACE_EXECUTE_OP (this->suspend_thr, 0);
01084 }
|
|
|
Suspend all threads.
Definition at line 1358 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_all, and suspend_thr. Referenced by ACE_Schedule_All_Threaded_Strategy::suspend.
01359 {
01360 ACE_TRACE ("ACE_Thread_Manager::suspend_all");
01361 return this->apply_all (ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::suspend_thr));
01362 }
|
|
|
Suspend a group of threads.
Definition at line 1278 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_grp, and suspend_thr.
01279 {
01280 ACE_TRACE ("ACE_Thread_Manager::suspend_grp");
01281 return this->apply_grp (grp_id,
01282 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::suspend_thr));
01283 }
|
|
|
Suspend all threads in an ACE_Task. Definition at line 1889 of file Thread_Manager.cpp. References ACE_THR_MEMBER_FUNC, ACE_TRACE, apply_task, and suspend_thr. Referenced by ACE_Task_Base::suspend.
01890 {
01891 ACE_TRACE ("ACE_Thread_Manager::suspend_task");
01892 return this->apply_task (task,
01893 ACE_THR_MEMBER_FUNC (&ACE_Thread_Manager::suspend_thr));
01894 }
|
|
||||||||||||
|
Suspend the thread described in <tda>.
Definition at line 979 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.
00980 {
00981 ACE_TRACE ("ACE_Thread_Manager::suspend_thr");
00982
00983 int result = ACE_Thread::suspend (td->thr_handle_);
00984 if (result == -1) {
00985 if (errno != ENOTSUP)
00986 this->thr_to_be_removed_.enqueue_tail (td);
00987 return -1;
00988 }
00989 else {
00990 ACE_SET_BITS (td->thr_state_, ACE_THR_SUSPENDED);
00991 return 0;
00992 }
00993 }
|
|
|
Returns a pointer to the current <ACE_Task_Base> we're executing in if this thread is indeed running in an <ACE_Task_Base>, else return 0. Definition at line 250 of file Thread_Manager.i. References ACE_TRACE, ACE_Thread_Descriptor_Base::task, and thread_desc_self.
00251 {
00252 ACE_TRACE ("ACE_Thread_Manager::task");
00253
00254 ACE_Thread_Descriptor *td = this->thread_desc_self () ;
00255
00256 if (td == 0)
00257 return 0;
00258 else
00259 return td->task ();
00260 }
|
|
||||||||||||
|
Returns in <task_list> a list of up to <n> <ACE_Tasks>. The caller must allocate the memory for <task_list>. 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 2000 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, and ACE_Double_Linked_List_Iterator_Base::next.
02002 {
02003 ACE_TRACE ("ACE_Thread_Manager::task_all_list");
02004 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02005
02006 size_t task_list_count = 0;
02007
02008 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02009 !iter.done ();
02010 iter.advance ())
02011 {
02012 if (task_list_count >= n)
02013 break;
02014
02015 ACE_Task_Base *task_p = iter.next ()->task_;
02016 if (0 != task_p)
02017 {
02018 // This thread has a task pointer; see if it's already in the
02019 // list. Don't add duplicates.
02020 size_t i = 0;
02021 for (; i < task_list_count; ++i)
02022 if (task_list[i] == task_p)
02023 break;
02024 if (i == task_list_count) // No match - add this one
02025 task_list[task_list_count++] = task_p;
02026 }
02027 }
02028
02029 return task_list_count;
02030 }
|
|
||||||||||||||||
|
Returns in <task_list> a list of up to <n> <ACE_Tasks> in a group. The caller must allocate the memory for <task_list>. 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 2060 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, find_task, and ACE_Double_Linked_List_Iterator_Base::next.
02063 {
02064 ACE_TRACE ("ACE_Thread_Manager::task_list");
02065 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02066
02067 ACE_Task_Base **task_list_iterator = task_list;
02068 size_t task_list_count = 0;
02069 size_t i = 0;
02070
02071 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02072 !iter.done ();
02073 iter.advance ())
02074 {
02075 if (task_list_count >= n)
02076 break;
02077
02078 if (iter.next ()->grp_id_ == grp_id
02079 && this->find_task (iter.next ()->task_, i) == 0)
02080 {
02081 task_list_iterator[task_list_count] = iter.next ()->task_;
02082 task_list_count++;
02083 }
02084
02085 i++;
02086 }
02087
02088 return task_list_count;
02089 }
|
|
|
True if <t_id> is cancelled, else false. Always return false if <t_id> is not managed by the Thread_Manager. Definition at line 1169 of file Thread_Manager.cpp. References ACE_THR_CANCELLED, ACE_thread_t, ACE_TRACE, and check_state.
01170 {
01171 ACE_TRACE ("ACE_Thread_Manager::testcancel");
01172 return this->check_state (ACE_THR_CANCELLED, t_id);
01173 }
|
|
|
True if <t_id> is active (i.e., resumed), else false. Always return false if <t_id> is not managed by the Thread_Manager. Definition at line 1160 of file Thread_Manager.cpp. References ACE_THR_SUSPENDED, ACE_thread_t, ACE_TRACE, and check_state.
01161 {
01162 ACE_TRACE ("ACE_Thread_Manager::testresume");
01163 return this->check_state (ACE_THR_SUSPENDED, t_id, 0);
01164 }
|
|
|
True if <t_id> is inactive (i.e., suspended), else false. Always return false if <t_id> is not managed by the Thread_Manager. Definition at line 1151 of file Thread_Manager.cpp. References ACE_THR_SUSPENDED, ACE_thread_t, ACE_TRACE, and check_state.
01152 {
01153 ACE_TRACE ("ACE_Thread_Manager::testsuspend");
01154 return this->check_state (ACE_THR_SUSPENDED, t_id);
01155 }
|
|
|
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 243 of file Thread_Manager.i. References ACE_TRACE, and ACE_Thread::self.
00244 {
00245 ACE_TRACE ("ACE_Thread_Manager::thr_self");
00246 return ACE_Thread::self ();
00247 }
|
|
|
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 307 of file Thread_Manager.cpp. References ACE_hthread_t, ACE_TRACE, ACE_Thread_Descriptor::self, and thread_desc_self.
00308 {
00309 ACE_TRACE ("ACE_Thread_Manager::thr_self");
00310
00311 ACE_Thread_Descriptor *desc =
00312 this->thread_desc_self ();
00313
00314 if (desc == 0)
00315 return -1;
00316 else
00317 desc->self (self);
00318
00319 return 0;
00320 }
|
|
||||||||||||
|
Returns in <thread_list> a list of up to <n> thread ids. The caller must allocate the memory for <thread_list>. 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 2035 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_thread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, ACE_Double_Linked_List_Iterator_Base::next, and thread_list.
02037 {
02038 ACE_TRACE ("ACE_Thread_Manager::thread_all_list");
02039 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02040
02041 size_t thread_count = 0;
02042
02043 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02044 !iter.done ();
02045 iter.advance ())
02046 {
02047 if (thread_count >= n)
02048 break;
02049
02050 thread_list[thread_count] = iter.next ()->thr_id_;
02051 thread_count ++;
02052 }
02053
02054 return thread_count;
02055 }
|
|
|
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 213 of file Thread_Manager.i. 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.
00214 {
00215 // This method must be called with lock held.
00216
00217 // Try to get it from cache.
00218 ACE_Thread_Descriptor *desc = ACE_LOG_MSG->thr_desc ();
00219
00220 #if 1
00221 // ACE_ASSERT (desc != 0);
00222 // Thread descriptor should always get cached.
00223 #else
00224 if (desc == 0)
00225 {
00226 ACE_thread_t id = ACE_OS::thr_self ();
00227
00228 desc = this->find_thread (id);
00229
00230 // Thread descriptor adapter might not have been put into the
00231 // list yet.
00232 if (desc != 0)
00233 // Update the TSS cache.
00234 ACE_LOG_MSG->thr_desc (desc);
00235 }
00236 #endif
00237 return desc;
00238 }
|
|
|
Return a pointer to the thread's Thread_Descriptor, 0 if fail.
Definition at line 285 of file Thread_Manager.cpp. References ACE_FIND, ACE_GUARD_RETURN, ACE_MT, ACE_thread_t, and ACE_TRACE.
00286 {
00287 ACE_TRACE ("ACE_Thread_Manager::thread_descriptor");
00288 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
00289
00290 ACE_FIND (this->find_thread (thr_id), ptr);
00291 return ptr;
00292 }
|
|
||||||||||||||||
|
Returns in <thread_list> a list of up to <n> thread ids in a group <grp_id>. The caller must allocate the memory for <thread_list>. 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 2150 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_thread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, ACE_Double_Linked_List_Iterator_Base::next, and thread_list.
02153 {
02154 ACE_TRACE ("ACE_Thread_Manager::thread_grp_list");
02155 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02156
02157 size_t thread_count = 0;
02158
02159 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02160 !iter.done ();
02161 iter.advance ())
02162 {
02163 if (thread_count >= n)
02164 break;
02165
02166 if (iter.next ()->grp_id_ == grp_id)
02167 {
02168 thread_list[thread_count] = iter.next ()->thr_id_;
02169 thread_count++;
02170 }
02171 }
02172
02173 return thread_count;
02174 }
|
|
||||||||||||||||
|
Returns in <thread_list> a list of up to <n> thread ids in an <ACE_Task_Base>. The caller must allocate the memory for <thread_list>. 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 2094 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_thread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, ACE_Double_Linked_List_Iterator_Base::next, and thread_list. Referenced by thread_all_list, thread_grp_list, and thread_list.
02097 {
02098 ACE_TRACE ("ACE_Thread_Manager::thread_list");
02099 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
02100
02101 size_t thread_count = 0;
02102
02103 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
02104 !iter.done ();
02105 iter.advance ())
02106 {
02107 if (thread_count >= n)
02108 break;
02109
02110 if (iter.next ()->task_ == task)
02111 {
02112 thread_list[thread_count] = iter.next ()->thr_id_;
02113 thread_count++;
02114 }
02115 }
02116
02117 return thread_count;
02118 }
|
|
|
Definition at line 1193 of file Thread_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_thread_t, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator_Base::done, ACE_Double_Linked_List_Iterator_Base::next, and ACE_OS::thr_equal.
01194 {
01195 ACE_TRACE ("ACE_Thread_Manager::thread_within");
01196 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_monx, this->lock_, -1));
01197
01198 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01199 !iter.done ();
01200 iter.advance ())
01201 if (ACE_OS::thr_equal (iter.next ()->thr_id_, tid))
01202 return 1;
01203
01204 return 0;
01205 }
|
|
||||||||||||
|
Block until there are no more threads running in the <Thread_Manager> or <timeout> expires. Note that <timeout> is treated as "absolute" time. Returns 0 on success and -1 on failure. If <abandon_detached_threads> is set, wait will first check thru its thread list for threads with THR_DETACHED or THR_DAEMON flags set and remove these threads. Notice that unlike other wait_* function, by default, <wait> does wait on all thread spawned by this thread_manager no matter the detached flags are set or not unless it is called with <abandon_detached_threads> flag set. NOTE that if this function is called while the 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 1690 of file Thread_Manager.cpp. References ACE_ASSERT, ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_MT, ACE_SET_BITS, ACE_THR_JOINING, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List< ACE_Thread_Descriptor_Base >::delete_head, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::dequeue_head, ACE_Double_Linked_List_Iterator_Base::done, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::enqueue_tail, ACE_OS_Thread_Descriptor::flags_, ACE_Unbounded_Queue< ACE_Thread_Descriptor * >::is_empty, ACE_Thread::join, ACE_Double_Linked_List_Iterator_Base::next, remove_thr, remove_thr_all, ACE_Object_Manager::shutting_down, ACE_Double_Linked_List< ACE_Thread_Descriptor >::size, 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.
01692 {
01693 ACE_TRACE ("ACE_Thread_Manager::wait");
01694
01695 #if defined (ACE_HAS_THREADS)
01696 {
01697 // Just hold onto the guard while waiting.
01698 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01699
01700 if (ACE_Object_Manager::shutting_down () != 1)
01701 {
01702 // Program is not shutting down. Perform a normal wait on threads.
01703 if (abandon_detached_threads != 0)
01704 {
01705 ACE_ASSERT (this->thr_to_be_removed_.is_empty ());
01706 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor>
01707 iter (this->thr_list_);
01708 !iter.done ();
01709 iter.advance ())
01710 if (ACE_BIT_ENABLED (iter.next ()->flags_,
01711 THR_DETACHED | THR_DAEMON)
01712 && ACE_BIT_DISABLED (iter.next ()->flags_, THR_JOINABLE))
01713 {
01714 this->thr_to_be_removed_.enqueue_tail (iter.next ());
01715 ACE_SET_BITS (iter.next ()->thr_state_, ACE_THR_JOINING);
01716 }
01717
01718 if (! this->thr_to_be_removed_.is_empty ())
01719 {
01720 ACE_Thread_Descriptor *td;
01721 while (this->thr_to_be_removed_.dequeue_head (td) != -1)
01722 this->remove_thr (td, 1);
01723 }
01724 }
01725
01726 while (this->thr_list_.size () > 0)
01727 if (this->zero_cond_.wait (timeout) == -1)
01728 return -1;
01729 }
01730 else
01731 // Program is shutting down, no chance to wait on threads.
01732 // Therefore, we'll just remove threads from the list.
01733 this->remove_thr_all ();
01734 // Release the guard, giving other threads a chance to run.
01735 }
01736
01737 #if !defined (VXWORKS)
01738 // @@ VxWorks doesn't support thr_join (yet.) We are working
01739 //on our implementation. Chorus'es thr_join seems broken.
01740 ACE_Thread_Descriptor_Base *item;
01741
01742 #if defined (CHORUS)
01743 if (ACE_Object_Manager::shutting_down () != 1)
01744 {
01745 #endif /* CHORUS */
01746 while ((item = this->terminated_thr_list_.delete_head ()) != 0)
01747 {
01748 if (ACE_BIT_DISABLED (item->flags_, THR_DETACHED | THR_DAEMON)
01749 || ACE_BIT_ENABLED (item->flags_, THR_JOINABLE))
01750 // Detached handles shouldn't reached here.
01751 ACE_Thread::join (item->thr_handle_);
01752
01753 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH)
01754 // Must explicitly detach threads. Threads without
01755 // THR_DETACHED were detached in ACE_OS::thr_create ().
01756 ::pthread_detach (&item->thr_handle_);
01757 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */
01758 delete item;
01759 }
01760 #if defined (CHORUS)
01761 }
01762 #endif /* CHORUS */
01763
01764 #endif /* ! VXWORKS */
01765 #else
01766 ACE_UNUSED_ARG (timeout);
01767 ACE_UNUSED_ARG (abandon_detached_threads);
01768 #endif /* ACE_HAS_THREADS */
01769
01770 return 0;
01771 }
|
|
|
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 1480 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_MT, ACE_NEW_RETURN, ACE_SET_BITS, ACE_THR_JOINING, ACE_TRACE, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator::advance_and_remove, ACE_Double_Linked_List_Iterator_Base::done, ACE_Thread::join, ACE_Double_Linked_List_Iterator_Base::next, ACE_Double_Linked_List< ACE_Thread_Descriptor_Base >::size, terminated_thr_list_, and ACE_Thread_Descriptor_Base::thr_handle_. Referenced by ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler.
01481 {
01482 ACE_TRACE ("ACE_Thread_Manager::wait_grp");
01483
01484 int copy_count = 0;
01485 ACE_Thread_Descriptor_Base *copy_table = 0;
01486
01487 // We have to make sure that while we wait for these threads to
01488 // exit, we do not have the lock. Therefore we make a copy of all
01489 // interesting entries and let go of the lock.
01490 {
01491 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01492
01493 #if !defined (VXWORKS)
01494 ACE_NEW_RETURN (copy_table,
01495 ACE_Thread_Descriptor_Base [this->thr_list_.size ()
01496 + this->terminated_thr_list_.size ()],
01497 -1);
01498 #else
01499 ACE_NEW_RETURN (copy_table,
01500 ACE_Thread_Descriptor_Base [this->thr_list_.size ()],
01501 -1);
01502 #endif /* VXWORKS */
01503
01504 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01505 !iter.done ();
01506 iter.advance ())
01507 // If threads are created as THR_DETACHED or THR_DAEMON, we
01508 // can't help much.
01509 if (iter.next ()->grp_id_ == grp_id &&
01510 (ACE_BIT_DISABLED (iter.next ()->flags_, THR_DETACHED | THR_DAEMON)
01511 || ACE_BIT_ENABLED (iter.next ()->flags_, THR_JOINABLE)))
01512 {
01513 ACE_SET_BITS (iter.next ()->thr_state_, ACE_THR_JOINING);
01514 copy_table[copy_count++] = *iter.next ();
01515 }
01516
01517 #if !defined (VXWORKS)
01518 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor_Base> biter (this->terminated_thr_list_);
01519 !biter.done ();
01520 biter.advance ())
01521 // If threads are created as THR_DETACHED or THR_DAEMON, we
01522 // can't help much.
01523 if (biter.next ()->grp_id_ == grp_id)
01524 {
01525 ACE_Thread_Descriptor_Base *tdb = biter.advance_and_remove (0);
01526 copy_table[copy_count++] = *tdb;
01527 delete tdb;
01528 }
01529 #endif /* !VXWORKS */
01530 }
01531
01532 // Now actually join() with all the threads in this group.
01533 int result = 0;
01534
01535 for (int i = 0;
01536 i < copy_count && result != -1;
01537 i++)
01538 {
01539 if (ACE_Thread::join (copy_table[i].thr_handle_) == -1)
01540 result = -1;
01541
01542 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH)
01543 // Must explicitly detach threads. Threads without THR_DETACHED
01544 // were detached in ACE_OS::thr_create ().
01545 ::pthread_detach (©_table[i].thr_handle_);
01546 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */
01547 }
01548
01549 delete [] copy_table;
01550
01551 return result;
01552 }
|
|
|
Definition at line 312 of file Thread_Manager.i. References automatic_wait_.
00313 {
00314 return this->automatic_wait_;
00315 }
|
|
|
Access function to determine whether the Thread_Manager will wait for its thread to exit or not when being closing down.
Definition at line 306 of file Thread_Manager.i. References automatic_wait_.
00307 {
00308 this->automatic_wait_ = do_wait;
00309 }
|
|
|
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 1811 of file Thread_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD_RETURN, ACE_MT, ACE_NEW_RETURN, ACE_SET_BITS, ACE_THR_JOINING, ACE_Double_Linked_List_Iterator::advance, ACE_Double_Linked_List_Iterator::advance_and_remove, ACE_Double_Linked_List_Iterator_Base::done, ACE_Thread::join, ACE_Double_Linked_List_Iterator_Base::next, ACE_Double_Linked_List< ACE_Thread_Descriptor_Base >::size, terminated_thr_list_, and ACE_Thread_Descriptor_Base::thr_handle_. Referenced by ACE_Task_Base::wait.
01812 {
01813 int copy_count = 0;
01814 ACE_Thread_Descriptor_Base *copy_table = 0;
01815
01816 // We have to make sure that while we wait for these threads to
01817 // exit, we do not have the lock. Therefore we make a copy of all
01818 // interesting entries and let go of the lock.
01819 {
01820 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
01821
01822 #if !defined (VXWORKS)
01823 ACE_NEW_RETURN (copy_table,
01824 ACE_Thread_Descriptor_Base [this->thr_list_.size ()
01825 + this->terminated_thr_list_.size ()],
01826 -1);
01827 #else
01828 ACE_NEW_RETURN (copy_table,
01829 ACE_Thread_Descriptor_Base [this->thr_list_.size ()],
01830 -1);
01831 #endif /* VXWORKS */
01832
01833 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor> iter (this->thr_list_);
01834 !iter.done ();
01835 iter.advance ())
01836 // If threads are created as THR_DETACHED or THR_DAEMON, we
01837 // can't wait on them here.
01838 if (iter.next ()->task_ == task &&
01839 (ACE_BIT_DISABLED (iter.next ()->flags_,
01840 THR_DETACHED | THR_DAEMON)
01841 || ACE_BIT_ENABLED (iter.next ()->flags_,
01842 THR_JOINABLE)))
01843 {
01844 ACE_SET_BITS (iter.next ()->thr_state_,
01845 ACE_THR_JOINING);
01846 copy_table[copy_count++] = *iter.next ();
01847 }
01848
01849 #if !defined (VXWORKS)
01850 for (ACE_Double_Linked_List_Iterator<ACE_Thread_Descriptor_Base> titer (this->terminated_thr_list_);
01851 !titer.done ();
01852 titer.advance ())
01853 // If threads are created as THR_DETACHED or THR_DAEMON, we can't help much here.
01854 if (titer.next ()->task_ == task)
01855 {
01856 ACE_Thread_Descriptor_Base *tdb =
01857 titer.advance_and_remove (0);
01858 copy_table[copy_count++] = *tdb;
01859 delete tdb;
01860 }
01861 #endif /* VXWORKS */
01862 }
01863
01864 // Now to do the actual work
01865 int result = 0;
01866
01867 for (int i = 0;
01868 i < copy_count && result != -1;
01869 i++)
01870 {
01871 if (ACE_Thread::join (copy_table[i].thr_handle_) == -1)
01872 result = -1;
01873
01874 # if defined (ACE_HAS_PTHREADS_DRAFT4) && defined (ACE_LACKS_SETDETACH)
01875 // Must explicitly detach threads. Threads without THR_DETACHED
01876 // were detached in ACE_OS::thr_create ().
01877 ::pthread_detach (©_table[i].thr_handle_);
01878 # endif /* ACE_HAS_PTHREADS_DRAFT4 && ACE_LACKS_SETDETACH */
01879 }
01880
01881 delete [] copy_table;
01882
01883 return result;
01884 }
|
|
|
Definition at line 390 of file Thread_Manager.h. |
|
|
Definition at line 395 of file Thread_Manager.h. |
|
|
Definition at line 393 of file Thread_Manager.h. |
|
|
Declare the dynamic allocation hooks.
Definition at line 916 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 1061 of file Thread_Manager.h. Referenced by close, and wait_on_exit. |
|
|
Must delete the <thr_mgr_> if non-0.
Definition at line 26 of file Thread_Manager.cpp. Referenced by close_singleton, and instance. |
|
|
Keeps track of the next group id to assign.
Definition at line 1057 of file Thread_Manager.h. Referenced by insert_thr, spawn, and spawn_n. |
|
|
Serialize access to the <zero_cond_>.
Definition at line 1066 of file Thread_Manager.h. Referenced by dump. |
|
|
Collect terminated but not yet joined thread entries.
Definition at line 1050 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 1046 of file Thread_Manager.h. Referenced by append_thr, count_threads, remove_thr, remove_thr_all, and wait. |
|
|
Pointer to a process-wide <ACE_Thread_Manager>.
Definition at line 22 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 1054 of file Thread_Manager.h. Referenced by apply_all, apply_grp, apply_task, kill_thr, resume_thr, suspend_thr, and wait. |
|
|
Definition at line 1073 of file Thread_Manager.h. Referenced by remove_thr. |
|
|
Keep track of when there are no more threads.
Definition at line 1069 of file Thread_Manager.h. Referenced by remove_thr, and wait. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002