version 1.98.4.1, 2007/04/04 11:04:44
|
version 1.100.2.6, 2008/10/23 18:59:32
|
|
|
| |
extern "C" void *_start_wrapper(void *arg_) | extern "C" void *_start_wrapper(void *arg_) |
{ | { |
StartWrapperArg *arg = (StartWrapperArg *) arg_; |
// Clean up dynamic memory now to prevent a leak if the thread is canceled. |
|
StartWrapperArg arg; |
|
arg.start = ((StartWrapperArg *) arg_)->start; |
|
arg.arg = ((StartWrapperArg *) arg_)->arg; |
|
delete (StartWrapperArg *) arg_; |
| |
void *return_value = (*arg->start) (arg->arg); |
// establish cancelability of the thread |
delete arg; |
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); |
|
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); |
|
|
|
void *return_value = (*arg.start) (arg.arg); |
| |
return return_value; | return return_value; |
} | } |
|
|
arg->start = _start; | arg->start = _start; |
arg->arg = this; | arg->arg = this; |
| |
Threads::Type type = _is_detached ? Threads::DETACHED : Threads::JOINABLE; |
Threads::Type type = |
|
_is_detached ? Threads::THREADS_DETACHED : Threads::THREADS_JOINABLE; |
int rc = Threads::create(_handle.thid, type, _start_wrapper, arg); | int rc = Threads::create(_handle.thid, type, _start_wrapper, arg); |
| |
// On Linux distributions released prior 2005, the implementation of | // On Linux distributions released prior 2005, the implementation of |
|
|
return sig; | return sig; |
} | } |
| |
|
/* |
|
ATTN: remove this! |
|
*/ |
|
#if 1 |
|
static Uint32 _num_threads = 0; |
|
static Mutex _num_threads_mutex; |
|
#endif |
|
|
Thread::Thread( | Thread::Thread( |
ThreadReturnType(PEGASUS_THREAD_CDECL* start) (void*), | ThreadReturnType(PEGASUS_THREAD_CDECL* start) (void*), |
void* parameter, | void* parameter, |
|
|
_thread_parm(parameter), | _thread_parm(parameter), |
_exit_code(0) | _exit_code(0) |
{ | { |
|
/* |
|
ATTN: remove this! |
|
*/ |
|
#if 1 |
|
Uint32 num_threads; |
|
_num_threads_mutex.lock(); |
|
_num_threads++; |
|
num_threads = _num_threads; |
|
printf("Thread::Thread(): num_threads=%u\n", num_threads); |
|
_num_threads_mutex.unlock(); |
|
#endif |
|
|
Threads::clear(_handle.thid); | Threads::clear(_handle.thid); |
} | } |
| |
Thread::~Thread() | Thread::~Thread() |
{ | { |
|
/* |
|
ATTN: remove this! |
|
*/ |
|
#if 1 |
|
Uint32 num_threads; |
|
_num_threads_mutex.lock(); |
|
_num_threads--; |
|
num_threads = _num_threads; |
|
printf("Thread::~Thread(): num_threads=%u\n", num_threads); |
|
_num_threads_mutex.unlock(); |
|
#endif |
|
|
try | try |
{ | { |
join(); | join(); |
|
|
| |
void Thread::exit_self(ThreadReturnType exit_code) | void Thread::exit_self(ThreadReturnType exit_code) |
{ | { |
#ifndef PEGASUS_PLATFORM_AIX_RS_IBMCXX |
#if !defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) \ |
|
&& !defined(PEGASUS_PLATFORM_PASE_ISERIES_IBMCXX) |
Threads::exit(exit_code); | Threads::exit(exit_code); |
#else | #else |
// execute the cleanup stack and then return | // execute the cleanup stack and then return |