Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cSemaphore Class Reference

#include <cSemaphore.h>

Public Member Functions

 cSemaphore (int iUnlockedCount, int iMaxCount, const FILECHAR_t *pszName=nullptr)
 
 ~cSemaphore ()
 
bool isValidSemaphore () const
 
bool LockWait (TIMESYSD_t tWait=cTimeSys::k_INF)
 
bool Unlock (LONG nReleaseCount=1, LONG *plPreviousCount=nullptr)
 

Public Attributes

sem_t m_sem
 Unnamed semaphore. More...
 
sem_t * m_pSem
 pthread semaphore. More...
 

Detailed Description

A semaphore allows X users of the locked resource. All others must wait. Allow interprocess naming of the semaphore resource. i.e. A mutex allows only one user. Semaphore(1) = mutex Mutex = 1 bathroom door 1 lock. Semaphore = a set of X keys to X bathrooms. like the MFC class cSemaphore http://www.cse.psu.edu/~dheller/cse411/notes/OSC/posix.html

Constructor & Destructor Documentation

◆ cSemaphore()

GrayLib::cSemaphore::cSemaphore ( int  iUnlockedCount,
int  iMaxCount,
const FILECHAR_t pszName = nullptr 
)
inline

Create a new semaphore.

  • iUnlockedCount = the number of signaled states to start <= iMaxCount. iUnlockedCount < 0 = just open an existing semaphore by pszName. don't create a new one.

◆ ~cSemaphore()

GrayLib::cSemaphore::~cSemaphore ( )
inline

Member Function Documentation

◆ isValidSemaphore()

bool GrayLib::cSemaphore::isValidSemaphore ( ) const
inline

◆ LockWait()

bool GrayLib::cSemaphore::LockWait ( TIMESYSD_t  tWait = cTimeSys::k_INF)
inline

Acquire a single lock. wait if i have to. Used by cSemaphoreLock

◆ Unlock()

bool GrayLib::cSemaphore::Unlock ( LONG  nReleaseCount = 1,
LONG *  plPreviousCount = nullptr 
)
inline

Release nReleaseCount locks on the semaphore.

Member Data Documentation

◆ m_pSem

sem_t* GrayLib::cSemaphore::m_pSem

pthread semaphore.

◆ m_sem

sem_t GrayLib::cSemaphore::m_sem

Unnamed semaphore.


The documentation for this class was generated from the following file: