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


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 ]    [ 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