INOS
CINOSMutex Class Reference

Public Types

enum  EFlags { eFlgNone = 0x00000000 , eFlgClassic = 0x00000001 , eFlgReclaimLock = 0x00000002 }
 

Public Member Functions

 CINOSMutex (EFlags aeFlags)
 Create a mutex with the given name.
 
 CINOSMutex (const char *apName=0, EFlags aeFlags=eFlgNone)
 Create a mutex with the given name.
 
 ~CINOSMutex ()
 Destroy mutex. It is not allowed to destroy a mutex with still waiting tasks. This ends up in an assertion.
 
ICACHE uint32 Request (uint32 aTimeout=INOS_WAIT_FOREVER)
 
ICACHE void lock ()
 
bool TryRequest ()
 
bool try_lock ()
 
ICACHE void Release (bool aSuspend=false, uint32 auState=defINOSTaskPureSuspended)
 
ICACHE void unlock ()
 
ICACHE class CINOSTaskGetOwner ()
 Return id of mutex owner.
 
const charGetName ()
 Return mutex name.
 
volatile uint32 * GetLockAdr ()
 Return pointer to core locking structure.
 
void SetFlag (EFlags aeFlag)
 sets the given mutex flag.
 
void ClrFlag (EFlags aeFlag)
 clears the given mutex flag.
 

Static Public Member Functions

static void RequestBoth (CINOSMutex &aMutex1, CINOSMutex &aMutex2)
 

Protected Member Functions

 DECLARE_DYNAMIC (CINOSMutex)
 
 DECLARE_DYNAMIC_PLACEMENT (CINOSMutex)
 

Protected Attributes

const charm_pName
 name of mutex
 
tTaskId m_idOwner
 owner of mutex (0->free)
 
tTaskId m_idFstWaiting
 id of first task waiting for the mutex
 
tTaskId m_idLstWaiting
 id of last task waiting for the mutex
 
uint32 m_uCounter
 number of times the owner 'owns' the mutex
 
SINOSCoreLock m_Lock
 core lock
 
uint32 m_uFlags
 mutex flags
 

Friends

class CINOSTask
 

Constructor & Destructor Documentation

◆ CINOSMutex() [1/2]

CINOSMutex::CINOSMutex ( EFlags  aeFlags)
explicit

Create a mutex with the given name.

Parameters
aeFlagsDefines whether to use a standard or classic mutex. Classic mutexes didn't support a recursive behaviour and should bot be used anymore.

◆ CINOSMutex() [2/2]

CINOSMutex::CINOSMutex ( const char apName = 0,
EFlags  aeFlags = eFlgNone 
)

Create a mutex with the given name.

Parameters
apNameName of mutex
aeFlagsDefines whether to use a standard or classic mutex. Classic mutexes didn't support a recursive behaviour and should not be used anymore.

Member Function Documentation

◆ lock()

ICACHE void CINOSMutex::lock ( )
inline

To make this class compatible with C++11's unique_lock, used by 'condition variables'.

◆ Release()

ICACHE void CINOSMutex::Release ( bool  aSuspend = false,
uint32  auState = defINOSTaskPureSuspended 
)

Releases a previously requested mutex (and suspend task atomically). Note that it is a failure to release a mutex which has not been requested before. In that sense, a calling task should call Release as many times as it successfully called Request. On the other side, it is not allowed to call Release if a previous call to Request failed.

Parameters
aSuspendTrue if atomic suspend requested

◆ Request()

ICACHE uint32 CINOSMutex::Request ( uint32  aTimeout = INOS_WAIT_FOREVER)

Request mutex. By default, the same task may call this function multiple times (recursive mutex). This behavior can be changed at object construction time (see aeFlags).

Parameters
aTimeoutMust be either INOS_WAIT_FOREVER or INOS_NO_WAIT
Returns
1 if requesting the mutex succeeded, 0 otherwise. The value 0 may only occur if INOS_NO_WAIT was passed.

◆ try_lock()

bool CINOSMutex::try_lock ( )
inline

To make this class compatible with C++11's unique_lock, used by 'condition variables'.

◆ TryRequest()

bool CINOSMutex::TryRequest ( )

Tries to request the mutex without blocking. IOW: If the mutex is not yet locked, the caller causes the mutex to be locked afterwards. If the mutex is already locked, the caller will not get the mutex, but it won't be blocked either.

Returns
true if the caller got the mutex, false otherwise.

◆ unlock()

ICACHE void CINOSMutex::unlock ( )
inline

To make this class compatible with C++11's unique_lock, used by 'condition variables'.


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