(abstraction-rtos)
All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
Mutex

General Description

APIs for acquiring and working with Mutexes.

cy_rslt_t cy_rtos_mutex_init (cy_mutex_t *mutex, bool recursive)
 Create a mutex which can support recursion or not. More...
 
cy_rslt_t cy_rtos_mutex_get (cy_mutex_t *mutex, cy_time_t timeout_ms)
 Get a mutex. More...
 
cy_rslt_t cy_rtos_mutex_set (cy_mutex_t *mutex)
 Set a mutex. More...
 
cy_rslt_t cy_rtos_mutex_deinit (cy_mutex_t *mutex)
 Deletes a mutex. More...
 
#define cy_rtos_init_mutex2(mutex, recursive)    cy_rtos_mutex_init(mutex, recursive)
 Create a mutex which can support recursion or not. More...
 
#define cy_rtos_init_mutex(mutex)    cy_rtos_mutex_init(mutex, true)
 Create a mutex which can support recursion. More...
 
#define cy_rtos_get_mutex(mutex, timeout_ms)    cy_rtos_mutex_get(mutex, timeout_ms)
 Get a mutex. More...
 
#define cy_rtos_set_mutex(mutex)   cy_rtos_mutex_set(mutex)
 Set a mutex. More...
 
#define cy_rtos_deinit_mutex(mutex)   cy_rtos_mutex_deinit(mutex)
 Deletes a mutex. More...
 

Macro Definition Documentation

◆ cy_rtos_init_mutex2

#define cy_rtos_init_mutex2 (   mutex,
  recursive 
)     cy_rtos_mutex_init(mutex, recursive)

Create a mutex which can support recursion or not.

Creates a binary mutex which can be used for mutual exclusion to prevent simulatenous access of shared resources. 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.
Parameters
[out]mutexPointer to the mutex handle to be initialized
[in]recursiveShould the created mutex support recursion or not
Returns
The status of mutex creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_init_mutex

#define cy_rtos_init_mutex (   mutex)     cy_rtos_mutex_init(mutex, true)

Create a mutex which can support recursion.

Creates a binary mutex which can be used for mutual exclusion to prevent simulatenous access of shared resources. 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.
Parameters
[out]mutexPointer to the mutex handle to be initialized
Returns
The status of mutex creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_get_mutex

#define cy_rtos_get_mutex (   mutex,
  timeout_ms 
)     cy_rtos_mutex_get(mutex, 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.
Parameters
[in]mutexPointer to the mutex handle
[in]timeout_msMaximum number of milliseconds to wait while attempting to get the mutex. Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever.
Returns
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]

◆ cy_rtos_set_mutex

#define cy_rtos_set_mutex (   mutex)    cy_rtos_mutex_set(mutex)

Set a mutex.

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

Parameters
[in]mutexPointer to the mutex handle
Returns
The status of the set mutex request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_deinit_mutex

#define cy_rtos_deinit_mutex (   mutex)    cy_rtos_mutex_deinit(mutex)

Deletes a mutex.

This function frees the resources associated with a sempahore.

Parameters
[in]mutexPointer to the mutex handle
Returns
The status to the delete request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

Function Documentation

◆ cy_rtos_mutex_init()

cy_rslt_t cy_rtos_mutex_init ( cy_mutex_t mutex,
bool  recursive 
)

Create a mutex which can support recursion or not.

Creates a binary mutex which can be used for mutual exclusion to prevent simulatenous access of shared resources. 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.
Parameters
[out]mutexPointer to the mutex handle to be initialized
[in]recursiveShould the created mutex support recursion or not
Returns
The status of mutex creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_mutex_get()

cy_rslt_t cy_rtos_mutex_get ( 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.
Parameters
[in]mutexPointer to the mutex handle
[in]timeout_msMaximum number of milliseconds to wait while attempting to get the mutex. Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever.
Returns
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]

◆ cy_rtos_mutex_set()

cy_rslt_t cy_rtos_mutex_set ( cy_mutex_t mutex)

Set a mutex.

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

Parameters
[in]mutexPointer to the mutex handle
Returns
The status of the set mutex request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_mutex_deinit()

cy_rslt_t cy_rtos_mutex_deinit ( cy_mutex_t mutex)

Deletes a mutex.

This function frees the resources associated with a sempahore.

Parameters
[in]mutexPointer to the mutex handle
Returns
The status to the delete request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]