f9-kernel
f9-kernel copied to clipboard
Ensure that all explicit memory accesses that appear in program order
Function test_and_set_word and test_and_set_bit in file platform/bitops.c implements the basic locking mechanism utilizing ldrex and strexeq instruction. However, other similar routines are not taken into consideration carefully, and we have to ensure that all explicit memory accesses that appear in program order before the DMB instruction are observed before any explicit memory accesses.
Here is the conceptual implementation:
int test_and_set(int *lock)
{
int old_value;
/* Ensure that all explicit memory accesses that appear in program order
* before the DMB instruction are observed before any explicit memory
* accesses. */
__asm__ volatile ("dmb");
old_value = *lock;
*lock = 1;
return old_value;
}