"L. Spiro Engine"
|
00001 00016 #ifndef __LSH_THREADLIB_H__ 00017 #define __LSH_THREADLIB_H__ 00018 00019 // Include the standard library. 00020 #include "LSSTDStandardLib.h" 00021 using namespace ::lsstd; 00022 00023 #if defined( LSE_WINDOWS ) 00024 // Get threading routines on Windows. 00025 #include "Windows/LSSTDWindows.h" 00026 #define LSH_CALL WINAPI 00027 #elif defined( LSE_MAC ) 00028 // Apple/Macintosh OS X. 00029 #include <pthread.h> 00030 00031 #define LSH_CALL 00032 #elif defined( __linux__ ) 00033 // Linux. 00034 #define LSH_LIN 00035 #endif // #if defined( LSE_WINDOWS ) 00036 00037 00038 namespace lsh { 00039 00040 // The handle to a thread. 00041 #ifdef LSE_WINDOWS 00042 typedef HANDLE LSH_THREAD; 00043 #elif defined( LSE_MAC ) 00044 typedef pthread_t LSH_THREAD; 00045 #else 00046 #error "Threading not supported on this platform yet." 00047 #endif // #ifdef LSE_WINDOWS 00048 00049 typedef LSUINT32 (LSH_CALL * LSH_THREAD_PROC)( LSVOID * _lpParameter ); 00050 00057 class CThreadLib { 00058 public : 00059 // == Functions. 00068 static LSBOOL LSE_CALL CreateThread( LSH_THREAD_PROC _pfProc, LSVOID * _lpParameter, LSH_THREAD * _ptReturnHandle ); 00069 00076 static LSBOOL LSE_CALL CloseThread( LSH_THREAD &_tReturnHandle ); 00077 00086 static LSBOOL LSE_CALL WaitForThread( const LSH_THREAD &_tThread, LSUINT32 * _pui32RetVal ); 00087 00093 static LSH_THREAD LSE_CALL GetCurThread(); 00094 00100 static LSE_INLINE LSVOID LSE_CALL MakeInvalidHandle( LSH_THREAD &_tHandle ); 00101 00108 static LSE_INLINE LSBOOL LSE_CALL ThreadHandleIsValid( const LSH_THREAD &_tHandle ); 00109 }; 00110 00111 00112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00113 // DEFINITIONS 00114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00115 // == Functions. 00121 LSE_INLINE LSVOID LSE_CALL CThreadLib::MakeInvalidHandle( LSH_THREAD &_tHandle ) { 00122 CStd::MemSet( &_tHandle, 0, sizeof( LSH_THREAD ) ); 00123 } 00124 00131 LSE_INLINE LSBOOL LSE_CALL CThreadLib::ThreadHandleIsValid( const LSH_THREAD &_tHandle ) { 00132 static const LSUINT8 ui8Invalid[sizeof( LSH_THREAD )] = { 0 }; 00133 return !CStd::MemCmpF( &_tHandle, ui8Invalid, sizeof( LSH_THREAD ) ); 00134 } 00135 00136 } // namespace lsh 00137 00138 #endif // __LSH_THREADLIB_H__