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




Loading

receiving efficiently messages from queues

Posted by bodev on October 27, 2008
Hi all,
in many FreeRTOS examples, i have seen code like this:

while( xQueueReceive( queue, &mess, portMAX_DELAY ) != pdPASS );

i was wondering if this is efficient in the sense that it blocks the thread until a message is posted
or this instruction implies a true active polling and hence consumes CPU time.

is there any efficient way to do this?

the obvious solution that come to mind is to use a binarysemaphore to signal that a message has been posted,
so the receiving thread can stop on the sempahore and only when woken up receive the message.

comments?
any other solution?

Regards,
BoDev

RE: receiving efficiently messages from queues

Posted by Richard on October 27, 2008
> while( xQueueReceive( queue, &mess, portMAX_DELAY ) != pdPASS );

This code is truely blocking - not polling.

xQueueReceive() is in a while loop to deal with the case where the block time expires, but no data has been received.

Taking the two extremes:

Depending on your configuration (see the configuration section of the WEB docs), portMAX_DELAY may block indefinitely, in which case xQueueReceive() will only return when it has successfully received some data. In this case the while() loop has no effect as xQueueReceive() will only ever return pdPASS.

If you have not configured your system to allow indefinite blocking, and you are using 16bit ticks, then portMAX_DELAY will expire every 0xffff ticks, so it xQueueReceive() could well return pdFALSE, depending on how often data is written to the queue. [most systems would use 32bit ticks].

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