Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


High performance lock ? MutexGet MutexPut

Posted by Engin AYDOGAN on July 17, 2009
Hello there!

For Cortex-M3 port, I wonder if the mutex implementation in the grlib will make any use. Because it performs a lock without masking out the interrupts and could perform better ?

What do you think ?

Below is the code for MutexGet and MutexPut for your convenience (taken from widget.c of grlib of Luminary);

unsigned long __attribute__((naked))
WidgetMutexGet(unsigned char *pcMutex)
unsigned long ulRet;

// Acquire the mutex if possible.
__asm(" mov r1, #1\n"
" ldrexb r2, [r0]\n"
" cmp r2, #0\n"
" it eq\n"
" strexbeq r2, r1, [r0]\n"
" mov r0, r2\n"
" bx lr\n"
: "=r" (ulRet));

// The return is handled in the inline assembly, but the compiler will
// still complain if there is not an explicit return here (despite the fact
// that this does not result in any code being produced because of the
// naked attribute).

WidgetMutexPut(unsigned char *pcMutex)
// Release the mutex.
*pcMutex = 0;

Kind regards,


RE: High performance lock ? MutexGet MutexPut

Posted by Richard on July 17, 2009
Most semi complex architectures have instructions that can be used to implement mutexes, and indeed you could optimise individual ports this way. The mutex code as it stands is in the common code and not in the portable layer, so it would require some major changes and a support nightmare. Also, the mutex structures contain all the event control information, so tasks can block and be unblocked as semaphores are taken and given - all in strict priority order.


RE: High performance lock ? MutexGet MutexPut

Posted by Engin AYDOGAN on July 17, 2009
Hmm, so FreeRTOS is currently designed in a way that it cannot itself take advantage of this. i.e. it has [Enter|Exit]CriticalSection in portable layer and uses that as locks.

Besides it wouldn't support priority levels.

Even though it is not appropriate for FreeRTOS as of today, is it suitable for simple usage in user programs ? i.e. it wouldn't break anything and it would function as expected, right ?

Kind regards,


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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner