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

#include <cThreadLock.h>

Inheritance diagram for Gray::cThreadLockMutex:
Gray::cThreadLockBase Gray::cLockableBase Gray::cNonCopyable

Public Member Functions

 cThreadLockMutex (const cThreadLockMutex &a) noexcept
 
 cThreadLockMutex (const FILECHAR_t *pszMutexName=nullptr, bool bInitialOwner=false) noexcept
 
 ~cThreadLockMutex () noexcept
 
bool Lock ()
 
bool Unlock ()
 
bool LockTry (TIMESYSD_t dwDelayMS=0)
 
- Public Member Functions inherited from Gray::cThreadLockBase
 cThreadLockBase () noexcept
 
bool isLocked () const noexcept
 
THREADID_t get_ThreadLockOwner () const
 
bool isThreadLockedByCurrent () const noexcept
 

Public Attributes

pthread_mutex_t m_Mutex
 

Static Public Attributes

static const pthread_mutex_t k_MutexInit
 

Protected Member Functions

void InitLockMutex (const FILECHAR_t *pszMutexName, bool bInitialOwner) noexcept
 
void LockInternal ()
 
- Protected Member Functions inherited from Gray::cThreadLockBase
THREADID_t __DECL_ALIGN (_SIZEOF_THREADID) m_nLockThreadID
 The thread that has the lock. cThreadId:k_NULL is not locked. More...
 
- Protected Member Functions inherited from Gray::cLockableBase
 cLockableBase () noexcept
 
 ~cLockableBase ()
 
LONG get_LockCount () const
 
bool isLocked () const
 
void IncLockCount ()
 
LONG DecLockCount ()
 
void Lock ()
 
LONG Unlock ()
 
- Protected Member Functions inherited from Gray::cNonCopyable
 cNonCopyable () noexcept
 Force the use of Factory creation via protected constructor. More...
 
 ~cNonCopyable () noexcept
 

Protected Attributes

bool m_bInitialOwner
 I also lock this myself. More...
 

Detailed Description

Base class for data structure that may be locked for multi threaded/process access. These are expensive size wise but fast. lock something and wait for it to be freed.

Note
reentrant, multi locks on a single thread are allowed and counted. fast collision resolution. Mutex = 1 bathroom door 1 lock. Semaphore = a set of X keys to X bathrooms. m_nLockThreadID = API wont tell me if it is locked. i have to track this myself.
I've seen use of this in Windows Service on W10 cause app exit !? 2015

Constructor & Destructor Documentation

◆ cThreadLockMutex() [1/2]

Gray::cThreadLockMutex::cThreadLockMutex ( const cThreadLockMutex a)
inlinenoexcept

Copy constructor should never actually be used. but if it is just make a new copy that is not locked! DUMMY = pretend we copied stuff.

◆ cThreadLockMutex() [2/2]

Gray::cThreadLockMutex::cThreadLockMutex ( const FILECHAR_t pszMutexName = nullptr,
bool  bInitialOwner = false 
)
inlinenoexcept

◆ ~cThreadLockMutex()

Gray::cThreadLockMutex::~cThreadLockMutex ( )
inlinenoexcept

Member Function Documentation

◆ InitLockMutex()

void Gray::cThreadLockMutex::InitLockMutex ( const FILECHAR_t pszMutexName,
bool  bInitialOwner 
)
inlineprotectednoexcept

Create a system mutex.

  • bInitialOwner = owned by the thread that created this.

◆ Lock()

bool Gray::cThreadLockMutex::Lock ( )
inline

code to lock a thread. This will wait forever for the resource to be free !

Note
It should NOT wait if it is in the same thread.

◆ LockInternal()

void Gray::cThreadLockMutex::LockInternal ( )
inlineprotected

i was able to acquire this Mutex. some other way like WaitForMultipleObjects() ?

◆ LockTry()

bool Gray::cThreadLockMutex::LockTry ( TIMESYSD_t  dwDelayMS = 0)
inline

Try to lock the mutex. give up after a certain amount of time if it is locked by another thread. dwDelayMS = amount of time to wait. 0 = don't wait

◆ Unlock()

bool Gray::cThreadLockMutex::Unlock ( )
inline

Member Data Documentation

◆ k_MutexInit

const pthread_mutex_t Gray::cThreadLockMutex::k_MutexInit
static

◆ m_bInitialOwner

bool Gray::cThreadLockMutex::m_bInitialOwner
protected

I also lock this myself.

◆ m_Mutex

pthread_mutex_t Gray::cThreadLockMutex::m_Mutex

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