version 1.58, 2003/10/23 19:30:23
|
version 1.59, 2003/10/30 00:22:39
|
|
|
// | // |
// Modified By: Rudy Schuet (rudy.schuet@compaq.com) 11/12/01 | // Modified By: Rudy Schuet (rudy.schuet@compaq.com) 11/12/01 |
// added nsk platform support | // added nsk platform support |
|
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
{ | { |
_work(parm); | _work(parm); |
} | } |
|
catch(Exception & e) |
|
{ |
|
PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
|
String("Exception from _work in ThreadPool::_loop: ") + |
|
e.getMessage()); |
|
PEG_METHOD_EXIT(); |
|
return((PEGASUS_THREAD_RETURN)0); |
|
} |
catch(...) | catch(...) |
{ | { |
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
|
|
return((PEGASUS_THREAD_RETURN)0); | return((PEGASUS_THREAD_RETURN)0); |
} | } |
| |
void ThreadPool::allocate_and_awaken(void *parm, |
Boolean ThreadPool::allocate_and_awaken(void *parm, |
PEGASUS_THREAD_RETURN \ | PEGASUS_THREAD_RETURN \ |
(PEGASUS_THREAD_CDECL *work)(void *), | (PEGASUS_THREAD_CDECL *work)(void *), |
Semaphore *blocking) | Semaphore *blocking) |
|
|
throw(IPCException) | throw(IPCException) |
{ | { |
PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::allocate_and_awaken"); | PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::allocate_and_awaken"); |
|
|
{ | { |
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"ThreadPool::allocate_and_awaken: ThreadPool is dying(1)."); | "ThreadPool::allocate_and_awaken: ThreadPool is dying(1)."); |
return; |
// ATTN: Error result has not yet been defined |
|
return true; |
} | } |
struct timeval now; | struct timeval now; |
struct timeval start; | struct timeval start; |
|
|
| |
th = _pool.remove_first(); | th = _pool.remove_first(); |
| |
// wait for the right interval and try again |
if (th == 0) |
while (th == 0) |
|
{ | { |
// will throw an IPCException& | // will throw an IPCException& |
_check_deadlock(&start) ; | _check_deadlock(&start) ; |
|
|
if(_max_threads == 0 || _current_threads < _max_threads) | if(_max_threads == 0 || _current_threads < _max_threads) |
{ | { |
th = _init_thread(); | th = _init_thread(); |
continue; |
|
} | } |
pegasus_yield(); |
} |
th = _pool.remove_first(); |
|
|
if (th == 0) |
|
{ |
|
return false; |
} | } |
| |
// initialize the thread data with the work function and parameters | // initialize the thread data with the work function and parameters |
|
|
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"ThreadPool::allocate_and_awaken: Operation Failed."); | "ThreadPool::allocate_and_awaken: Operation Failed."); |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return; |
// ATTN: Error result has not yet been defined |
|
return true; |
} | } |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
|
return true; |
} | } |
| |
// caller is responsible for only calling this routine during slack periods | // caller is responsible for only calling this routine during slack periods |
|
|
| |
bodies++; | bodies++; |
th->dereference_tsd(); | th->dereference_tsd(); |
_dead.insert_first(th); |
// Putting thread on _dead queue delays availability to others |
|
//_dead.insert_first(th); |
sleep_sem->signal(); | sleep_sem->signal(); |
|
th->join(); // Note: Clean up the thread here rather than |
|
delete th; // leave it sitting unused on the _dead queue |
th = 0; | th = 0; |
} | } |
else | else |
|
|
th->put_tsd("deadlock timer", thread_data::default_delete, sizeof(struct timeval), (void *)dldt); | th->put_tsd("deadlock timer", thread_data::default_delete, sizeof(struct timeval), (void *)dldt); |
// thread will enter _loop(void *) and sleep on sleep_sem until we signal it | // thread will enter _loop(void *) and sleep on sleep_sem until we signal it |
| |
th->run(); |
if (!th->run()) |
|
{ |
|
delete th; |
|
return 0; |
|
} |
_current_threads++; | _current_threads++; |
pegasus_yield(); | pegasus_yield(); |
| |