atomic test and modify uint32_t
Posted: Thu Mar 15, 2018 12:29 pm
Hello,
what is the best way to do a atomic uint32_t operation. The uint32_t variable is only accessed by different freertos tasks, not by HW-ISR.
I do not know if the stdatomic.h stuff works.
I tried
but I'm unsure if that enough protection if the tasks runs on different ESP32-cores. And probably there is a more efficent solution than my code...
Any help is appreciated,
Mark
what is the best way to do a atomic uint32_t operation. The uint32_t variable is only accessed by different freertos tasks, not by HW-ISR.
I do not know if the stdatomic.h stuff works.
I tried
Code: Select all
uint32_t Can_ModifyUInt(uint32_t volatile *pUInt, uint32_t CompareValue, uint32_t NewValue)
{
taskDISABLE_INTERRUPTS();
uint32_t result = *pUInt;
if (result == CompareValue)
*pUInt = NewValue;
taskENABLE_INTERRUPTS();
return result;
}
Any help is appreciated,
Mark