Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

GSemaphore.h

00001 #ifndef __GSEMAPHORE_H
00002 #define __GSEMAPHORE_H
00003 
00004 // Thread Type and Functions
00005 #if defined WIN32
00006 
00007     typedef DWORD                       OsThreadId;
00008     typedef HANDLE                      OsSemaphore;
00009     #define LgiGetCurrentThread()       GetCurrentThreadId()
00010 
00011 #elif defined BEOS
00012 
00013     typedef thread_id                   OsThreadId;
00014     typedef sem_id                      OsSemaphore;
00015     #define LgiGetCurrentThread()       find_thread(0)
00016 
00017 #elif defined LINUX
00018 
00019     typedef pthread_t                   OsThreadId;
00020     typedef pthread_mutex_t             OsSemaphore;
00021     #define LgiGetCurrentThread()       pthread_self()
00022 
00023 #else
00024 
00025     typedef int                         OsThreadId;
00026     typedef int                         OsSemaphore;
00027     #define LgiGetCurrentThread()       0
00028 
00029 #endif
00030 
00031 // Resource Locking Class
00032 class LgiClass GSemaphore
00033 {
00034     OsThreadId _Thread;
00035     OsSemaphore _Sem;
00036     bool _Lock();
00037     void _Unlock();
00038     char *_Name;
00039 
00040 protected:
00041     int _Count;
00042 
00043 public:
00044     GSemaphore(char *name = 0);
00045     virtual ~GSemaphore();
00046 
00047     bool Lock();
00048     bool LockWithTimeout(int Timeout /* in ms */);
00049     void Unlock();
00050 
00051     char *GetName();
00052     void SetName(char *s);
00053     
00054     #ifdef _DEBUG
00055     int GetCount() { return _Count; }
00056     #endif
00057 };
00058 
00059 #endif

Generated on Wed Oct 26 14:46:49 2005 for Lgi by  doxygen 1.4.1