Module: xenomai-gch
Branch: for-forge
Commit: 5ef2f39f63feae6d01e2dbb5122ec0be6e7eee57
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=5ef2f39f63feae6d01e2dbb5122ec0be6e7eee57

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Nov 14 19:10:02 2014 +0100

cobalt/rtdm/mutex: fix rtdm_mutex_timedlock()

The fast path in rtdm_mutex_timedlock() was terminally broken by the
not-so-recent addition of fast locks to RTDM-based kernel mutexes. As
a matter of fact, the xnthread_try_grab() helper suffered multiple
breakages, including the lack of update to the underlying fastlock
word to reflect a successful locking operation.

To this end, we introduce xnsynch_try_acquire() which properly
attempts to grab the requested mutex on behalf of the current thread,
and call it as a drop-in replacement for xnthread_try_grab().  Callers
fall back to xnsynch_acquire() on failure to put a fast grab on the
mutex.

---

 kernel/cobalt/synch.c |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 410ed73..d9a7f4d 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -299,6 +299,33 @@ static void xnsynch_renice_thread(struct xnthread *thread,
                xnsynch_requeue_sleeper(thread);
 }
 
+int xnsynch_try_acquire(struct xnsynch *synch)
+{
+       struct xnthread *curr;
+       atomic_t *lockp;
+       xnhandle_t h;
+
+       primary_mode_only();
+
+       XENO_BUGON(COBALT, (synch->status & XNSYNCH_OWNER) == 0);
+
+       curr = xnthread_current();
+       lockp = xnsynch_fastlock(synch);
+       trace_cobalt_synch_try_acquire(synch, curr);
+
+       h = atomic_cmpxchg(lockp, XN_NO_HANDLE, curr->handle);
+       if (h != XN_NO_HANDLE)
+               return xnhandle_get_id(h) == curr->handle ?
+                       -EDEADLK : -EBUSY;
+
+       xnsynch_set_owner(synch, curr);
+       if (xnthread_test_state(curr, XNWEAK))
+               curr->res_count++;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(xnsynch_try_acquire);
+
 /**
  * @fn int xnsynch_try_acquire(struct xnsynch *synch);
  * @brief Try acquiring the ownership of a synchronization object.


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to