version 1.85, 2005/06/07 17:46:30
|
version 1.86, 2005/06/24 19:34:23
|
|
|
ThreadPool::~ThreadPool() | ThreadPool::~ThreadPool() |
{ | { |
PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::~ThreadPool"); | PEG_METHOD_ENTER(TRC_THREAD, "ThreadPool::~ThreadPool"); |
|
|
try | try |
{ | { |
// Set the dying flag so all thread know the destructor has been entered | // Set the dying flag so all thread know the destructor has been entered |
_dying++; | _dying++; |
|
Tracer::trace(TRC_THREAD, Tracer::LEVEL2, |
|
"Cleaning up %d idle threads. ", _currentThreads.value()); |
while (_currentThreads.value() > 0) | while (_currentThreads.value() > 0) |
{ | { |
Thread* thread = _idleThreads.remove_first(); | Thread* thread = _idleThreads.remove_first(); |
|
|
e.getMessage()); | e.getMessage()); |
} | } |
#if !defined(PEGASUS_OS_LSB) | #if !defined(PEGASUS_OS_LSB) |
catch (exception& e) |
catch (const exception& e) |
{ | { |
PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, | PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
String("Exception from work in ThreadPool::_loop: ") + | String("Exception from work in ThreadPool::_loop: ") + |
|
|
return((PEGASUS_THREAD_RETURN)0); | return((PEGASUS_THREAD_RETURN)0); |
} | } |
| |
Boolean ThreadPool::allocate_and_awaken( |
ThreadStatus ThreadPool::allocate_and_awaken( |
void* parm, | void* parm, |
PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL* work)(void *), | PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL* work)(void *), |
Semaphore* blocking) | Semaphore* blocking) |
|
|
{ | { |
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)."); |
// ATTN: Error result has not yet been defined |
return PEGASUS_THREAD_UNAVAILABLE; |
return true; |
|
} | } |
struct timeval start; | struct timeval start; |
gettimeofday(&start, NULL); | gettimeofday(&start, NULL); |
|
|
// necessarily imply that a failure has occurred. However, | // necessarily imply that a failure has occurred. However, |
// this label is being used temporarily to help isolate | // this label is being used temporarily to help isolate |
// the cause of client timeout problems. | // the cause of client timeout problems. |
|
|
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"ThreadPool::allocate_and_awaken: Insufficient resources: " | "ThreadPool::allocate_and_awaken: Insufficient resources: " |
" pool = %s, running threads = %d, idle threads = %d", | " pool = %s, running threads = %d, idle threads = %d", |
_key, _runningThreads.count(), _idleThreads.count()); | _key, _runningThreads.count(), _idleThreads.count()); |
return false; |
return PEGASUS_THREAD_INSUFFICIENT_RESOURCES; |
} | } |
| |
// initialize the thread data with the work function and parameters | // initialize the thread data with the work function and parameters |
|
|
"ThreadPool::allocate_and_awaken: Operation Failed."); | "ThreadPool::allocate_and_awaken: Operation Failed."); |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
// ATTN: Error result has not yet been defined | // ATTN: Error result has not yet been defined |
return true; |
return PEGASUS_THREAD_SETUP_FAILURE; |
} | } |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
return PEGASUS_THREAD_OK; |
} | } |
| |
// caller is responsible for only calling this routine during slack periods | // caller is responsible for only calling this routine during slack periods |
|
|
sizeof(struct timeval), (void *)lastActivityTime); | sizeof(struct timeval), (void *)lastActivityTime); |
// thread will enter _loop() and sleep on sleep_sem until we signal it | // thread will enter _loop() and sleep on sleep_sem until we signal it |
| |
if (!th->run()) |
if (th->run() != PEGASUS_THREAD_OK) |
{ | { |
|
Tracer::trace(TRC_THREAD, Tracer::LEVEL2, |
|
"Could not create thread. Error code is %d.", errno); |
delete th; | delete th; |
return 0; | return 0; |
} | } |