Mutex

group group_abstraction_rtos_mutex

APIs for acquiring and working with Mutexes.

Unnamed Group

cy_rtos_init_mutex(mutex)

Create a recursive mutex.

Creates a binary mutex which can be used to synchronize between threads and between threads and ISRs. Created mutexes are recursive and support priority inheritance.

This function has been replaced by cy_rtos_init_mutex2 which allow for specifying whether or not the mutex supports recursion or not.

Return

The status of mutex creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

Parameters
  • [out] mutex: Pointer to the mutex handle to be initialized

cy_rslt_t cy_rtos_init_mutex2(cy_mutex_t *mutex, bool recursive)

Create a mutex which can support recursion or not.

Creates a binary mutex which can be used to synchronize between threads and between threads and ISRs. Created mutexes can support priority inheritance if recursive.

note

Not all RTOS implementations support non-recursive mutexes. In this case a recursive mutex will be created.

Return

The status of mutex creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

Parameters
  • [out] mutex: Pointer to the mutex handle to be initialized

  • [in] recursive: Should the created mutex support recursion or not

cy_rslt_t cy_rtos_get_mutex(cy_mutex_t *mutex, cy_time_t timeout_ms)

Get a mutex.

If the mutex is available, it is acquired and this function returned. If the mutex is not available, the thread waits until the mutex is available or until the timeout occurs.

note

This function must not be called from an interrupt context as it may block.

Return

The status of the get mutex. Returns timeout if mutex was not acquired before timeout_ms period. [CY_RSLT_SUCCESS, CY_RTOS_TIMEOUT, CY_RTOS_GENERAL_ERROR]

Parameters
  • [in] mutex: Pointer to the mutex handle

  • [in] timeout_ms: Maximum number of milliseconds to wait while attempting to get the mutex. Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever. Must be zero if in_isr is true.

cy_rslt_t cy_rtos_set_mutex(cy_mutex_t *mutex)

Set a mutex.

The mutex is released allowing any other threads waiting on the mutex to obtain the semaphore.

Return

The status of the set mutex request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

Parameters
  • [in] mutex: Pointer to the mutex handle

cy_rslt_t cy_rtos_deinit_mutex(cy_mutex_t *mutex)

Deletes a mutex.

This function frees the resources associated with a sempahore.

Return

The status to the delete request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

Parameters
  • [in] mutex: Pointer to the mutex handle