Quality RTOS & Embedded Software

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


Loading

xQueueAddToSet/xQueueRemoveFromSet is it safe?

Posted by beginend1 on January 24, 2014

Is it safe to use xQueueAddToSet/xQueueRemoveFromSet? The check in those functions are made outside critical section, so there could be race condition. See note in code.

	if( ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )
	{
		/* Cannot add a queue/semaphore to more than one queue set. */
		xReturn = pdFAIL;
	}
	/* #### critical setion from here ? #### */
	else if( ( ( xQUEUE * ) xQueueOrSemaphore )->uxMessagesWaiting != ( unsigned portBASE_TYPE ) 0 )
	{
		/* Cannot add a queue/semaphore to a queue set if there are already
		items in the queue/semaphore. */
		xReturn = pdFAIL;
	}
	else
	{
		taskENTER_CRITICAL();
		{
			( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;
		}
		taskEXIT_CRITICAL();
		xReturn = pdPASS;
	}

	return xReturn;

xQueueAddToSet/xQueueRemoveFromSet is it safe?

Posted by rtel on January 24, 2014

I'm not sure why the decision was taken not to put a critical section around that line, as there is a critical section in the 'else' statement. No matter what the reason, as this is a very fast function that is generally only called during initialisation anyway, it would seem prudent to move the existing critical section to instead go around the entire if/else if/else statements. It has been done but not checked in yet.

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.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

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.


Careers

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

Renesas

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