version 1.98.4.2, 2008/02/19 22:42:15
|
version 1.107, 2008/09/16 18:37:03
|
|
|
| |
extern "C" void *_start_wrapper(void *arg_) | extern "C" void *_start_wrapper(void *arg_) |
{ | { |
AutoPtr<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 |
|
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; |
} | } |
| |
void Thread::cancel() | void Thread::cancel() |
{ | { |
_cancelled = true; |
|
pthread_cancel(_handle.thid.thread); | pthread_cancel(_handle.thid.thread); |
} | } |
| |
void Thread::test_cancel() |
|
{ |
|
#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
|
pthread_testintr(); |
|
#else |
|
pthread_testcancel(); |
|
#endif |
|
} |
|
|
|
Boolean Thread::is_cancelled() |
|
{ |
|
return _cancelled; |
|
} |
|
|
|
void Thread::thread_switch() | void Thread::thread_switch() |
{ | { |
#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) | #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
|
|
#endif | #endif |
} | } |
| |
/* |
|
ATTN: why are these missing on other platforms? |
|
*/ |
|
#if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
|
void Thread::suspend() |
|
{ |
|
pthread_kill(_handle.thid.thread, SIGSTOP); |
|
} |
|
|
|
void Thread::resume() |
|
{ |
|
pthread_kill(_handle.thid.thread, SIGCONT); |
|
} |
|
#endif |
|
|
|
void Thread::sleep(Uint32 msec) | void Thread::sleep(Uint32 msec) |
{ | { |
Threads::sleep(msec); | Threads::sleep(msec); |
|
|
Threads::clear(_handle.thid); | Threads::clear(_handle.thid); |
} | } |
| |
void Thread::thread_init() |
|
{ |
|
#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
|
pthread_setintr(PTHREAD_INTR_ENABLE); |
|
pthread_setintrtype(PTHREAD_INTR_ASYNCHRONOUS); |
|
#else |
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); |
|
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); |
|
#endif |
|
_cancel_enabled = true; |
|
} |
|
|
|
void Thread::detach() | void Thread::detach() |
{ | { |
_is_detached = true; | _is_detached = true; |
|
|
return PEGASUS_THREAD_OK; | return PEGASUS_THREAD_OK; |
} | } |
| |
static sigset_t *block_signal_mask(sigset_t * sig) |
|
{ |
|
sigemptyset(sig); |
|
// should not be used for main() |
|
sigaddset(sig, SIGHUP); |
|
sigaddset(sig, SIGINT); |
|
// maybe useless, since KILL can't be blocked according to POSIX |
|
sigaddset(sig, SIGKILL); |
|
|
|
sigaddset(sig, SIGABRT); |
|
sigaddset(sig, SIGALRM); |
|
sigaddset(sig, SIGPIPE); |
|
|
|
|
|
// Note: older versions of the linux pthreads library use SIGUSR1 and SIGUSR2 |
|
// internally to stop and start threads that are blocking, the newer ones |
|
// implement this through the kernel's real time signals |
|
// since SIGSTOP/CONT can handle suspend()/resume() on Linux |
|
// block them |
|
// #if defined(PEGASUS_PLATFORM_LINUX_IX86_GNU) |
|
// sigaddset(sig, SIGUSR1); |
|
// sigaddset(sig, SIGUSR2); |
|
// #endif |
|
#if defined (PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined (PEGASUS_OS_VMS) |
|
sigprocmask(SIG_BLOCK, sig, NULL); |
|
#else |
|
pthread_sigmask(SIG_BLOCK, sig, NULL); |
|
#endif |
|
return sig; |
|
} |
|
|
|
Thread::Thread( | Thread::Thread( |
ThreadReturnType(PEGASUS_THREAD_CDECL* start) (void*), | ThreadReturnType(PEGASUS_THREAD_CDECL* start) (void*), |
void* parameter, | void* parameter, |
Boolean detached) | Boolean detached) |
: _is_detached(detached), | : _is_detached(detached), |
_cancel_enabled(true), |
|
_cancelled(false), |
|
_start(start), | _start(start), |
_cleanup(), | _cleanup(), |
_tsd(), | _tsd(), |
|
|
_cancelled = true; | _cancelled = true; |
} | } |
| |
void Thread::test_cancel() |
|
{ |
|
if (_cancel_enabled && _cancelled) |
|
{ |
|
exit_self(0); |
|
} |
|
} |
|
|
|
Boolean Thread::is_cancelled() |
|
{ |
|
return _cancelled; |
|
} |
|
|
|
void Thread::thread_switch() | void Thread::thread_switch() |
{ | { |
Sleep(0); | Sleep(0); |
|
|
} | } |
} | } |
| |
void Thread::thread_init() |
|
{ |
|
_cancel_enabled = true; |
|
} |
|
|
|
void Thread::detach() | void Thread::detach() |
{ | { |
_is_detached = true; | _is_detached = true; |
|
|
Thread::Thread(ThreadReturnType(PEGASUS_THREAD_CDECL * start) (void *), | Thread::Thread(ThreadReturnType(PEGASUS_THREAD_CDECL * start) (void *), |
void *parameter, | void *parameter, |
Boolean detached):_is_detached(detached), | Boolean detached):_is_detached(detached), |
_cancel_enabled(true), |
|
_cancelled(false), | _cancelled(false), |
_start(start), _cleanup(), _tsd(), _thread_parm(parameter), _exit_code(0) | _start(start), _cleanup(), _tsd(), _thread_parm(parameter), _exit_code(0) |
{ | { |
|
|
{ | { |
cu.reset(_cleanup.remove_front()); | cu.reset(_cleanup.remove_front()); |
} | } |
catch (IPCException &) |
catch (...) |
{ | { |
PEGASUS_ASSERT(0); | PEGASUS_ASSERT(0); |
} | } |
|
|
| |
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 |
|
|
{ | { |
cleanup_pop(true); | cleanup_pop(true); |
} | } |
catch (IPCException &) |
catch (...) |
{ | { |
PEGASUS_ASSERT(0); | PEGASUS_ASSERT(0); |
break; | break; |
|
|
{ | { |
if (Thread::_key_error) | if (Thread::_key_error) |
{ | { |
PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4, |
PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL1, |
"Thread: ERROR - thread key error"); | "Thread: ERROR - thread key error"); |
return -1; | return -1; |
} | } |
|
|
} | } |
else | else |
{ | { |
PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4, |
PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL1, |
"Thread: ERROR - unable to create a thread key"); | "Thread: ERROR - unable to create a thread key"); |
Thread::_key_error = true; | Thread::_key_error = true; |
return -1; | return -1; |
|
|
} | } |
else | else |
{ | { |
PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4, |
PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL1, |
"ERROR: error setting Thread * into thread specific storage"); | "ERROR: error setting Thread * into thread specific storage"); |
} | } |
} | } |
|
|
return acceptLangs; | return acceptLangs; |
} | } |
| |
void Thread::setLanguages(AcceptLanguageList * langs) |
void Thread::setLanguages(const AcceptLanguageList& langs) |
{ | { |
PEG_METHOD_ENTER(TRC_THREAD, "Thread::setLanguages"); | PEG_METHOD_ENTER(TRC_THREAD, "Thread::setLanguages"); |
| |
Thread *currentThrd = Thread::getCurrent(); | Thread *currentThrd = Thread::getCurrent(); |
if (currentThrd != NULL) | if (currentThrd != NULL) |
{ | { |
|
AutoPtr<AcceptLanguageList> langsCopy(new AcceptLanguageList(langs)); |
|
|
// deletes the old tsd and creates a new one | // deletes the old tsd and creates a new one |
currentThrd->put_tsd("acceptLanguages", |
currentThrd->put_tsd( |
|
"acceptLanguages", |
language_delete, | language_delete, |
sizeof (AcceptLanguageList *), langs); |
sizeof (AcceptLanguageList *), |
|
langsCopy.get()); |
|
|
|
langsCopy.release(); |
} | } |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |