From fb410a403db7298f97fb0120bb93f822ec0e2aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 5 Jan 2016 23:20:02 +0100 Subject: [PATCH] cm3/sync: Fix broken mutex_trylock() Fails when the mutex was already locked. Implemented zyp's fix for broken mutex. If it's 1 (= failure) by default, the function works fine. irc log for reference ``` strex returns 1 if it fails, 0 if it's successful but if the mutex is already locked, line 57 skips the status update and status gets remains at the initial value which means successful, which is wrong changing line 54 to status = 1 should do the trick ``` --- lib/cm3/sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cm3/sync.c b/lib/cm3/sync.c index 41017257..2a77d4f6 100644 --- a/lib/cm3/sync.c +++ b/lib/cm3/sync.c @@ -51,7 +51,7 @@ void mutex_lock(mutex_t *m) /* returns 1 if the lock was acquired */ uint32_t mutex_trylock(mutex_t *m) { - uint32_t status = 0; + uint32_t status = 1; /* If the mutex is unlocked. */ if (__ldrex(m) == MUTEX_UNLOCKED) {