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] [October 2007 Threads] Nested Critical RegionPosted by jackson on October 18, 2007 Will it be a problem when a task(A) yield from within the function vTaskPrioritySet()?(also many other functions such as xQueueSend...)that have the code structure taskENTER_CRITICAL(); { ... taskYIELD(); } taskEXIT_CRITICAL();
and if the succeding task(B) also has a code taskENTER_CRITICAL(); { ... } taskEXIT_CRITICAL();
From the Source code (ARM IAR port)
void vPortEnterCritical( void ) //taskENTER_CRITICAL() { __disable_interrupt(); ulCriticalNesting++; }
void vPortExitCritical( void ) //taskEXIT_CRITICAL() { if( ulCriticalNesting > portNO_CRITICAL_NESTING ) //(>0) { ulCriticalNesting--; if( ulCriticalNesting == portNO_CRITICAL_NESTING ) // == 0 { __enable_interrupt(); } } }
My question is, will the interrupt still be disabled after task B leave the critical region ? If yes then it certainly not meet our desire. Do i miss something ?
RE: Nested Critical RegionPosted by Richard on October 18, 2007 I need to write an FAQ on this one :o)
No it is not a problem for the kernel to switch tasks from within a critical section - in fact the scheduler locking mechanism relies on the ability to do this.
Each task maintains its own interrupt state. Therefore task A may enter a critical section, then yield to task B. When task A starts executing again it will do so from within the critical section, so interrupts will again be disabled. Task B may or may not have interrupts enabled, it depends on the interrupt status when task B yielded, so interrupts will not necessarily be disabled between when task A stops executing and subsequently starts executing again.
Regards.
RE: Nested Critical RegionPosted by Dave on October 18, 2007 >Each task maintains its own interrupt state
and each task saves its uxCriticalNesting value as part of its context.
RE: Nested Critical RegionPosted by jackson on October 18, 2007 What i mean is task B never expect it will cause the interrupt disabled after leave the critical section.
RE: Nested Critical RegionPosted by jackson on October 18, 2007 Thanks for your explanation !
RE: Nested Critical RegionPosted by Dave on October 18, 2007 I don't understand what you mean here. As far as TaskB is concerned it is the only task in the system. It does not know or care what TaskA is doing. It always has the interrupt state as it expects it to have. If its in a critical region then it expects to have interrupts diabled. If its out of a critical region then it expects to have interrupts enabled. This is always the case and is not dependent on when it or any other task yields. Critical sections can nest quite happily so the critical section will only be exited when the same number of calls are made to portEXIT_CRITICAL as were already made to portENTER_CRITICAL.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|