version 1.55.12.1, 2006/06/29 17:33:12
|
version 1.57.2.1, 2006/07/27 23:11:52
|
|
|
| |
#include <cstring> | #include <cstring> |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/IPC.h> |
#include <Pegasus/Common/AtomicInt.h> |
#include <Pegasus/Common/InternalException.h> | #include <Pegasus/Common/InternalException.h> |
#include <Pegasus/Common/AcceptLanguageList.h> | #include <Pegasus/Common/AcceptLanguageList.h> |
#include <Pegasus/Common/Linkage.h> | #include <Pegasus/Common/Linkage.h> |
#include <Pegasus/Common/AutoPtr.h> | #include <Pegasus/Common/AutoPtr.h> |
#include <Pegasus/Common/List.h> | #include <Pegasus/Common/List.h> |
#include <Pegasus/Common/RMutex.h> |
#include <Pegasus/Common/Mutex.h> |
|
#include <Pegasus/Common/Semaphore.h> |
|
#include <Pegasus/Common/TSDKey.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
public: | public: |
cleanup_handler( void (*routine)(void *), void *arg ) : _routine(routine), _arg(arg) {} | cleanup_handler( void (*routine)(void *), void *arg ) : _routine(routine), _arg(arg) {} |
~cleanup_handler() {; } | ~cleanup_handler() {; } |
inline Boolean operator==(const void *key) const |
|
{ |
|
if(key == (void *)_routine) |
|
return true; |
|
return false; |
|
} |
|
inline Boolean operator ==(const cleanup_handler & b) const |
|
{ |
|
return(operator==((const void *)b._routine)); |
|
} |
|
private: | private: |
void execute() { _routine(_arg); } | void execute() { _routine(_arg); } |
cleanup_handler(); | cleanup_handler(); |
void (*_routine)(void *); | void (*_routine)(void *); |
| |
void *_arg; | void *_arg; |
PEGASUS_CLEANUP_HANDLE _cleanup_buffer; |
ThreadCleanupType _cleanup_buffer; |
friend class Thread; | friend class Thread; |
}; | }; |
| |
|
|
{ | { |
public: | public: |
| |
Thread( PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *start )(void *), |
Thread( ThreadReturnType (PEGASUS_THREAD_CDECL *start )(void *), |
void *parameter, Boolean detached ); | void *parameter, Boolean detached ); |
| |
~Thread(); | ~Thread(); |
|
|
| |
// thread routine needs to call this function when | // thread routine needs to call this function when |
// it is ready to exit | // it is ready to exit |
void exit_self(PEGASUS_THREAD_RETURN return_code); |
void exit_self(ThreadReturnType return_code); |
| |
// stack of functions to be called when thread terminates | // stack of functions to be called when thread terminates |
// will be called last in first out (LIFO) | // will be called last in first out (LIFO) |
|
|
catch(IPCException& e) { e = e; throw; } | catch(IPCException& e) { e = e; throw; } |
ntsd.release(); | ntsd.release(); |
} | } |
inline PEGASUS_THREAD_RETURN get_exit() { return _exit_code; } |
inline ThreadReturnType get_exit() { return _exit_code; } |
inline PEGASUS_THREAD_TYPE self() {return pegasus_thread_self(); } |
inline ThreadType self() {return Threads::self(); } |
| |
PEGASUS_THREAD_HANDLE getThreadHandle() {return _handle;} |
ThreadHandle getThreadHandle() {return _handle;} |
|
|
inline Boolean operator==(const void *key) const |
|
{ |
|
if ( (void *)this == key) |
|
return(true); |
|
return(false); |
|
} |
|
inline Boolean operator==(const Thread & b) const |
|
{ |
|
return(operator==((const void *)&b )); |
|
} |
|
| |
void detach(); | void detach(); |
| |
|
|
_tsd.insert_front(tsd.get()); | _tsd.insert_front(tsd.get()); |
tsd.release(); | tsd.release(); |
} | } |
PEGASUS_THREAD_HANDLE _handle; |
ThreadHandle _handle; |
Boolean _is_detached; | Boolean _is_detached; |
Boolean _cancel_enabled; | Boolean _cancel_enabled; |
Boolean _cancelled; | Boolean _cancelled; |
| |
PEGASUS_SEM_HANDLE _suspend_count; |
|
|
|
// always pass this * as the void * parameter to the thread | // always pass this * as the void * parameter to the thread |
// store the user parameter in _thread_parm | // store the user parameter in _thread_parm |
| |
PEGASUS_THREAD_RETURN ( PEGASUS_THREAD_CDECL *_start)(void *); |
ThreadReturnType ( PEGASUS_THREAD_CDECL *_start)(void *); |
List<cleanup_handler, RMutex> _cleanup; |
List<cleanup_handler, Mutex> _cleanup; |
List<thread_data, RMutex> _tsd; |
List<thread_data, Mutex> _tsd; |
| |
void *_thread_parm; | void *_thread_parm; |
PEGASUS_THREAD_RETURN _exit_code; |
ThreadReturnType _exit_code; |
static Boolean _signals_blocked; | static Boolean _signals_blocked; |
static PEGASUS_THREAD_KEY_TYPE _platform_thread_key; //l10n |
static TSDKeyType _platform_thread_key; //l10n |
static Boolean _key_initialized; // l10n | static Boolean _key_initialized; // l10n |
static Boolean _key_error; // l10n | static Boolean _key_error; // l10n |
}; | }; |
|
|
*/ | */ |
ThreadStatus allocate_and_awaken( | ThreadStatus allocate_and_awaken( |
void* parm, | void* parm, |
PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL* work)(void *), |
ThreadReturnType (PEGASUS_THREAD_CDECL* work)(void *), |
Semaphore* blocking = 0); | Semaphore* blocking = 0); |
| |
/** | /** |
|
|
| |
void get_key(Sint8* buf, int bufsize); | void get_key(Sint8* buf, int bufsize); |
| |
inline Boolean operator==(const char* key) const |
|
{ |
|
return (!strncmp(key, _key, 16)); |
|
} |
|
|
|
Boolean operator==(const void* p) const |
|
{ |
|
return ((void *)this == p); |
|
} |
|
|
|
Boolean operator==(const ThreadPool & p) const |
|
{ |
|
return operator==((const void *)&p); |
|
} |
|
|
|
inline void setMinThreads(Sint16 min) | inline void setMinThreads(Sint16 min) |
{ | { |
_minThreads = min; | _minThreads = min; |
|
|
ThreadPool(const ThreadPool&); // Unimplemented | ThreadPool(const ThreadPool&); // Unimplemented |
ThreadPool& operator=(const ThreadPool&); // Unimplemented | ThreadPool& operator=(const ThreadPool&); // Unimplemented |
| |
static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL _loop(void *); |
static ThreadReturnType PEGASUS_THREAD_CDECL _loop(void *); |
| |
static Boolean _timeIntervalExpired( | static Boolean _timeIntervalExpired( |
struct timeval* start, | struct timeval* start, |
|
|
AtomicInt _currentThreads; | AtomicInt _currentThreads; |
struct timeval _deallocateWait; | struct timeval _deallocateWait; |
char _key[17]; | char _key[17]; |
List<Thread, RMutex> _idleThreads; |
List<Thread, Mutex> _idleThreads; |
List<Thread, RMutex> _runningThreads; |
List<Thread, Mutex> _runningThreads; |
AtomicInt _dying; | AtomicInt _dying; |
}; | }; |
| |