Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Synchronization.h

Go to the documentation of this file.
00001 #ifdef LINUX
00002 #include <pthread.h>
00003 #endif
00004 
00005 #ifndef THREAD_H
00006 namespace rwil {
00008 
00014   class Mutex
00015     {
00016     public:
00018 
00021       Mutex();
00023 
00026       ~Mutex();
00027 
00029 
00033       void Wait();
00035 
00039       bool TryWait();
00041 
00045       void Release();
00046 
00047     private:
00048 #ifdef _WIN32
00049 
00050       HANDLE m_mutex;
00051 #endif
00052 #ifdef LINUX
00053 
00054       pthread_mutex_t m_mutex;
00055 #endif
00056     };
00057 
00059 
00063   class ScopedMutex
00064     {
00065     public:
00067 
00071       ScopedMutex(Mutex & mutex);
00073 
00076       ~ScopedMutex();
00077     private:
00079       Mutex &m_mutex;
00080     };
00081 
00083 
00087   class CriticalSection
00088     {
00089     public:
00091       CriticalSection() { m_mutex.Wait(); }
00093       ~CriticalSection() { m_mutex.Release(); }
00094     private:
00096       Mutex m_mutex;
00097     };
00098 
00100 
00103   class Semaphore
00104     {
00105     public:
00107 
00111       Semaphore(int count);
00113 
00117       Semaphore();
00118 
00120       //  They then decrement the count
00122 
00126       void Wait();
00128 
00133       bool TryWait();
00135 
00142       bool Wait(int millisecondTimeout);
00144 
00148       void Signal();
00149     private:
00151       Mutex m_mutex;
00153       int m_count;
00154     };
00155 
00157 
00160   class Thread
00161     {
00162     public:
00164 
00167       Thread();
00169 
00172       virtual ~Thread();
00174 
00178       void Start();
00180 
00183       void Go();
00185 
00188       void Join();
00189     protected:
00191 
00194       void Yield();
00196 
00199       virtual void Function() = 0;
00201       Mutex m_mutex;
00202 #ifdef _WIN32
00203 
00204       HANDLE m_threadHandle
00205 #endif
00206 #ifdef LINUX
00207 
00208         pthread_t m_threadHandle;
00209 #endif
00210     };
00211 }
00212 #define THREAD_H
00213 #endif
00214 

Generated on Tue Apr 9 13:53:08 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001