Sturk 1.0.2
Publish-subscribe C implementation.
Loading...
Searching...
No Matches
mutex.h File Reference

Mutex. More...

#include "st/bits.h"
#include <stdbool.h>
Include dependency graph for mutex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ST_MUTEX_BF(attr, opt)   ST_BITFIELD(ST_MUTEX_##attr##_MASK, (opt))
 Create a bitfield for the mutex attribute option.
 
#define ST_MUTEX_POLICY_MASK   ST_BITMASK(2, 0)
 mutex policy setting bits.
 
#define ST_MUTEX_TYPE_MASK   ST_BITMASK(6, 3)
 mutex type setting bits.
 
#define ST_MUTEX_UNUSED_MASK   ST_BITMASK(31, 7)
 mutex settings unused bits.
 
#define ST_MUTEX_POLICY_NONE   ST_MUTEX_BF(POLICY, 0)
 mutex policy none.
 
#define ST_MUTEX_POLICY_PRIO_INHERIT   ST_MUTEX_BF(POLICY, 1)
 mutex policy priority inherit.
 
#define ST_MUTEX_POLICY_DELIM   ST_MUTEX_BF(POLICY, 8)
 mutex policy deliminator.
 
#define ST_MUTEX_TYPE_NONE   ST_MUTEX_BF(TYPE, 0)
 mutex type none.
 
#define ST_MUTEX_TYPE_RECURSIVE   ST_MUTEX_BF(TYPE, 1)
 mutex type recursive.
 
#define ST_MUTEX_TYPE_DELIM   ST_MUTEX_BF(TYPE, 16)
 mutex type deliminator.
 

Typedefs

typedef struct StMutex StMutex
 Mutex.
 

Functions

StMutexst_mutex_create (StBits args)
 Create a mutex.
 
void st_mutex_destroy (StMutex *mutex)
 Destroy a mutex.
 
void st_mutex_lock (StMutex *mutex)
 Block the calling thread until the mutex is unlocked.
 
bool st_mutex_trylock (StMutex *mutex)
 Lock the mutex if it is not locked.
 
void st_mutex_unlock (StMutex *mutex)
 Unlock a mutex.
 

Detailed Description

Mutex.

Macro Definition Documentation

◆ ST_MUTEX_BF

#define ST_MUTEX_BF (   attr,
  opt 
)    ST_BITFIELD(ST_MUTEX_##attr##_MASK, (opt))

Create a bitfield for the mutex attribute option.

Parameters
[in]attrThe attribute: POLICY or TYPE.
[in]optThe unique integer identifier for the option.
Returns
The bitfield.

Function Documentation

◆ st_mutex_create()

StMutex * st_mutex_create ( StBits  args)

Create a mutex.

Parameters
[in]argsThe configuration arguments.

Create a recursive mutex with a priority inherit policy.

StMutex * st_mutex_create(StBits args)
Create a mutex.
#define ST_MUTEX_TYPE_RECURSIVE
mutex type recursive.
Definition mutex.h:66
#define ST_MUTEX_POLICY_PRIO_INHERIT
mutex policy priority inherit.
Definition mutex.h:62
Returns
The new mutex.

◆ st_mutex_destroy()

void st_mutex_destroy ( StMutex mutex)

Destroy a mutex.

Parameters
[in,out]mutexThe mutex.

◆ st_mutex_lock()

void st_mutex_lock ( StMutex mutex)

Block the calling thread until the mutex is unlocked.

Lock the mutex.

Parameters
[in,out]mutexThe mutex.

◆ st_mutex_trylock()

bool st_mutex_trylock ( StMutex mutex)

Lock the mutex if it is not locked.

Do not block the calling thread.

Parameters
[in,out]mutexThe mutex.
Returns
True, if the mutex has been successfully locked.

◆ st_mutex_unlock()

bool st_mutex_unlock ( StMutex mutex)

Unlock a mutex.

Parameters
[in,out]mutexThe mutex.