FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [November 2015 Threads] Why vSemaphoreCreateBinary macro 'give' immediately after created the semaphore?Posted by rainbowsnow on November 30, 2015 I found the below definition in the source code of FreeRTOS v7.0.2.
I have known that vSemaphoreCreateBinary has been replaced by xSemaphoreCreateBinary now and won't 'give' the semaphore after created it, but I still want to know why vSemaphoreCreateBinary does this.
~~~~
define vSemaphoreCreateBinary( xSemaphore )
{ \
( xSemaphore ) = xQueueGenericCreate( ( unsigned portBASE_TYPE ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ); \
if( ( xSemaphore ) != NULL ) \
{ \
( void ) xSemaphoreGive( ( xSemaphore ) ); \
} \
}
~~~~
Thanks!
Why vSemaphoreCreateBinary macro 'give' immediately after created the semaphore?Posted by rtel on November 30, 2015 Probably because the [now defunct, as you point out] macro is very old, and dates back to a time before there was a separate mutex object - meaning binary semaphores were sometimes used as a mutexes. When a semaphore is used for mutual exclusion, you assume the resource being protected starts in the available state, so the mutex starts in the available state. Now there are separate binary semaphore and mutex objects, so when the very old semaphore macro was replaced by a function (so its semantics were consistent with the newer functions) it is created in the not available state - which is more logical when the semaphore is used for signalling. In more recent versions of FreeRTOS it is preferable to use direct to task notifications for signalling, as they are faster and use less RAM, so binary semaphores don't get much use in new applications.
Why vSemaphoreCreateBinary macro 'give' immediately after created the semaphore?Posted by rainbowsnow on December 2, 2015 Got it, thanks very much ^_^
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|