Skip to content

File syn_mutex.c

FileList > sched > syn_mutex.c

Go to the source code of this file

Priority-inheriting recursive mutex implementation.

  • #include "../port/syn_port_system.h"
  • #include "../util/syn_assert.h"
  • #include "syn_mutex.h"
  • #include "syn_sched.h"

Public Functions

Type Name
SYN_Task * syn_mutex_get_owner (const SYN_Mutex * mutex)
Get the current owner of the mutex.
SYN_Status syn_mutex_init (SYN_Mutex * mutex)
Initialize a mutex in unlocked state.
bool syn_mutex_is_locked (const SYN_Mutex * mutex)
Check if the mutex is currently locked.
SYN_Status syn_mutex_try_lock (SYN_Mutex * mutex, SYN_Task * task)
Attempt to acquire the mutex without blocking.
SYN_Status syn_mutex_unlock (SYN_Mutex * mutex, SYN_Task * task)
Release a previously acquired mutex.

Public Functions Documentation

function syn_mutex_get_owner

Get the current owner of the mutex.

SYN_Task * syn_mutex_get_owner (
    const SYN_Mutex * mutex
) 

Parameters:

  • mutex Pointer to mutex structure.

Returns:

Pointer to owner task, or NULL if unlocked.


function syn_mutex_init

Initialize a mutex in unlocked state.

SYN_Status syn_mutex_init (
    SYN_Mutex * mutex
) 

Parameters:

  • mutex Pointer to mutex structure.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM if mutex is NULL.


function syn_mutex_is_locked

Check if the mutex is currently locked.

bool syn_mutex_is_locked (
    const SYN_Mutex * mutex
) 

Parameters:

  • mutex Pointer to mutex structure.

Returns:

true if locked, false otherwise.


function syn_mutex_try_lock

Attempt to acquire the mutex without blocking.

SYN_Status syn_mutex_try_lock (
    SYN_Mutex * mutex,
    SYN_Task * task
) 

If the mutex is already locked by another task and task has higher priority (numerically lower value) than the owner, the owner's priority is automatically boosted.

Parameters:

  • mutex Pointer to mutex structure.
  • task Pointer to acquiring task (optional, NULL for standalone lock).

Returns:

SYN_OK if acquired, SYN_BUSY if held by another task, or SYN_INVALID_PARAM.


function syn_mutex_unlock

Release a previously acquired mutex.

SYN_Status syn_mutex_unlock (
    SYN_Mutex * mutex,
    SYN_Task * task
) 

Decrements the recursion count. When the count reaches zero, the owner's priority is restored to its base priority and ownership is cleared.

Parameters:

  • mutex Pointer to mutex structure.
  • task Pointer to owner task releasing the lock.

Returns:

SYN_OK on success, SYN_ERROR if not locked or wrong owner, or SYN_INVALID_PARAM.



The documentation for this class was generated from the following file src/syntropic/sched/syn_mutex.c