#include <Thread.h>
Static Public Member Functions | |
int | spawn (ACE_THR_FUNC func, void *arg=0, long flags=THR_NEW_LWP|THR_JOINABLE, ACE_thread_t *t_id=0, ACE_hthread_t *t_handle=0, long priority=ACE_DEFAULT_THREAD_PRIORITY, void *stack=0, size_t stack_size=ACE_DEFAULT_THREAD_STACKSIZE, ACE_Thread_Adapter *thread_adapter=0) |
size_t | spawn_n (size_t n, ACE_THR_FUNC func, void *arg=0, long flags=THR_NEW_LWP|THR_JOINABLE, long priority=ACE_DEFAULT_THREAD_PRIORITY, void *stack[]=0, size_t stack_size[]=0, ACE_Thread_Adapter *thread_adapter=0) |
size_t | spawn_n (ACE_thread_t thread_ids[], size_t n, ACE_THR_FUNC func, void *arg, long flags, long priority=ACE_DEFAULT_THREAD_PRIORITY, void *stack[]=0, size_t stack_size[]=0, ACE_hthread_t thread_handles[]=0, ACE_Thread_Adapter *thread_adapter=0) |
int | join (ACE_thread_t thread_id, ACE_thread_t *departed, ACE_THR_FUNC_RETURN *status) |
int | join (ACE_hthread_t, ACE_THR_FUNC_RETURN *=0) |
Wait for one thread to exit and reap its exit status. | |
int | resume (ACE_hthread_t) |
Continue the execution of a previously suspended thread. | |
int | suspend (ACE_hthread_t) |
Suspend the execution of a particular thread. | |
int | getprio (ACE_hthread_t ht_id, int &priority) |
Get the priority of a particular thread. | |
int | getprio (ACE_hthread_t ht_id, int &priority, int &policy) |
Get the priority and policy of a particular thread. | |
int | setprio (ACE_hthread_t ht_id, int priority, int policy=-1) |
Set the priority of a particular thread. | |
int | kill (ACE_thread_t, int signum) |
Send a signal to the thread. | |
void | yield (void) |
Yield the thread to another. | |
void | self (ACE_hthread_t &t_handle) |
ACE_thread_t | self (void) |
Return the unique ID of the thread. | |
void | exit (ACE_THR_FUNC_RETURN status=0) |
int | getconcurrency (void) |
Get the LWP concurrency level of the process. | |
int | setconcurrency (int new_level) |
Set the LWP concurrency level of the process. | |
int | sigsetmask (int how, const sigset_t *sigset, sigset_t *osigset=0) |
Change and/or examine calling thread's signal mask. | |
int | keycreate (ACE_thread_key_t *keyp, ACE_THR_DEST destructor, void *=0) |
int | keyfree (ACE_thread_key_t key) |
Free up the key so that other threads can reuse it. | |
int | setspecific (ACE_thread_key_t key, void *value) |
int | getspecific (ACE_thread_key_t key, void **valuep) |
int | disablecancel (struct cancel_state *old_state) |
Disable thread cancellation. | |
int | enablecancel (struct cancel_state *old_state, int flag) |
Enable thread cancellation. | |
int | setcancelstate (struct cancel_state &new_state, struct cancel_state *old_state) |
Set the cancellation state. | |
int | cancel (ACE_thread_t t_id) |
void | testcancel (void) |
Test the cancel. | |
Private Member Functions | |
ACE_Thread (void) | |
Ensure that we don't get instantiated. |
This class provides a common interface that is mapped onto POSIX Pthreads, Solaris threads, Win32 threads, VxWorks threads, or pSoS threads. Note, however, that it is generally a better idea to use the ACE_Thread_Manager programming API rather than the API since the thread manager is more powerful.
Definition at line 51 of file Thread.h.
|
Ensure that we don't get instantiated.
|
|
Cancel a thread.
Definition at line 241 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_cancel(). Referenced by ACE_Thread_Manager::cancel_thr().
00242 { 00243 ACE_TRACE ("ACE_Thread::cancel"); 00244 00245 return ACE_OS::thr_cancel (t_id); 00246 } |
|
Disable thread cancellation.
Definition at line 162 of file Thread.inl. References ACE_TRACE, ACE_OS::memset(), and ACE_OS::thr_setcancelstate().
00163 { 00164 ACE_TRACE ("ACE_Thread::disablecancel"); 00165 int old_cstate = 0; 00166 int result = ACE_OS::thr_setcancelstate (THR_CANCEL_DISABLE, 00167 &old_cstate); 00168 if (result == 0 && old_state != 0) 00169 { 00170 ACE_OS::memset (old_state, 00171 0, 00172 sizeof (old_state)); 00173 old_state->cancelstate = old_cstate; 00174 } 00175 00176 return result; 00177 } |
|
Enable thread cancellation.
Definition at line 180 of file Thread.inl. References ACE_TRACE, cancel_state::cancelstate, cancel_state::canceltype, ACE_OS::thr_setcancelstate(), and ACE_OS::thr_setcanceltype().
00182 { 00183 ACE_TRACE ("ACE_Thread::enablecancel"); 00184 int old_cstate = 0; 00185 int old_ctype = 0; 00186 int result; 00187 00188 result = ACE_OS::thr_setcancelstate (THR_CANCEL_ENABLE, 00189 &old_cstate); 00190 if (result != 0) 00191 return result; 00192 00193 result = ACE_OS::thr_setcanceltype (flag, 00194 &old_ctype); 00195 if (result != 0) 00196 return result; 00197 00198 if (old_state != 0) 00199 { 00200 old_state->cancelstate = old_cstate; 00201 old_state->canceltype = old_ctype; 00202 } 00203 00204 return 0; 00205 } |
|
Exit the current thread and return "status". Should _not_ be called by main thread. Definition at line 63 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_exit(). Referenced by ACE_Thread_Manager::exit().
00064 { 00065 ACE_TRACE ("ACE_Thread::exit"); 00066 ACE_OS::thr_exit (status); 00067 } |
|
Get the LWP concurrency level of the process.
Definition at line 139 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_getconcurrency().
00140 { 00141 ACE_TRACE ("ACE_Thread::getconcurrency"); 00142 return ACE_OS::thr_getconcurrency (); 00143 } |
|
Get the priority and policy of a particular thread.
Definition at line 271 of file Thread.inl. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_getprio().
00272 { 00273 ACE_TRACE ("ACE_Thread::getprio"); 00274 return ACE_OS::thr_getprio (ht_id, priority, policy); 00275 } |
|
Get the priority of a particular thread.
Definition at line 264 of file Thread.inl. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_getprio().
00265 { 00266 ACE_TRACE ("ACE_Thread::getprio"); 00267 return ACE_OS::thr_getprio (ht_id, priority); 00268 } |
|
Stores the current value bound to key for the calling thread into the location pointed to by valuep. Definition at line 49 of file Thread.inl. References ACE_thread_key_t, and ACE_OS::thr_getspecific(). Referenced by ACE_Log_Msg::close(), ACE_Log_Msg::exists(), and ACE_Log_Msg::instance().
00050 { 00051 // ACE_TRACE ("ACE_Thread::getspecific"); 00052 return ACE_OS::thr_getspecific (key, valuep); 00053 } |
|
Wait for one thread to exit and reap its exit status.
Definition at line 131 of file Thread.inl. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_join().
00133 { 00134 ACE_TRACE ("ACE_Thread::join"); 00135 return ACE_OS::thr_join (wait_for, status); 00136 } |
|
Wait for one or more threads to exit and reap their exit status. thr_join() returns successfully when the target thread terminates.
Definition at line 122 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_join(). Referenced by ACE_Thread_Manager::join(), ACE_Thread_Manager::join_thr(), ACE_Thread_Manager::wait(), ACE_Thread_Manager::wait_grp(), and ACE_Thread_Manager::wait_task().
00125 { 00126 ACE_TRACE ("ACE_Thread::join"); 00127 return ACE_OS::thr_join (wait_for, departed, status); 00128 } |
|
Allocates a keyp that is used to identify data that is specific to each thread in the process. The key is global to all threads in the process. Definition at line 14 of file Thread.inl. References ACE_thread_key_t, and ACE_OS::thr_keycreate(). Referenced by ACE_Log_Msg::instance().
00021 { 00022 // ACE_TRACE ("ACE_Thread::keycreate"); 00023 return ACE_OS::thr_keycreate (keyp, destructor, inst); 00024 } |
|
Free up the key so that other threads can reuse it.
Definition at line 29 of file Thread.inl. References ACE_thread_key_t, ACE_TRACE, and ACE_OS::thr_keyfree().
00030 { 00031 ACE_TRACE ("ACE_Thread::keyfree"); 00032 return ACE_OS::thr_keyfree (key); 00033 } |
|
Send a signal to the thread.
Definition at line 115 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_kill(). Referenced by ACE_Thread_Manager::kill_thr().
00116 { 00117 ACE_TRACE ("ACE_Thread::kill"); 00118 return ACE_OS::thr_kill (t_id, signum); 00119 } |
|
Continue the execution of a previously suspended thread.
Definition at line 101 of file Thread.inl. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_continue(). Referenced by ACE_Thread_Manager::resume_thr().
00102 { 00103 ACE_TRACE ("ACE_Thread::resume"); 00104 return ACE_OS::thr_continue (t_id); 00105 } |
|
Return the unique ID of the thread.
Definition at line 56 of file Thread.inl. References ACE_OS::thr_self(). Referenced by ACE_Task_Base::cleanup(), ACE_Log_Msg::log(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::open(), ACE_TP_Reactor::owner(), ACE_Token::renew(), ACE_Token::shared_acquire(), ACE_Thread_Timer_Queue_Adapter< TQ >::svc(), and ACE_Thread_Manager::thr_self().
00057 { 00058 // ACE_TRACE ("ACE_Thread::self"); 00059 return ACE_OS::thr_self (); 00060 } |
|
Return the unique kernel handle of the thread. Note that on Win32 this is actually a pseudohandle, which cannot be shared with other processes or waited on by threads. To locate the real handle, please use the ACE_Thread_Manager::thr_self() method. Definition at line 257 of file Thread.inl. References ACE_hthread_t, and ACE_OS::thr_self().
00258 { 00259 // ACE_TRACE ("ACE_Thread::self"); 00260 ACE_OS::thr_self (t_id); 00261 } |
|
Set the cancellation state.
Definition at line 208 of file Thread.inl. References ACE_TRACE, cancel_state::cancelstate, cancel_state::canceltype, ACE_OS::thr_setcancelstate(), and ACE_OS::thr_setcanceltype().
00210 { 00211 ACE_TRACE ("ACE_Thread::setcancelstate"); 00212 int old_cstate = 0; 00213 int old_ctype = 0; 00214 00215 if (new_state.cancelstate != 0 00216 && ACE_OS::thr_setcancelstate (new_state.cancelstate, 00217 &old_cstate) != 0) 00218 return -1; 00219 00220 if (new_state.canceltype != 0 00221 && ACE_OS::thr_setcanceltype (new_state.canceltype, 00222 &old_ctype) != 0) 00223 { 00224 int o_cstate; 00225 00226 ACE_OS::thr_setcancelstate (old_cstate, 00227 &o_cstate); 00228 return -1; 00229 } 00230 00231 if (old_state != 0) 00232 { 00233 old_state->cancelstate = old_cstate; 00234 old_state->canceltype = old_ctype; 00235 } 00236 00237 return 0; 00238 } |
|
Set the LWP concurrency level of the process.
Definition at line 146 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_setconcurrency().
00147 { 00148 ACE_TRACE ("ACE_Thread::setconcurrency"); 00149 return ACE_OS::thr_setconcurrency (new_level); 00150 } |
|
Set the priority of a particular thread.
Definition at line 278 of file Thread.inl. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_setprio().
00279 { 00280 ACE_TRACE ("ACE_Thread::setprio"); 00281 return ACE_OS::thr_setprio (ht_id, priority, policy); 00282 } |
|
Bind value to the thread-specific data key, key, for the calling thread. Definition at line 39 of file Thread.inl. References ACE_thread_key_t, and ACE_OS::thr_setspecific(). Referenced by ACE_Log_Msg::close(), and ACE_Log_Msg::instance().
00040 { 00041 // ACE_TRACE ("ACE_Thread::setspecific"); 00042 return ACE_OS::thr_setspecific (key, value); 00043 } |
|
Change and/or examine calling thread's signal mask.
Definition at line 153 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_sigsetmask().
00156 { 00157 ACE_TRACE ("ACE_Thread::sigsetmask"); 00158 return ACE_OS::thr_sigsetmask (how, sigset, osigset); 00159 } |
|
Creates a new thread having attributes and running with (if is non-0 then and are ignored and are obtained from ). and are set to the thread's ID and handle (?), respectively. The thread runs at priority (see below). The are a bitwise-OR of the following: = BEGIN<INDENT> THR_CANCEL_DISABLE, THR_CANCEL_ENABLE, THR_CANCEL_DEFERRED, THR_CANCEL_ASYNCHRONOUS, THR_BOUND, THR_NEW_LWP, THR_DETACHED, THR_SUSPENDED, THR_DAEMON, THR_JOINABLE, THR_SCHED_FIFO, THR_SCHED_RR, THR_SCHED_DEFAULT, THR_EXPLICIT_SCHED, THR_SCOPE_SYSTEM, THR_SCOPE_PROCESS = END<INDENT> By default, or if is set to ACE_DEFAULT_THREAD_PRIORITY, an "appropriate" priority value for the given scheduling policy (specified in <flags}>, e.g., ) is used. This value is calculated dynamically, and is the median value between the minimum and maximum priority values for the given policy. If an explicit value is given, it is used. Note that actual priority values are EXTREMEMLY implementation-dependent, and are probably best avoided. Note that is always deleted when is called, so it must be allocated with global operator new. Definition at line 77 of file Thread.inl. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_create(). Referenced by ACE_Thread_Manager::spawn_i().
00086 { 00087 ACE_TRACE ("ACE_Thread::spawn"); 00088 00089 return ACE_OS::thr_create (func, 00090 arg, 00091 flags, 00092 t_id, 00093 t_handle, 00094 priority, 00095 thr_stack, 00096 thr_stack_size, 00097 thread_adapter); 00098 } |
|
Spawn n new threads, which execute with argument (if is non-0 then and are ignored and are obtained from ). The thread_ids of successfully spawned threads will be placed into the buffer (which must be the same size as n). If != 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 != 0 it is assumed to be an array of n values indicating how big each of the corresponding s are. If != 0 it is assumed to be an array of n thread_handles that will be assigned the values of the thread handles being spawned. Returns the number of threads actually spawned (if this doesn't equal the number requested then something has gone wrong and
Definition at line 48 of file Thread.cpp. References ACE_DEFAULT_THREAD_STACKSIZE, ACE_hthread_t, ACE_thread_t, ACE_TRACE, and ACE_OS::thr_create().
00058 { 00059 ACE_TRACE ("ACE_Thread::spawn_n"); 00060 size_t i; 00061 00062 for (i = 0; i < n; i++) 00063 { 00064 ACE_thread_t t_id; 00065 ACE_hthread_t t_handle; 00066 00067 int result = 00068 ACE_OS::thr_create (func, 00069 arg, 00070 flags, 00071 &t_id, 00072 &t_handle, 00073 priority, 00074 stack == 0 ? 0 : stack[i], 00075 stack_size == 0 ? ACE_DEFAULT_THREAD_STACKSIZE : stack_size[i], 00076 thread_adapter); 00077 00078 if (result == 0) 00079 { 00080 if (thread_ids != 0) 00081 thread_ids[i] = t_id; 00082 if (thread_handles != 0) 00083 thread_handles[i] = t_handle; 00084 } 00085 else 00086 // Bail out if error occurs. 00087 break; 00088 } 00089 00090 return i; 00091 } |
|
Spawn N new threads, which execute func with argument arg (if thread_adapter is non-0 then func and args are ignored and are obtained from thread_adapter). 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. Likewise, if stack_size != 0 it is assumed to be an array of n values indicating how big each of the corresponding s are. Returns the number of threads actually spawned (if this doesn't equal the number requested then something has gone wrong and
Definition at line 18 of file Thread.cpp. References ACE_DEFAULT_THREAD_STACKSIZE, ACE_thread_t, ACE_TRACE, and ACE_OS::thr_create().
00026 { 00027 ACE_TRACE ("ACE_Thread::spawn_n"); 00028 ACE_thread_t t_id; 00029 size_t i; 00030 00031 for (i = 0; i < n; i++) 00032 // Bail out if error occurs. 00033 if (ACE_OS::thr_create (func, 00034 arg, 00035 flags, 00036 &t_id, 00037 0, 00038 priority, 00039 stack == 0 ? 0 : stack[i], 00040 stack_size == 0 ? ACE_DEFAULT_THREAD_STACKSIZE : stack_size[i], 00041 thread_adapter) != 0) 00042 break; 00043 00044 return i; 00045 } |
|
Suspend the execution of a particular thread.
Definition at line 108 of file Thread.inl. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_suspend(). Referenced by ACE_Thread_Manager::suspend_thr().
00109 { 00110 ACE_TRACE ("ACE_Thread::suspend"); 00111 return ACE_OS::thr_suspend (t_id); 00112 } |
|
Test the cancel.
Definition at line 249 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_testcancel().
00250 { 00251 ACE_TRACE ("ACE_Thread::testcancel"); 00252 00253 ACE_OS::thr_testcancel (); 00254 } |
|
Yield the thread to another.
Definition at line 70 of file Thread.inl. References ACE_TRACE, and ACE_OS::thr_yield().
00071 { 00072 ACE_TRACE ("ACE_Thread::yield"); 00073 ACE_OS::thr_yield (); 00074 } |