#include <Thread.h>
Static Public Methods | |
| 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=0, 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, ACE_thread_t *, ACE_THR_FUNC_RETURN *status) |
| Wait for one or more threads to exit and reap their exit status. More... | |
| int | join (ACE_hthread_t, ACE_THR_FUNC_RETURN *=0) |
| Wait for one thread to exit and reap its exit status. More... | |
| int | resume (ACE_hthread_t) |
| Continue the execution of a previously suspended thread. More... | |
| int | suspend (ACE_hthread_t) |
| Suspend the execution of a particular thread. More... | |
| int | getprio (ACE_hthread_t id, int &priority) |
| Get the priority of a particular thread. More... | |
| int | getprio (ACE_hthread_t id, int &priority, int &policy) |
| Get the priority and policy of a particular thread. More... | |
| int | setprio (ACE_hthread_t id, int priority, int policy=-1) |
| Set the priority of a particular thread. More... | |
| int | kill (ACE_thread_t, int signum) |
| Send a signal to the thread. More... | |
| void | yield (void) |
| Yield the thread to another. More... | |
| void | self (ACE_hthread_t &t_handle) |
| ACE_thread_t | self (void) |
| Return the unique ID of the thread. More... | |
| void | exit (ACE_THR_FUNC_RETURN status=0) |
| Exit the current thread and return "status". Should _not_ be called by main thread. More... | |
| int | getconcurrency (void) |
| Get the LWP concurrency level of the process. More... | |
| int | setconcurrency (int new_level) |
| Set the LWP concurrency level of the process. More... | |
| int | sigsetmask (int how, const sigset_t *sigset, sigset_t *osigset=0) |
| Change and/or examine calling thread's signal mask. More... | |
| 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. More... | |
| int | setspecific (ACE_thread_key_t key, void *value) |
| Bind value to the thread-specific data key, <key>, for the calling thread. More... | |
| int | getspecific (ACE_thread_key_t key, void **valuep) |
| Stores the current value bound to <key> for the calling thread into the location pointed to by <valuep>. More... | |
| int | disablecancel (struct cancel_state *old_state) |
| Disable thread cancellation. More... | |
| int | enablecancel (struct cancel_state *old_state, int flag) |
| Enable thread cancellation. More... | |
| int | setcancelstate (struct cancel_state &new_state, struct cancel_state *old_state) |
| Set the cancellation state. More... | |
| int | cancel (ACE_thread_t t_id) |
| void | testcancel (void) |
| Test the cancel. More... | |
Private Methods | |
| ACE_Thread (void) | |
| Ensure that we don't get instantiated. More... | |
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 39 of file Thread.h.
|
|
Ensure that we don't get instantiated.
|
|
|
Cancel a thread. Note that this method is only portable on platforms, such as POSIX pthreads, that support thread cancellation. Definition at line 238 of file Thread.i. References ACE_thread_t, ACE_TRACE, and ACE_OS::thr_cancel. Referenced by ACE_Thread_Manager::cancel_thr.
00239 {
00240 ACE_TRACE ("ACE_Thread::cancel");
00241
00242 return ACE_OS::thr_cancel (t_id);
00243 }
|
|
|
Disable thread cancellation.
Definition at line 159 of file Thread.i. References ACE_TRACE, cancel_state::cancelstate, ACE_OS_String::memset, and ACE_OS::thr_setcancelstate.
00160 {
00161 ACE_TRACE ("ACE_Thread::disablecancel");
00162 int old_cstate = 0;
00163 int result = ACE_OS::thr_setcancelstate (THR_CANCEL_DISABLE,
00164 &old_cstate);
00165 if (result == 0 && old_state != 0)
00166 {
00167 ACE_OS::memset (old_state,
00168 0,
00169 sizeof (old_state));
00170 old_state->cancelstate = old_cstate;
00171 }
00172
00173 return result;
00174 }
|
|
||||||||||||
|
Enable thread cancellation.
Definition at line 177 of file Thread.i. References ACE_TRACE, cancel_state::cancelstate, cancel_state::canceltype, ACE_OS::thr_setcancelstate, and ACE_OS::thr_setcanceltype.
00179 {
00180 ACE_TRACE ("ACE_Thread::enablecancel");
00181 int old_cstate = 0;
00182 int old_ctype = 0;
00183 int result;
00184
00185 result = ACE_OS::thr_setcancelstate (THR_CANCEL_ENABLE,
00186 &old_cstate);
00187 if (result != 0)
00188 return result;
00189
00190 result = ACE_OS::thr_setcanceltype (flag,
00191 &old_ctype);
00192 if (result != 0)
00193 return result;
00194
00195 if (old_state != 0)
00196 {
00197 old_state->cancelstate = old_cstate;
00198 old_state->canceltype = old_ctype;
00199 }
00200
00201 return 0;
00202 }
|
|
|
Exit the current thread and return "status". Should _not_ be called by main thread.
Definition at line 60 of file Thread.i. References ACE_TRACE, and ACE_OS::thr_exit. Referenced by ACE_Thread_Manager::exit.
00061 {
00062 ACE_TRACE ("ACE_Thread::exit");
00063 ACE_OS::thr_exit (status);
00064 }
|
|
|
Get the LWP concurrency level of the process.
Definition at line 136 of file Thread.i. References ACE_TRACE, and ACE_OS::thr_getconcurrency.
00137 {
00138 ACE_TRACE ("ACE_Thread::getconcurrency");
00139 return ACE_OS::thr_getconcurrency ();
00140 }
|
|
||||||||||||||||
|
Get the priority and policy of a particular thread.
Definition at line 268 of file Thread.i. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_getprio.
00269 {
00270 ACE_TRACE ("ACE_Thread::getprio");
00271 return ACE_OS::thr_getprio (id, priority, policy);
00272 }
|
|
||||||||||||
|
Get the priority of a particular thread.
Definition at line 261 of file Thread.i. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_getprio.
00262 {
00263 ACE_TRACE ("ACE_Thread::getprio");
00264 return ACE_OS::thr_getprio (id, priority);
00265 }
|
|
||||||||||||
|
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.i. References ACE_thread_key_t, and ACE_OS::thr_getspecific. Referenced by ACE_Log_Msg::exists, and ACE_Log_Msg::instance.
00047 {
00048 // ACE_TRACE ("ACE_Thread::getspecific");
00049 return ACE_OS::thr_getspecific (key, valuep);
00050 }
|
|
||||||||||||
|
Wait for one thread to exit and reap its exit status.
Definition at line 128 of file Thread.i. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_join.
00130 {
00131 ACE_TRACE ("ACE_Thread::join");
00132 return ACE_OS::thr_join (wait_for, status);
00133 }
|
|
||||||||||||||||
|
Wait for one or more threads to exit and reap their exit status.
Definition at line 119 of file Thread.i. References ACE_thread_t, 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.
00122 {
00123 ACE_TRACE ("ACE_Thread::join");
00124 return ACE_OS::thr_join (wait_for, departed, status);
00125 }
|
|
||||||||||||||||
|
Definition at line 11 of file Thread.i. References ACE_thread_key_t, and ACE_OS::thr_keycreate. Referenced by ACE_Log_Msg::instance.
00018 {
00019 // ACE_TRACE ("ACE_Thread::keycreate");
00020 return ACE_OS::thr_keycreate (keyp, destructor, inst);
00021 }
|
|
|
Free up the key so that other threads can reuse it.
Definition at line 26 of file Thread.i. References ACE_thread_key_t, ACE_TRACE, and ACE_OS::thr_keyfree.
00027 {
00028 ACE_TRACE ("ACE_Thread::keyfree");
00029 return ACE_OS::thr_keyfree (key);
00030 }
|
|
||||||||||||
|
Send a signal to the thread.
Definition at line 112 of file Thread.i. References ACE_thread_t, ACE_TRACE, and ACE_OS::thr_kill. Referenced by ACE_Thread_Manager::kill_thr.
00113 {
00114 ACE_TRACE ("ACE_Thread::kill");
00115 return ACE_OS::thr_kill (t_id, signum);
00116 }
|
|
|
Continue the execution of a previously suspended thread.
Definition at line 98 of file Thread.i. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_continue. Referenced by ACE_Thread_Manager::resume_thr.
00099 {
00100 ACE_TRACE ("ACE_Thread::resume");
00101 return ACE_OS::thr_continue (t_id);
00102 }
|
|
|
Return the unique ID of the thread.
Definition at line 53 of file Thread.i. References ACE_OS::thr_self. Referenced by ACE_TPQ_Entry::ACE_TPQ_Entry, ACE_WFMO_Reactor::calculate_timeout, ACE_WFMO_Reactor_Handler_Repository::current_info, ACE_WFMO_Reactor::expire_timers, ACE_WFMO_Reactor_Handler_Repository::handles, ACE_Log_Msg::log, ACE_WFMO_Reactor_Handler_Repository::max_handlep1, ACE_Select_Reactor_T::open, ACE_TP_Reactor::owner, ACE_Token::renew, ACE_WFMO_Reactor_Handler_Repository::scheduled_for_deletion, ACE_Token::shared_acquire, ACE_Thread_Timer_Queue_Adapter::svc, ACE_Thread_Manager::thr_self, and ACE_WFMO_Reactor::update_state.
00054 {
00055 // ACE_TRACE ("ACE_Thread::self");
00056 return ACE_OS::thr_self ();
00057 }
|
|
|
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 254 of file Thread.i. References ACE_hthread_t, and ACE_OS::thr_self. Referenced by ACE_Token::dump, ACE_Select_Reactor_T::handle_events, ACE_Log_Msg::log, and ACE_Asynch_Pseudo_Task::svc.
00255 {
00256 // ACE_TRACE ("ACE_Thread::self");
00257 ACE_OS::thr_self (t_id);
00258 }
|
|
||||||||||||
|
Set the cancellation state.
Definition at line 205 of file Thread.i. References ACE_TRACE, cancel_state::cancelstate, cancel_state::canceltype, ACE_OS::thr_setcancelstate, and ACE_OS::thr_setcanceltype.
00207 {
00208 ACE_TRACE ("ACE_Thread::setcancelstate");
00209 int old_cstate = 0;
00210 int old_ctype = 0;
00211
00212 if (new_state.cancelstate != 0
00213 && ACE_OS::thr_setcancelstate (new_state.cancelstate,
00214 &old_cstate) != 0)
00215 return -1;
00216
00217 if (new_state.canceltype != 0
00218 && ACE_OS::thr_setcanceltype (new_state.canceltype,
00219 &old_ctype) != 0)
00220 {
00221 int o_cstate;
00222
00223 ACE_OS::thr_setcancelstate (old_cstate,
00224 &o_cstate);
00225 return -1;
00226 }
00227
00228 if (old_state != 0)
00229 {
00230 old_state->cancelstate = old_cstate;
00231 old_state->canceltype = old_ctype;
00232 }
00233
00234 return 0;
00235 }
|
|
|
Set the LWP concurrency level of the process.
Definition at line 143 of file Thread.i. References ACE_TRACE, and ACE_OS::thr_setconcurrency.
00144 {
00145 ACE_TRACE ("ACE_Thread::setconcurrency");
00146 return ACE_OS::thr_setconcurrency (new_level);
00147 }
|
|
||||||||||||||||
|
Set the priority of a particular thread.
Definition at line 275 of file Thread.i. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_setprio.
00276 {
00277 ACE_TRACE ("ACE_Thread::setprio");
00278 return ACE_OS::thr_setprio (id, priority, policy);
00279 }
|
|
||||||||||||
|
Bind value to the thread-specific data key, <key>, for the calling thread.
Definition at line 36 of file Thread.i. References ACE_thread_key_t, and ACE_OS::thr_setspecific. Referenced by ACE_Log_Msg::instance.
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 150 of file Thread.i. References ACE_TRACE, and ACE_OS::thr_sigsetmask.
00153 {
00154 ACE_TRACE ("ACE_Thread::sigsetmask");
00155 return ACE_OS::thr_sigsetmask (how, sigset, osigset);
00156 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
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 74 of file Thread.i. References ACE_hthread_t, ACE_thread_t, ACE_TRACE, and ACE_OS::thr_create. Referenced by ACE_Thread_Manager::spawn_i.
00083 {
00084 ACE_TRACE ("ACE_Thread::spawn");
00085
00086 return ACE_OS::thr_create (func,
00087 arg,
00088 flags,
00089 t_id,
00090 t_handle,
00091 priority,
00092 thr_stack,
00093 thr_stack_size,
00094 thread_adapter);
00095 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
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 <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. 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. References ACE_hthread_t, ACE_thread_t, ACE_TRACE, and ACE_OS::thr_create.
00056 {
00057 ACE_TRACE ("ACE_Thread::spawn_n");
00058 size_t i;
00059
00060 for (i = 0; i < n; i++)
00061 {
00062 ACE_thread_t t_id;
00063 ACE_hthread_t t_handle;
00064
00065 int result =
00066 ACE_OS::thr_create (func,
00067 arg,
00068 flags,
00069 &t_id,
00070 &t_handle,
00071 priority,
00072 stack == 0 ? 0 : stack[i],
00073 stack_size == 0 ? 0 : stack_size[i],
00074 thread_adapter);
00075
00076 if (result == 0)
00077 {
00078 if (thread_ids != 0)
00079 thread_ids[i] = t_id;
00080 if (thread_handles != 0)
00081 thread_handles[i] = t_handle;
00082 }
00083 else
00084 // Bail out if error occurs.
00085 break;
00086 }
00087
00088 return i;
00089 }
|
|
||||||||||||||||||||||||||||||||||||
|
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 <stack>s 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 16 of file Thread.cpp. References ACE_thread_t, ACE_TRACE, and ACE_OS::thr_create.
00024 {
00025 ACE_TRACE ("ACE_Thread::spawn_n");
00026 ACE_thread_t t_id;
00027 size_t i;
00028
00029 for (i = 0; i < n; i++)
00030 // Bail out if error occurs.
00031 if (ACE_OS::thr_create (func,
00032 arg,
00033 flags,
00034 &t_id,
00035 0,
00036 priority,
00037 stack == 0 ? 0 : stack[i],
00038 stack_size == 0 ? 0 : stack_size[i],
00039 thread_adapter) != 0)
00040 break;
00041
00042 return i;
00043 }
|
|
|
Suspend the execution of a particular thread.
Definition at line 105 of file Thread.i. References ACE_hthread_t, ACE_TRACE, and ACE_OS::thr_suspend. Referenced by ACE_Thread_Manager::suspend_thr.
00106 {
00107 ACE_TRACE ("ACE_Thread::suspend");
00108 return ACE_OS::thr_suspend (t_id);
00109 }
|
|
|
Test the cancel.
Definition at line 246 of file Thread.i. References ACE_TRACE, and ACE_OS::thr_testcancel.
00247 {
00248 ACE_TRACE ("ACE_Thread::testcancel");
00249
00250 ACE_OS::thr_testcancel ();
00251 }
|
|
|
Yield the thread to another.
Definition at line 67 of file Thread.i. References ACE_TRACE, and ACE_OS::thr_yield.
00068 {
00069 ACE_TRACE ("ACE_Thread::yield");
00070 ACE_OS::thr_yield ();
00071 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002