version 1.19, 2002/06/07 15:17:13
|
version 1.20, 2002/06/07 20:52:13
|
|
|
| |
#endif | #endif |
| |
|
DQueue<ThreadPool> ThreadPool::_pools(true); |
|
|
|
|
|
void ThreadPool::kill_idle_threads(void) |
|
{ |
|
static struct timeval now, last = {0, 0}; |
|
|
|
pegasus_gettimeofday(&now); |
|
if(now.tv_sec - last.tv_sec > 5) |
|
{ |
|
_pools.lock(); |
|
ThreadPool *p = _pools.next(0); |
|
while(p != 0) |
|
{ |
|
try |
|
{ |
|
p->kill_dead_threads(); |
|
} |
|
catch(...) |
|
{ |
|
} |
|
p = _pools.next(p); |
|
} |
|
_pools.unlock(); |
|
pegasus_gettimeofday(&last); |
|
} |
|
} |
|
|
|
|
ThreadPool::ThreadPool(Sint16 initial_size, | ThreadPool::ThreadPool(Sint16 initial_size, |
const Sint8 *key, | const Sint8 *key, |
Sint16 min, | Sint16 min, |
|
|
{ | { |
_link_pool(_init_thread()); | _link_pool(_init_thread()); |
} | } |
|
_pools.insert_last(this); |
|
|
} | } |
| |
| |
|
|
ThreadPool::~ThreadPool(void) | ThreadPool::~ThreadPool(void) |
{ | { |
| |
|
_pools.remove(this); |
_dying++; | _dying++; |
Thread *th = 0; | Thread *th = 0; |
th = _pool.remove_first(); | th = _pool.remove_first(); |
|
|
delete th; | delete th; |
th = _dead.remove_first(); | th = _dead.remove_first(); |
} | } |
|
|
} | } |
| |
// make this static to the class | // make this static to the class |
|
|
throw NullPointer(); | throw NullPointer(); |
} | } |
gettimeofday(deadlock_timer, NULL); | gettimeofday(deadlock_timer, NULL); |
|
try |
|
{ |
_work(parm); | _work(parm); |
|
} |
|
catch(...) |
|
{ |
|
gettimeofday(deadlock_timer, NULL); |
|
} |
|
gettimeofday(deadlock_timer, NULL); |
if( blocking_sem != 0 ) | if( blocking_sem != 0 ) |
blocking_sem->signal(); | blocking_sem->signal(); |
| |
|
|
} | } |
} | } |
delete dead; | delete dead; |
|
pegasus_sleep(1); |
} | } |
| |
DQueue<Thread> * map[2] = | DQueue<Thread> * map[2] = |
|
|
int i = 0; | int i = 0; |
AtomicInt needed(0); | AtomicInt needed(0); |
| |
for( q = map[i] ; i < 2; i++, q = map[i]) |
for( q = map[i] ; i < 2; i++, q = map[i], pegasus_sleep(1)) |
{ | { |
if(q->count() > 0 ) | if(q->count() > 0 ) |
{ | { |
|
|
} | } |
} | } |
th = q->next(th); | th = q->next(th); |
|
pegasus_sleep(1); |
} | } |
q->unlock(); | q->unlock(); |
while (needed.value() > 0) | while (needed.value() > 0) |
{ | { |
_link_pool(_init_thread()); | _link_pool(_init_thread()); |
needed--; | needed--; |
|
pegasus_sleep(0); |
} | } |
} | } |
} | } |