version 1.13, 2002/03/18 15:38:18
|
version 1.14, 2002/04/06 19:28:00
|
|
|
| |
#include "Thread.h" | #include "Thread.h" |
#include <Pegasus/Common/IPC.h> | #include <Pegasus/Common/IPC.h> |
|
#include <Pegasus/Common/Tracer.h> |
| |
#if defined(PEGASUS_OS_TYPE_WINDOWS) | #if defined(PEGASUS_OS_TYPE_WINDOWS) |
# include "ThreadWindows.cpp" | # include "ThreadWindows.cpp" |
|
|
// make this static to the class | // make this static to the class |
PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ThreadPool::_loop(void *parm) | PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ThreadPool::_loop(void *parm) |
{ | { |
|
PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::_loop"); |
|
|
Thread *myself = (Thread *)parm; | Thread *myself = (Thread *)parm; |
if(myself == 0) | if(myself == 0) |
|
{ |
|
PEG_METHOD_EXIT(); |
throw NullPointer(); | throw NullPointer(); |
|
} |
ThreadPool *pool = (ThreadPool *)myself->get_parm(); | ThreadPool *pool = (ThreadPool *)myself->get_parm(); |
if(pool == 0 ) | if(pool == 0 ) |
|
{ |
|
PEG_METHOD_EXIT(); |
throw NullPointer(); | throw NullPointer(); |
|
} |
Semaphore *sleep_sem = 0; | Semaphore *sleep_sem = 0; |
Semaphore *blocking_sem = 0; | Semaphore *blocking_sem = 0; |
| |
|
|
} | } |
catch(IPCException &) | catch(IPCException &) |
{ | { |
|
PEG_METHOD_EXIT(); |
myself->exit_self(0); | myself->exit_self(0); |
} | } |
if(sleep_sem == 0 || deadlock_timer == 0) | if(sleep_sem == 0 || deadlock_timer == 0) |
|
{ |
|
PEG_METHOD_EXIT(); |
throw NullPointer(); | throw NullPointer(); |
|
} |
| |
while(pool->_dying < 1) | while(pool->_dying < 1) |
{ | { |
|
|
} | } |
catch(IPCException &) | catch(IPCException &) |
{ | { |
|
PEG_METHOD_EXIT(); |
myself->exit_self(0); | myself->exit_self(0); |
} | } |
| |
if(_work == 0) | if(_work == 0) |
|
{ |
|
PEG_METHOD_EXIT(); |
throw NullPointer(); | throw NullPointer(); |
|
} |
gettimeofday(deadlock_timer, NULL); | gettimeofday(deadlock_timer, NULL); |
_work(parm); | _work(parm); |
| |
|
|
} | } |
catch(IPCException &) | catch(IPCException &) |
{ | { |
|
PEG_METHOD_EXIT(); |
myself->exit_self(0); | myself->exit_self(0); |
} | } |
} | } |
// wait to be awakend by the thread pool destructor | // wait to be awakend by the thread pool destructor |
sleep_sem->wait(); | sleep_sem->wait(); |
myself->test_cancel(); | myself->test_cancel(); |
|
|
|
PEG_METHOD_EXIT(); |
myself->exit_self(0); | myself->exit_self(0); |
return((PEGASUS_THREAD_RETURN)0); | return((PEGASUS_THREAD_RETURN)0); |
} | } |
|
|
| |
throw(IPCException) | throw(IPCException) |
{ | { |
|
PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::allocate_and_awaken"); |
struct timeval start; | struct timeval start; |
gettimeofday(&start, NULL); | gettimeofday(&start, NULL); |
| |
|
|
if(_dying < 1) | if(_dying < 1) |
{ | { |
// initialize the thread data with the work function and parameters | // initialize the thread data with the work function and parameters |
|
Tracer::trace(TRC_THREAD, Tracer::LEVEL4, |
|
"Initializing thread with work function and parameters: parm = %p", |
|
parm); |
|
|
th->remove_tsd("work func"); | th->remove_tsd("work func"); |
th->put_tsd("work func", NULL, | th->put_tsd("work func", NULL, |
sizeof( PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *)(void *)), | sizeof( PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *)(void *)), |
|
|
if(sleep_sem == 0) | if(sleep_sem == 0) |
{ | { |
th->dereference_tsd(); | th->dereference_tsd(); |
|
PEG_METHOD_EXIT(); |
throw NullPointer(); | throw NullPointer(); |
} | } |
|
Tracer::trace(TRC_THREAD, Tracer::LEVEL4, "Signal thread to awaken"); |
sleep_sem->signal(); | sleep_sem->signal(); |
th->dereference_tsd(); | th->dereference_tsd(); |
} | } |
else | else |
_pool.insert_first(th); | _pool.insert_first(th); |
|
|
|
PEG_METHOD_EXIT(); |
} | } |
| |
// caller is responsible for only calling this routine during slack periods | // caller is responsible for only calling this routine during slack periods |