Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




xSemaphoreCreateRecursiveMutexStatic
[Semaphores]

semphr. h
SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic(
                              StaticSemaphore_t *pxMutexBuffer )
Creates a recursive mutex, and returns a handle by which the mutex can be referenced. Recursive mutexes cannot be used in interrupt service routines. configUSE_RECURSIVE_MUTEXES and configSUPPORT_STATIC_ALLOCATION must both be set to 1 in FreeRTOSConfig.h for xSemaphoreCreateRecursiveMutexStatic() to be available.

Each recursive mutex require a small amount of RAM that is used to hold the recursive mutex's state. If a mutex is created using xSemaphoreCreateRecursiveMutex() then the required RAM is automatically allocated from the FreeRTOS heap. If a recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic() then the RAM is provided by the application writer, which requires an additional parameter, but allows the RAM to be statically allocated at compile time. See the Static Vs Dynamic allocation page for more information.

Recursive mutexes are 'taken' (obtained) using the xSemaphoreTakeRecursive() and given (released) using the xSemaphoreGiveRecursive() API functions respectively. xSemaphoreTake() and xSemaphoreGive() must not be used.

Non-recursive mutexes are created using xSemaphoreCreateMutex() and xSemaphoreCreateMutexStatic(). A non-recursive mutex can only be 'taken' by a task once. Any attempt by a task to take a non-recursive mutex that it already holds will fail - and the mutex will always be given back the first time the task 'gives' the mutex.

Contrary to non-recursive mutexes, a task can 'take' a recursive mutex multiple times, and the recursive mutex will only be returned after the holding task has 'given' the mutex the same number of times it 'took' the mutex.

Like non-recursive mutexes, recursive mutexes implement a priority inheritance algorithm. The priority of a task that 'takes' a mutex will be temporarily raised if another task of higher priority attempts to obtain the same mutex. The task that owns the mutex 'inherits' the priority of the task attempting to 'take' the same mutex. This means the mutex must always be 'given' back - otherwise the higher priority task will never be able to obtain the mutex, and the lower priority task will never 'disinherit' the priority.

Parameters:
pxMutexBuffer   Must point to a variable of type StaticSemaphore_t, which will be used to hold the mutex type semaphore's state.
Return:
If the recursive mutex was created successfully then a handle to the created mutex is returned. If the recursive mutex was not created because pxMutexBuffer was NULL then NULL is returned.

Example usage:

 SemaphoreHandle_t xSemaphore = NULL;
 StaticSemaphore_t xMutexBuffer;

 void vATask( void * pvParameters )
 {
    /* Create a recursivemutex semaphore without using any dynamic
    memory allocation.  The mutex's data structures will be saved into
    the xMutexBuffer variable. */
    xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );

    /* The pxMutexBuffer was not NULL, so it is expected that the
    handle will not be NULL. */
    configASSERT( xSemaphore );

    /* Rest of the task code goes here. */
 }





[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists