From ce60b937cb172690222b19026212718aac6fd469 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 14 Mar 2012 20:58:52 +0000 Subject: mutex: retry immediatly if we could not get exclusive access When updating the lock field of the mutex to acquire it, if the store exclusive fails, we want to retry immediatly else if the failure has been triggered by the other user doing the mutex_unlock we might not be woken up. Signed-off-by: Vincent Palatin BUG=chrome-os-partner:8492 TEST=run on proto-0.5 and see that the temperature sensor and battery tasks are longer hanging (see the bug for details how to check it) Change-Id: I0c8a4e997666a7781b3837f0dbbc47ffbc06b6c3 --- core/cortex-m/task.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c index aed0a6b13c..4e4928929e 100644 --- a/core/cortex-m/task.c +++ b/core/cortex-m/task.c @@ -339,8 +339,11 @@ void mutex_lock(struct mutex *mtx) " it eq\n" " strexeq %0, %2, [%1]\n" : "=&r" (value) - : "r" (&mtx->lock), "r" (1) : "cc"); - if (value) { + : "r" (&mtx->lock), "r" (2) : "cc"); + /* "value" is equals to 1 if the store conditional failed, + * 2 if somebody else owns the mutex, 0 else. + */ + if (value == 2) { /* contention on the mutex */ task_wait_msg(0); } -- cgit v1.2.1