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] [January 2007 Threads] queue.c: *_interrupts vs. *_criticalPosted by Nobody/Anonymous on January 12, 2007 <<And yes, I'm using anonymous on purpose.>>
Looking at queue.c and trying to write my own counting semaphores (as an exercise and to contribute), I see the coroutine-specific portions calling portDISABLE_INTERRUPTS directly rather than using taskENTER_CRITICAL to count multiple depth. It would seem this could cause an error of enabling interrupts when the system is supposed to be in a nested critical section.
RE: queue.c: *_interrupts vs. *_criticalPosted by Richard on January 12, 2007 The coroutine versions don't nest interrupts. There is a very good reason for this, it just temporarily escapes me ;-)
There was in fact a bug fix about two versions ago where a co-routine called a utility function within an if() condition while interrupts were disabled. The utility function itself entered and exited a critical section - and in so doing resulted in interrupts being enabled when they should not have been for the very reason you point out. The utility macro was replaced with inlined code as the fix.
I think counting semaphores can be implemented in a similar way to the binary semaphores, just with a queue depth greater than 1 - which is where the 'binary' comes from.
Regards.
RE: queue.c: *_interrupts vs. *_criticalPosted by HAR on January 12, 2007 Maybe, but the queue implementation would try to allocate actual queue space which would be a waste. And it doesn't need to be as complicated, either - posting a semaphore should always work unlike adding to a queue.
RE: queue.c: *_interrupts vs. *_criticalPosted by Nobody/Anonymous on January 12, 2007 The binary semaphore has an item size of 0 so nothing is actually copied into the queue and I don't think any storage space allocated (?).
The return value from the post to the sem could be ignored, or a wrapper function that converts the return value to something more friendly for a sem.
Dave.
RE: queue.c: *_interrupts vs. *_criticalPosted by HAR on January 16, 2007 >>There was in fact a bug ... where a co-routine called a utility function ... while interrupts were disabled. The utility function itself entered and exited a critical section - and in so doing resulted in interrupts being enabled when they should not have been ... The utility macro was replaced with inlined code as the fix.
I have the vague memory that VRTX's interrupt-entry macro incremented the critical-section depth counter to avoid this problem . . . or else the critical-section code saved the status register on the first level, using the depth counter from zero *down* to use the condition code *after* the operation (on 80x86)? Maybe I'm mixing up two. Point is, that should be handled.
While acknowledging the specific goal of processor-independence, I would also like to see more processor- and compiler-specific inlining (all of which of course defaults to common standard C code). Call me old-fashioned....
RE: queue.c: *_interrupts vs. *_criticalPosted by Nobody/Anonymous on January 16, 2007 The interrupt macros do keep a count of the nesting depth. The coroutine thing is a special case. Normally you would not use portENABLE_INTERRUPTS or portDISABLE_INTERRUPTS from you code, but portENTER_CRITICAL and portEXIT_CRITICAL instead.
Dave.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|