le_mutex.h File Reference

Go to the source code of this file.

Macros

#define LE_MUTEX_DECLARE_REF(refName)
 

Typedefs

typedef struct le_mutex * le_mutex_Ref_t
 

Functions

le_mutex_Ref_t le_mutex_CreateRecursive (const char *nameStr)
 
le_mutex_Ref_t le_mutex_CreateNonRecursive (const char *nameStr)
 
void le_mutex_Delete (le_mutex_Ref_t mutexRef)
 
void le_mutex_Lock (le_mutex_Ref_t mutexRef)
 
le_result_t le_mutex_TryLock (le_mutex_Ref_t mutexRef)
 
void le_mutex_Unlock (le_mutex_Ref_t mutexRef)
 

Detailed Description

Legato Mutex API include file.

Macro Definition Documentation

◆ LE_MUTEX_DECLARE_REF

#define LE_MUTEX_DECLARE_REF (   refName)
Value:
static le_mutex_Ref_t refName; \
static inline void Lock(void) { le_mutex_Lock(refName); } \
static inline void Unlock(void) { le_mutex_Unlock(refName); }
struct le_mutex * le_mutex_Ref_t
Definition: le_mutex.h:96
void le_mutex_Lock(le_mutex_Ref_t mutexRef)
void le_mutex_Unlock(le_mutex_Ref_t mutexRef)

Declare a static mutex reference variable and accessor functions.

This is handy when you need a single, file-scope mutex for use inside your module to protect other file-scope data structures from multi-threaded race conditions.

Adding the line

near the top of your file will create a file-scope variable called "MyMutexRef" of type le_mutex_Ref_t and functions called "Lock" and "Unlock" that access that variable.

See c_mutex_locking_tips for more information.

Parameters
refNameName of the mutex reference variable.
Returns
Nothing.

Typedef Documentation

◆ le_mutex_Ref_t

typedef struct le_mutex* le_mutex_Ref_t

Reference to a Mutex object.

Function Documentation

◆ le_mutex_CreateNonRecursive()

le_mutex_Ref_t le_mutex_CreateNonRecursive ( const char *  nameStr)

Create a Non-Recursive mutex.

Parameters
[in]nameStrName of the mutex
Returns
Returns a reference to the mutex.
Note
Terminates the process on failure, no need to check the return value for errors.

◆ le_mutex_CreateRecursive()

le_mutex_Ref_t le_mutex_CreateRecursive ( const char *  nameStr)

Create a Recursive mutex.

Parameters
[in]nameStrName of the mutex
Returns
Returns a reference to the mutex.
Note
Terminates the process on failure, no need to check the return value for errors.

◆ le_mutex_Delete()

void le_mutex_Delete ( le_mutex_Ref_t  mutexRef)

Delete a mutex.

Returns
Nothing.
Parameters
[in]mutexRefMutex reference

◆ le_mutex_Lock()

void le_mutex_Lock ( le_mutex_Ref_t  mutexRef)

Lock a mutex.

Returns
Nothing.
Parameters
[in]mutexRefMutex reference

◆ le_mutex_TryLock()

le_result_t le_mutex_TryLock ( le_mutex_Ref_t  mutexRef)

Try a lock on a mutex.

Locks a mutex, if no other thread holds it. Otherwise, returns without locking.

Returns
  • LE_OK if mutex was locked.
  • LE_WOULD_BLOCK if mutex was already held by someone else.
Parameters
[in]mutexRefMutex reference

◆ le_mutex_Unlock()

void le_mutex_Unlock ( le_mutex_Ref_t  mutexRef)

Unlock a mutex.

Returns
Nothing.
Parameters
[in]mutexRefMutex reference