我在FreeRTOS(FreeRTOSV7.4.0\FreeRTOS\Source\tasks.c)中找到了一些代码:
void vTaskSuspendAll( void )
{
/* A critical section is not required as the variable is of type
portBASE_TYPE. */
++uxSchedulerSuspended;
}
显式地指明无需保护是因为类型是"portBASE_TYPE",这是一个"long"类型。我的理解是它假设自增操作对于这种类型是原子的。但是,在我反汇编之后,我没有找到任何证据,只是简单的load->add->store。那么这是个问题吗?
void vTaskSuspendAll( void )
{
/* A critical section is not required as the variable is of type
portBASE_TYPE. */
++uxSchedulerSuspended;
4dc: 4b03 ldr r3, [pc, #12] ; (4ec <vTaskSuspendAll+0x10>)
4de: f8d3 2118 ldr.w r2, [r3, #280] ; 0x118
4e2: 1c50 adds r0, r2, #1
4e4: f8c3 0118 str.w r0, [r3, #280] ; 0x118
4e8: 4770 bx lr
4ea: bf00 nop
4ec: 00000000 .word 0x00000000
000004f0 <xTaskGetTickCount>:
return xAlreadyYielded;
}