Quality RTOS & Embedded Software

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




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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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