I want to build a low level mutex with atomic operations but I'm not sure if it's correct. It seems to work but I'm not sure with the memory order of atomic_exchange and atomic_store. Could you help me?
This is the code:
Code:#include <stdatomic.h> typedef volatile atomic_int TMutex; inline void MutexLock(TMutex *mutex) { while(atomic_exchange(mutex,1)); } inline void MutexUnLock(TMutex *mutex) { atomic_store(mutex,0); }