CSemaphore Class Reference

#include <RioSemaphore.h>

Public Member Functions

 CSemaphore (int InitialValue, int MaxValue)
virtual ~CSemaphore ()
bool IsOpen ()
void P ()
void V ()

Private Attributes

sem_t m_Semaphore
bool m_isopen

Detailed Description

Definition at line 32 of file RioSemaphore.h.


Constructor & Destructor Documentation

CSemaphore::CSemaphore ( int  InitialValue,
int  MaxValue 
)

Definition at line 49 of file RioSemaphore.cpp.

00050 {
00051 #ifdef WINDOWS
00052   // WINDOWS32 implementation
00053   m_handle = CreateSemaphore(NULL,InitialValue,MaxValue,NULL);
00054   if(m_handle == INVALID_HANDLE_VALUE)
00055   {
00056     m_isopen = false;
00057   }
00058   else
00059   {
00060     m_isopen = true;
00061   }
00062 #else
00063   // UNIX implementation
00064   int result = sem_init(&m_Semaphore,0,InitialValue);
00065   if(result == 0)
00066   {
00067     m_isopen = true;
00068   }
00069   else
00070   {
00071     m_isopen = false;
00072   }
00073 #endif
00074 
00075 }

CSemaphore::~CSemaphore (  )  [virtual]

Definition at line 77 of file RioSemaphore.cpp.

00078 {
00079   if(m_isopen)
00080   {
00081 #ifdef WINDOWS
00082     // WINDOWS32 implementation
00083     CloseHandle (m_handle);
00084         m_isopen = false;
00085 #else
00086   // UNIX implementation
00087         sem_destroy(&m_Semaphore);
00088         m_isopen = false;
00089 #endif
00090   }
00091 }


Member Function Documentation

bool CSemaphore::IsOpen (  ) 

Definition at line 93 of file RioSemaphore.cpp.

00094 {
00095   return m_isopen;
00096 }

void CSemaphore::P (  ) 

Definition at line 99 of file RioSemaphore.cpp.

00100 {
00101 
00102 #ifdef WINDOWS
00103   // WINDOWS32 implementation
00104   WaitForSingleObject(m_handle,INFINITE);
00105 #else
00106   // UNIX implementation
00107   sem_wait(&m_Semaphore);
00108 #endif
00109 }

void CSemaphore::V (  ) 

Definition at line 111 of file RioSemaphore.cpp.

00112 {
00113 #ifdef WINDOWS
00114   // WINDOWS32 implementation
00115   ReleaseSemaphore(m_handle,1,NULL);
00116 #else
00117   // UNIX implementation
00118   sem_post(&m_Semaphore);
00119 #endif
00120 }


Field Documentation

bool CSemaphore::m_isopen [private]

Definition at line 42 of file RioSemaphore.h.

sem_t CSemaphore::m_Semaphore [private]

Definition at line 40 of file RioSemaphore.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:33 2012 for RIO by  doxygen 1.6.3