version 1.7, 2002/02/26 18:46:44
|
version 1.8, 2002/03/18 11:34:28
|
|
|
return(true); | return(true); |
return(false); | return(false); |
} | } |
|
|
inline Boolean operator==(const thread_data& b) const | inline Boolean operator==(const thread_data& b) const |
{ | { |
return(operator==((const void *)b._key)); | return(operator==((const void *)b._key)); |
|
|
PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *work)(void *)) | PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *work)(void *)) |
throw(IPCException); | throw(IPCException); |
| |
void kill_dead_threads( void ) |
void allocate_and_awaken(void *parm, |
|
PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *work)(void *), |
|
Semaphore *blocking_sem) |
|
throw(IPCException); |
|
|
|
|
|
Uint32 kill_dead_threads( void ) |
throw(IPCException); | throw(IPCException); |
| |
void get_key(Sint8 *buf, int bufsize); | void get_key(Sint8 *buf, int bufsize); |
|
|
struct timeval _deallocate_wait; | struct timeval _deallocate_wait; |
struct timeval _deadlock_detect; | struct timeval _deadlock_detect; |
static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL _loop(void *); | static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL _loop(void *); |
Semaphore _waiters; |
|
Sint8 _key[17]; | Sint8 _key[17]; |
Semaphore _pool_sem; |
|
DQueue<Thread> _pool; | DQueue<Thread> _pool; |
DQueue<Thread> _running; | DQueue<Thread> _running; |
DQueue<Thread> _dead; | DQueue<Thread> _dead; |
|
|
| |
inline Thread *ThreadPool::_init_thread(void) throw(IPCException) | inline Thread *ThreadPool::_init_thread(void) throw(IPCException) |
{ | { |
Thread *th = (Thread *) new Thread(&_loop, this, false); |
Thread *th = (Thread *) new Thread(_loop, this, false); |
// allocate a sleep semaphore and pass it in the thread context | // allocate a sleep semaphore and pass it in the thread context |
// initial count is zero, loop function will sleep until | // initial count is zero, loop function will sleep until |
// we signal the semaphore | // we signal the semaphore |
Semaphore *sleep_sem = (Semaphore *) new Semaphore(0); | Semaphore *sleep_sem = (Semaphore *) new Semaphore(0); |
th->put_tsd("sleep sem", &_sleep_sem_del, sizeof(Semaphore), (void *)sleep_sem); | th->put_tsd("sleep sem", &_sleep_sem_del, sizeof(Semaphore), (void *)sleep_sem); |
|
|
struct timeval *dldt = (struct timeval *) ::operator new(sizeof(struct timeval)); | struct timeval *dldt = (struct timeval *) ::operator new(sizeof(struct timeval)); |
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(); | th->run(); |
_current_threads++; | _current_threads++; |
|
pegasus_yield(); |
|
|
return th; | return th; |
} | } |
| |
|
|
if(th == 0) | if(th == 0) |
throw NullPointer(); | throw NullPointer(); |
_pool.insert_first(th); | _pool.insert_first(th); |
_pool_sem.signal(); |
|
} | } |
| |
| |