Provides a wrapper for threads. More...
#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,#if defined(ACE_HAS_THR_C_DEST) ACE_THR_C_DEST destructor#else ACE_THR_DEST destructor#endif) |
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. |
Provides a wrapper for threads.
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 49 of file Thread.h.
ACE_Thread::ACE_Thread | ( | void | ) | [private] |
Ensure that we don't get instantiated.
int ACE_Thread::cancel | ( | ACE_thread_t | t_id | ) | [static] |
Cancel a thread.
Definition at line 240 of file Thread.inl.
00241 { 00242 ACE_TRACE ("ACE_Thread::cancel"); 00243 00244 return ACE_OS::thr_cancel (t_id); 00245 }
int ACE_Thread::disablecancel | ( | struct cancel_state * | old_state | ) | [static] |
Disable thread cancellation.
Definition at line 161 of file Thread.inl.
00162 { 00163 ACE_TRACE ("ACE_Thread::disablecancel"); 00164 int old_cstate = 0; 00165 int result = ACE_OS::thr_setcancelstate (THR_CANCEL_DISABLE, 00166 &old_cstate); 00167 if (result == 0 && old_state != 0) 00168 { 00169 ACE_OS::memset (old_state, 00170 0, 00171 sizeof (*old_state)); 00172 old_state->cancelstate = old_cstate; 00173 } 00174 00175 return result; 00176 }
int ACE_Thread::enablecancel | ( | struct cancel_state * | old_state, | |
int | flag | |||
) | [static] |
Enable thread cancellation.
Definition at line 179 of file Thread.inl.
00181 { 00182 ACE_TRACE ("ACE_Thread::enablecancel"); 00183 int old_cstate = 0; 00184 int old_ctype = 0; 00185 int result; 00186 00187 result = ACE_OS::thr_setcancelstate (THR_CANCEL_ENABLE, 00188 &old_cstate); 00189 if (result != 0) 00190 return result; 00191 00192 result = ACE_OS::thr_setcanceltype (flag, 00193 &old_ctype); 00194 if (result != 0) 00195 return result; 00196 00197 if (old_state != 0) 00198 { 00199 old_state->cancelstate = old_cstate; 00200 old_state->canceltype = old_ctype; 00201 } 00202 00203 return 0; 00204 }
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 60 of file Thread.inl.
00061 { 00062 ACE_TRACE ("ACE_Thread::exit"); 00063 ACE_OS::thr_exit (status); 00064 }
int ACE_Thread::getconcurrency | ( | void | ) | [static] |
Get the LWP concurrency level of the process.
Definition at line 138 of file Thread.inl.
00139 { 00140 ACE_TRACE ("ACE_Thread::getconcurrency"); 00141 return ACE_OS::thr_getconcurrency (); 00142 }
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 270 of file Thread.inl.
00271 { 00272 ACE_TRACE ("ACE_Thread::getprio"); 00273 return ACE_OS::thr_getprio (ht_id, priority, policy); 00274 }
int ACE_Thread::getprio | ( | ACE_hthread_t | ht_id, | |
int & | priority | |||
) | [static] |
Get the priority of a particular thread.
Definition at line 263 of file Thread.inl.
00264 { 00265 ACE_TRACE ("ACE_Thread::getprio"); 00266 return ACE_OS::thr_getprio (ht_id, priority); 00267 }
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 46 of file Thread.inl.
00047 { 00048 // ACE_TRACE ("ACE_Thread::getspecific"); 00049 return ACE_OS::thr_getspecific (key, valuep); 00050 }
int ACE_Thread::join | ( | ACE_hthread_t | wait_for, | |
ACE_THR_FUNC_RETURN * | status = 0 | |||
) | [static] |
Wait for one thread to exit and reap its exit status.
Definition at line 130 of file Thread.inl.
00132 { 00133 ACE_TRACE ("ACE_Thread::join"); 00134 return ACE_OS::thr_join (wait_for, status); 00135 }
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 121 of file Thread.inl.
00124 { 00125 ACE_TRACE ("ACE_Thread::join"); 00126 return ACE_OS::thr_join (wait_for, departed, status); 00127 }
static int ACE_Thread::keycreate | ( | ACE_thread_key_t * | keyp, | |
#if defined(ACE_HAS_THR_C_DEST) ACE_THR_C_DEST destructor#else ACE_THR_DEST destructor# | endif | |||
) | [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.
int ACE_Thread::keyfree | ( | ACE_thread_key_t | key | ) | [static] |
Free up the key so that other threads can reuse it.
Definition at line 26 of file Thread.inl.
00027 { 00028 ACE_TRACE ("ACE_Thread::keyfree"); 00029 return ACE_OS::thr_keyfree (key); 00030 }
int ACE_Thread::kill | ( | ACE_thread_t | t_id, | |
int | signum | |||
) | [static] |
Send a signal to the thread.
Definition at line 114 of file Thread.inl.
00115 { 00116 ACE_TRACE ("ACE_Thread::kill"); 00117 return ACE_OS::thr_kill (t_id, signum); 00118 }
int ACE_Thread::resume | ( | ACE_hthread_t | t_id | ) | [static] |
Continue the execution of a previously suspended thread.
Definition at line 100 of file Thread.inl.
00101 { 00102 ACE_TRACE ("ACE_Thread::resume"); 00103 return ACE_OS::thr_continue (t_id); 00104 }
ACE_thread_t ACE_Thread::self | ( | void | ) | [static] |
Return the unique ID of the thread.
Definition at line 53 of file Thread.inl.
00054 { 00055 // ACE_TRACE ("ACE_Thread::self"); 00056 return ACE_OS::thr_self (); 00057 }
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 256 of file Thread.inl.
00257 { 00258 // ACE_TRACE ("ACE_Thread::self"); 00259 ACE_OS::thr_self (t_id); 00260 }
int ACE_Thread::setcancelstate | ( | struct cancel_state & | new_state, | |
struct cancel_state * | old_state | |||
) | [static] |
Set the cancellation state.
Definition at line 207 of file Thread.inl.
00209 { 00210 ACE_TRACE ("ACE_Thread::setcancelstate"); 00211 int old_cstate = 0; 00212 int old_ctype = 0; 00213 00214 if (new_state.cancelstate != 0 00215 && ACE_OS::thr_setcancelstate (new_state.cancelstate, 00216 &old_cstate) != 0) 00217 return -1; 00218 00219 if (new_state.canceltype != 0 00220 && ACE_OS::thr_setcanceltype (new_state.canceltype, 00221 &old_ctype) != 0) 00222 { 00223 int o_cstate; 00224 00225 ACE_OS::thr_setcancelstate (old_cstate, 00226 &o_cstate); 00227 return -1; 00228 } 00229 00230 if (old_state != 0) 00231 { 00232 old_state->cancelstate = old_cstate; 00233 old_state->canceltype = old_ctype; 00234 } 00235 00236 return 0; 00237 }
int ACE_Thread::setconcurrency | ( | int | new_level | ) | [static] |
Set the LWP concurrency level of the process.
Definition at line 145 of file Thread.inl.
00146 { 00147 ACE_TRACE ("ACE_Thread::setconcurrency"); 00148 return ACE_OS::thr_setconcurrency (new_level); 00149 }
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 277 of file Thread.inl.
00278 { 00279 ACE_TRACE ("ACE_Thread::setprio"); 00280 return ACE_OS::thr_setprio (ht_id, priority, policy); 00281 }
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 36 of file Thread.inl.
00037 { 00038 // ACE_TRACE ("ACE_Thread::setspecific"); 00039 return ACE_OS::thr_setspecific (key, value); 00040 }
Change and/or examine calling thread's signal mask.
Definition at line 152 of file Thread.inl.
00155 { 00156 ACE_TRACE ("ACE_Thread::sigsetmask"); 00157 return ACE_OS::thr_sigsetmask (how, sigset, osigset); 00158 }
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 EXTREMELY 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 74 of file Thread.inl.
00084 { 00085 ACE_TRACE ("ACE_Thread::spawn"); 00086 00087 return ACE_OS::thr_create (func, 00088 arg, 00089 flags, 00090 t_id, 00091 t_handle, 00092 priority, 00093 thr_stack, 00094 thr_stack_size, 00095 thread_adapter, 00096 thr_name); 00097 }
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...).
Definition at line 46 of file Thread.cpp.
00057 { 00058 ACE_TRACE ("ACE_Thread::spawn_n"); 00059 size_t i = 0; 00060 00061 for (i = 0; i < n; i++) 00062 { 00063 ACE_thread_t t_id; 00064 ACE_hthread_t t_handle; 00065 00066 int const result = 00067 ACE_OS::thr_create (func, 00068 arg, 00069 flags, 00070 &t_id, 00071 &t_handle, 00072 priority, 00073 stack == 0 ? 0 : stack[i], 00074 stack_size == 0 ? ACE_DEFAULT_THREAD_STACKSIZE : stack_size[i], 00075 thread_adapter, 00076 thr_name == 0 ? 0 : &thr_name[i]); 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 }
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...).
Definition at line 12 of file Thread.cpp.
00021 { 00022 ACE_TRACE ("ACE_Thread::spawn_n"); 00023 size_t i; 00024 00025 for (i = 0; i < n; i++) 00026 { 00027 ACE_thread_t t_id; 00028 // Bail out if error occurs. 00029 if (ACE_OS::thr_create (func, 00030 arg, 00031 flags, 00032 &t_id, 00033 0, 00034 priority, 00035 stack == 0 ? 0 : stack[i], 00036 stack_size == 0 ? ACE_DEFAULT_THREAD_STACKSIZE : stack_size[i], 00037 thread_adapter, 00038 thr_name == 0 ? 0 : &thr_name[i]) != 0) 00039 break; 00040 } 00041 00042 return i; 00043 }
int ACE_Thread::suspend | ( | ACE_hthread_t | t_id | ) | [static] |
Suspend the execution of a particular thread.
Definition at line 107 of file Thread.inl.
00108 { 00109 ACE_TRACE ("ACE_Thread::suspend"); 00110 return ACE_OS::thr_suspend (t_id); 00111 }
void ACE_Thread::testcancel | ( | void | ) | [static] |
Test the cancel.
Definition at line 248 of file Thread.inl.
00249 { 00250 ACE_TRACE ("ACE_Thread::testcancel"); 00251 00252 ACE_OS::thr_testcancel (); 00253 }
void ACE_Thread::yield | ( | void | ) | [static] |
Yield the thread to another.
Definition at line 67 of file Thread.inl.
00068 { 00069 ACE_TRACE ("ACE_Thread::yield"); 00070 ACE_OS::thr_yield (); 00071 }