[cm3/sync] mutex_lock now calls mutex_trylock repeatedly

This commit is contained in:
Oliver Meier 2014-12-05 17:51:09 +01:00 committed by Karl Palsson
parent a2fe6c49a8
commit f52a39cc48

View File

@ -45,20 +45,7 @@ uint32_t __strex(uint32_t val, volatile uint32_t *addr)
void mutex_lock(mutex_t *m) void mutex_lock(mutex_t *m)
{ {
uint32_t status = 0; while (!mutex_trylock(m));
do {
/* Wait until the mutex is unlocked. */
while (__ldrex(m) != MUTEX_UNLOCKED);
/* Try to acquire it. */
status = __strex(MUTEX_LOCKED, m);
/* Did we get it? If not then try again. */
} while (status != 0);
/* Execute the mysterious Data Memory Barrier instruction! */
__dmb();
} }
/* returns 1 if the lock was acquired */ /* returns 1 if the lock was acquired */