Chapter 2. API Reference
that the semaphore was not first obtained correctly.
Parameters
• xSemaphore: A handle to the semaphore being released. This is the handle returned when the
semaphore was created.
xSemaphoreGiveRecursive(xMutex)
Macro to recursively release, or 'give', a mutex type semaphore. The mutex must have previously been
created using a call to xSemaphoreCreateRecursiveMutex();
configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this macro to be available.
This macro must not be used on mutexes created using xSemaphoreCreateMutex().
A mutex used recursively can be 'taken'repeatedly by the owner. The mutex doesn't become available
again until the owner has called xSemaphoreGiveRecursive() for each successful'take' request. For example,
if a task successfully 'takes'the same mutex 5 times then the mutex will not be available to any other task
until it has also 'given'the mutex back exactly five times.
Example usage:
SemaphoreHandle_t xMutex
//
A task that creates a
void vATask( void
{
//
Create the mutex to guard a shared
xMutex
=
xSemaphoreCreateRecursiveMutex();
}
//
A task that uses the
void vAnotherTask( void
{
// ...
Do other
if( xMutex
!=
{
//
See
if
//
wait
10
if( xSemaphoreTakeRecursive( xMutex, ( TickType_t )
{
//
We were able to obtain the mutex
//
shared
// ...
//
For some reason due to the nature of the code further calls to
//
xSemaphoreTakeRecursive() are made on the same
//
code these would
//
no
//
a more
xSemaphoreTakeRecursive( xMutex, ( TickType_t )
xSemaphoreTakeRecursive( xMutex, ( TickType_t )
//
The mutex has now been
//
available to another task until it has also been given back
//
three
//
these calls sequentially, it would be more likely that the calls
//
to xSemaphoreGiveRecursive() would be called
// unwound.
xSemaphoreGiveRecursive( xMutex );
xSemaphoreGiveRecursive( xMutex );
xSemaphoreGiveRecursive( xMutex );
//
Now the mutex can be taken by other
}
Espressif Systems
=
NULL;
mutex.
*
pvParameters )
mutex.
*
pvParameters )
things.
NULL )
we can obtain the
mutex.
ticks to see
if
it becomes
resource.
not
be just sequential calls
sense.
Instead the calls are likely to be buried inside
complex
call
structure.
times.
Again it
This
is
just
Submit Document Feedback
resource.
If the mutex
is not
free.
and
can now access the
'taken'
three times, so will
is
unlikely that real code would have
for
demonstrative
purposes.
tasks.
906
available
10
)
==
pdTRUE )
mutex.
In real
as
this would make
10
);
10
);
not
be
as
a call stack
(continues on next page)
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers