#include <Thread.h>
Static Public Member Functions | |
static 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, const char **thr_name=0) |
static 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, const char *thr_name[]=0) |
static 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, const char *thr_name[]=0) |
static int | join (ACE_thread_t thread_id, ACE_thread_t *departed, ACE_THR_FUNC_RETURN *status) |
static int | join (ACE_hthread_t, ACE_THR_FUNC_RETURN *=0) |
Wait for one thread to exit and reap its exit status. | |
static int | resume (ACE_hthread_t) |
Continue the execution of a previously suspended thread. | |
static int | suspend (ACE_hthread_t) |
Suspend the execution of a particular thread. | |
static int | getprio (ACE_hthread_t ht_id, int &priority) |
Get the priority of a particular thread. | |
static int | getprio (ACE_hthread_t ht_id, int &priority, int &policy) |
Get the priority and policy of a particular thread. | |
static int | setprio (ACE_hthread_t ht_id, int priority, int policy=-1) |
Set the priority of a particular thread. | |
static int | kill (ACE_thread_t, int signum) |
Send a signal to the thread. | |
static void | yield (void) |
Yield the thread to another. | |
static void | self (ACE_hthread_t &t_handle) |
static ACE_thread_t | self (void) |
Return the unique ID of the thread. | |
static void | exit (ACE_THR_FUNC_RETURN status=0) |
static int | getconcurrency (void) |
Get the LWP concurrency level of the process. | |
static int | setconcurrency (int new_level) |
Set the LWP concurrency level of the process. | |
static int | sigsetmask (int how, const sigset_t *sigset, sigset_t *osigset=0) |
Change and/or examine calling thread's signal mask. | |
static int | keycreate (ACE_thread_key_t *keyp, ACE_THR_DEST destructor, void *=0) |
static int | keyfree (ACE_thread_key_t key) |
Free up the key so that other threads can reuse it. | |
static int | setspecific (ACE_thread_key_t key, void *value) |
static int | getspecific (ACE_thread_key_t key, void **valuep) |
static int | disablecancel (struct cancel_state *old_state) |
Disable thread cancellation. | |
static int | enablecancel (struct cancel_state *old_state, int flag) |
Enable thread cancellation. | |
static int | setcancelstate (struct cancel_state &new_state, struct cancel_state *old_state) |
Set the cancellation state. | |
static int | cancel (ACE_thread_t t_id) |
static 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 <ACE_Thread> API since the thread manager is more powerful.
Definition at line 51 of file Thread.h.
ACE_Thread::ACE_Thread | ( | void | ) | [private] |
Ensure that we don't get instantiated.
ACE_INLINE int ACE_Thread::cancel | ( | ACE_thread_t | t_id | ) | [static] |
Cancel a thread.
Definition at line 243 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_cancel().
Referenced by ACE_Thread_Manager::cancel_thr().
00244 { 00245 ACE_TRACE ("ACE_Thread::cancel"); 00246 00247 return ACE_OS::thr_cancel (t_id); 00248 }
ACE_INLINE int ACE_Thread::disablecancel | ( | struct cancel_state * | old_state | ) | [static] |
Disable thread cancellation.
Definition at line 164 of file Thread.inl.
References ACE_TRACE, ACE_OS::memset(), THR_CANCEL_DISABLE, and ACE_OS::thr_setcancelstate().
00165 { 00166 ACE_TRACE ("ACE_Thread::disablecancel"); 00167 int old_cstate = 0; 00168 int result = ACE_OS::thr_setcancelstate (THR_CANCEL_DISABLE, 00169 &old_cstate); 00170 if (result == 0 && old_state != 0) 00171 { 00172 ACE_OS::memset (old_state, 00173 0, 00174 sizeof (old_state)); 00175 old_state->cancelstate = old_cstate; 00176 } 00177 00178 return result; 00179 }
ACE_INLINE int ACE_Thread::enablecancel | ( | struct cancel_state * | old_state, | |
int | flag | |||
) | [static] |
Enable thread cancellation.
Definition at line 182 of file Thread.inl.
References ACE_TRACE, cancel_state::cancelstate, cancel_state::canceltype, THR_CANCEL_ENABLE, ACE_OS::thr_setcancelstate(), and ACE_OS::thr_setcanceltype().
00184 { 00185 ACE_TRACE ("ACE_Thread::enablecancel"); 00186 int old_cstate = 0; 00187 int old_ctype = 0; 00188 int result; 00189 00190 result = ACE_OS::thr_setcancelstate (THR_CANCEL_ENABLE, 00191 &old_cstate); 00192 if (result != 0) 00193 return result; 00194 00195 result = ACE_OS::thr_setcanceltype (flag, 00196 &old_ctype); 00197 if (result != 0) 00198 return result; 00199 00200 if (old_state != 0) 00201 { 00202 old_state->cancelstate = old_cstate; 00203 old_state->canceltype = old_ctype; 00204 } 00205 00206 return 0; 00207 }
ACE_INLINE void ACE_Thread::exit | ( | ACE_THR_FUNC_RETURN | status = 0 |
) | [static] |
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 }
ACE_INLINE int ACE_Thread::getconcurrency | ( | void | ) | [static] |
Get the LWP concurrency level of the process.
Definition at line 141 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_getconcurrency().
00142 { 00143 ACE_TRACE ("ACE_Thread::getconcurrency"); 00144 return ACE_OS::thr_getconcurrency (); 00145 }
ACE_INLINE int ACE_Thread::getprio | ( | ACE_hthread_t | ht_id, | |
int & | priority, | |||
int & | policy | |||
) | [static] |
Get the priority and policy of a particular thread.
Definition at line 273 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_getprio().
00274 { 00275 ACE_TRACE ("ACE_Thread::getprio"); 00276 return ACE_OS::thr_getprio (ht_id, priority, policy); 00277 }
ACE_INLINE int ACE_Thread::getprio | ( | ACE_hthread_t | ht_id, | |
int & | priority | |||
) | [static] |
Get the priority of a particular thread.
Definition at line 266 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_getprio().
00267 { 00268 ACE_TRACE ("ACE_Thread::getprio"); 00269 return ACE_OS::thr_getprio (ht_id, priority); 00270 }
ACE_INLINE int ACE_Thread::getspecific | ( | ACE_thread_key_t | key, | |
void ** | valuep | |||
) | [static] |
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_OS::thr_getspecific().
Referenced by ACE_Log_Msg::close(), ACE_Log_Msg::exists(), ACE_Threading_Helper< ACE_Thread_Mutex >::get(), and ACE_Log_Msg::instance().
00050 { 00051 // ACE_TRACE ("ACE_Thread::getspecific"); 00052 return ACE_OS::thr_getspecific (key, valuep); 00053 }
ACE_INLINE int ACE_Thread::join | ( | ACE_hthread_t | , | |
ACE_THR_FUNC_RETURN * | = 0 | |||
) | [static] |
Wait for one thread to exit and reap its exit status.
Definition at line 133 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_join().
00135 { 00136 ACE_TRACE ("ACE_Thread::join"); 00137 return ACE_OS::thr_join (wait_for, status); 00138 }
ACE_INLINE int ACE_Thread::join | ( | ACE_thread_t | thread_id, | |
ACE_thread_t * | departed, | |||
ACE_THR_FUNC_RETURN * | status | |||
) | [static] |
Wait for one or more threads to exit and reap their exit status. thr_join() returns successfully when the target thread terminates.
thread_id | is the ACE_thread_t ID of the thread to wait for. If thread_id is 0, join() waits for any undetached thread in the process to terminate on platforms that support this capability (for example, Solaris). | |
departed | points to a location that is set to the ID of the terminated thread if join() returns successfully. If departed is 0, it is ignored. | |
status | Points to the location that receives the joined thread's exit value. If status is 0, it is ignored. |
0 | for success | |
-1 | (with errno set) for failure. |
Definition at line 124 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().
00127 { 00128 ACE_TRACE ("ACE_Thread::join"); 00129 return ACE_OS::thr_join (wait_for, departed, status); 00130 }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_Thread::keycreate | ( | ACE_thread_key_t * | keyp, | |
ACE_THR_DEST | destructor, | |||
void * | = 0 | |||
) | [static] |
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_OS::thr_keycreate().
Referenced by ACE_Threading_Helper< ACE_Thread_Mutex >::ACE_Threading_Helper(), and ACE_Log_Msg::instance().
00021 { 00022 // ACE_TRACE ("ACE_Thread::keycreate"); 00023 return ACE_OS::thr_keycreate (keyp, destructor, inst); 00024 }
ACE_INLINE int ACE_Thread::keyfree | ( | ACE_thread_key_t | key | ) | [static] |
Free up the key so that other threads can reuse it.
Definition at line 29 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_keyfree().
00030 { 00031 ACE_TRACE ("ACE_Thread::keyfree"); 00032 return ACE_OS::thr_keyfree (key); 00033 }
ACE_INLINE int ACE_Thread::kill | ( | ACE_thread_t | , | |
int | signum | |||
) | [static] |
Send a signal to the thread.
Definition at line 117 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_kill().
Referenced by ACE_Thread_Manager::kill_thr().
00118 { 00119 ACE_TRACE ("ACE_Thread::kill"); 00120 return ACE_OS::thr_kill (t_id, signum); 00121 }
ACE_INLINE int ACE_Thread::resume | ( | ACE_hthread_t | ) | [static] |
Continue the execution of a previously suspended thread.
Definition at line 103 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_continue().
Referenced by ACE_Thread_Manager::resume_thr().
00104 { 00105 ACE_TRACE ("ACE_Thread::resume"); 00106 return ACE_OS::thr_continue (t_id); 00107 }
ACE_INLINE ACE_thread_t ACE_Thread::self | ( | void | ) | [static] |
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_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::handle_events(), ACE_Log_Msg::log(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::open(), ACE_TP_Reactor::owner(), ACE_Thread_Timer_Queue_Adapter< TQ >::svc(), ACE_Asynch_Pseudo_Task::svc(), and ACE_Thread_Manager::thr_self().
00057 { 00058 // ACE_TRACE ("ACE_Thread::self"); 00059 return ACE_OS::thr_self (); 00060 }
ACE_INLINE void ACE_Thread::self | ( | ACE_hthread_t & | t_handle | ) | [static] |
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 259 of file Thread.inl.
References ACE_OS::thr_self().
00260 { 00261 // ACE_TRACE ("ACE_Thread::self"); 00262 ACE_OS::thr_self (t_id); 00263 }
ACE_INLINE int ACE_Thread::setcancelstate | ( | struct cancel_state & | new_state, | |
struct cancel_state * | old_state | |||
) | [static] |
Set the cancellation state.
Definition at line 210 of file Thread.inl.
References ACE_TRACE, cancel_state::cancelstate, cancel_state::canceltype, ACE_OS::thr_setcancelstate(), and ACE_OS::thr_setcanceltype().
00212 { 00213 ACE_TRACE ("ACE_Thread::setcancelstate"); 00214 int old_cstate = 0; 00215 int old_ctype = 0; 00216 00217 if (new_state.cancelstate != 0 00218 && ACE_OS::thr_setcancelstate (new_state.cancelstate, 00219 &old_cstate) != 0) 00220 return -1; 00221 00222 if (new_state.canceltype != 0 00223 && ACE_OS::thr_setcanceltype (new_state.canceltype, 00224 &old_ctype) != 0) 00225 { 00226 int o_cstate; 00227 00228 ACE_OS::thr_setcancelstate (old_cstate, 00229 &o_cstate); 00230 return -1; 00231 } 00232 00233 if (old_state != 0) 00234 { 00235 old_state->cancelstate = old_cstate; 00236 old_state->canceltype = old_ctype; 00237 } 00238 00239 return 0; 00240 }
ACE_INLINE int ACE_Thread::setconcurrency | ( | int | new_level | ) | [static] |
Set the LWP concurrency level of the process.
Definition at line 148 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_setconcurrency().
00149 { 00150 ACE_TRACE ("ACE_Thread::setconcurrency"); 00151 return ACE_OS::thr_setconcurrency (new_level); 00152 }
ACE_INLINE int ACE_Thread::setprio | ( | ACE_hthread_t | ht_id, | |
int | priority, | |||
int | policy = -1 | |||
) | [static] |
Set the priority of a particular thread.
Definition at line 280 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_setprio().
00281 { 00282 ACE_TRACE ("ACE_Thread::setprio"); 00283 return ACE_OS::thr_setprio (ht_id, priority, policy); 00284 }
ACE_INLINE int ACE_Thread::setspecific | ( | ACE_thread_key_t | key, | |
void * | value | |||
) | [static] |
Bind value to the thread-specific data key, key, for the calling thread.
Definition at line 39 of file Thread.inl.
References ACE_OS::thr_setspecific().
Referenced by ACE_Log_Msg::close(), ACE_Log_Msg::instance(), and ACE_Threading_Helper< ACE_Thread_Mutex >::set().
00040 { 00041 // ACE_TRACE ("ACE_Thread::setspecific"); 00042 return ACE_OS::thr_setspecific (key, value); 00043 }
ACE_INLINE int ACE_Thread::sigsetmask | ( | int | how, | |
const sigset_t * | sigset, | |||
sigset_t * | osigset = 0 | |||
) | [static] |
Change and/or examine calling thread's signal mask.
Definition at line 155 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_sigsetmask().
00158 { 00159 ACE_TRACE ("ACE_Thread::sigsetmask"); 00160 return ACE_OS::thr_sigsetmask (how, sigset, osigset); 00161 }
ACE_INLINE int ACE_Thread::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 , |
|||
const char ** | thr_name = 0 | |||
) | [static] |
Creates a new thread having flags attributes and running func with <args> (if <thread_adapter> is non-0 then func and <args> are ignored and are obtained from <thread_adapter>). <thr_id> and <t_handle> are set to the thread's ID and handle (?), respectively. The thread runs at priority priority (see below).
The flags 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 priority is set to ACE_DEFAULT_THREAD_PRIORITY, an "appropriate" priority value for the given scheduling policy (specified in <flags}>, e.g., <THR_SCHED_DEFAULT>) 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 <thread_adapter> is always deleted when <spawn> is called, so it must be allocated with global operator new.
Definition at line 77 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_create().
Referenced by ACE_Thread_Manager::spawn_i().
00087 { 00088 ACE_TRACE ("ACE_Thread::spawn"); 00089 00090 return ACE_OS::thr_create (func, 00091 arg, 00092 flags, 00093 t_id, 00094 t_handle, 00095 priority, 00096 thr_stack, 00097 thr_stack_size, 00098 thread_adapter, 00099 thr_name); 00100 }
static size_t ACE_Thread::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 , |
|||
const char * | thr_name[] = 0 | |||
) | [static] |
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). 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 stacks 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. Returns the number of threads actually spawned (if this doesn't equal the number requested then something has gone wrong and errno
will explain...).
static size_t ACE_Thread::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 , |
|||
const char * | thr_name[] = 0 | |||
) | [static] |
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 stacks are. Returns the number of threads actually spawned (if this doesn't equal the number requested then something has gone wrong and errno
will explain...).
ACE_INLINE int ACE_Thread::suspend | ( | ACE_hthread_t | ) | [static] |
Suspend the execution of a particular thread.
Definition at line 110 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_suspend().
Referenced by ACE_Thread_Manager::suspend_thr().
00111 { 00112 ACE_TRACE ("ACE_Thread::suspend"); 00113 return ACE_OS::thr_suspend (t_id); 00114 }
ACE_INLINE void ACE_Thread::testcancel | ( | void | ) | [static] |
Test the cancel.
Definition at line 251 of file Thread.inl.
References ACE_TRACE, and ACE_OS::thr_testcancel().
00252 { 00253 ACE_TRACE ("ACE_Thread::testcancel"); 00254 00255 ACE_OS::thr_testcancel (); 00256 }
ACE_INLINE void ACE_Thread::yield | ( | void | ) | [static] |
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 }