queue.c: *_interrupts vs. *_critical

<<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.

queue.c: *_interrupts vs. *_critical

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.

queue.c: *_interrupts vs. *_critical

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.

queue.c: *_interrupts vs. *_critical

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.

queue.c: *_interrupts vs. *_critical

>>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 80×86)?  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….

queue.c: *_interrupts vs. *_critical

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.