Reading spru514 it mentions that some optimization levels may reorder operations.
Is there a way to ensure order of operations are maintained for specific code blocks?
Given the example:
int16_t run_handler(const handler_t handler, const OBJ_Handle handle) {
int16_t e = EXIT_SUCCESS;
if (handle->busy != true) {
handle->busy = true;
e = handler(handle);
handle->busy = false;
} else {
e = EXIT_FAILURE;
}
return e;
}
How can we ensure that busy will only be set to false after the function has been called?
In this case qualifying the busy variable as volatile is not enough I think, as J.3.10 of the aforementioned document says
"The TI compiler will not reorder two volatile accesses, but it may reorder a volatile and a non-volatile access"
While the handler is not critical code (interrupts should still run while it executes and may be free to change the value of busy if they see fit), it obviously would not make sense for the compiler to access the handler call before it has set busy to true or after it has set busy to false.
Thanks, T