[Xenomai-git] Philippe Gerum : cobalt/thread: introduce xnthread_try_grab()

2014-03-28 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: e440da777515f6ec64bbe27890f26d19291a9249
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e440da777515f6ec64bbe27890f26d19291a9249

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Mar 27 17:12:04 2014 +0100

cobalt/thread: introduce xnthread_try_grab()

We allow the caller to bypass xnsynch_acquire() for assigning the
ownership of an object to a given thread, by calling
xnthread_try_grab(), provided the object does not share any fastlock
area with userland.

xnthread_try_grab() returns non-zero if the object was successfully
grabbed, zero otherwise (i.e. this object was already owned by another
thread).

---

 include/cobalt/kernel/thread.h |   16 
 1 file changed, 16 insertions(+)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 9ec09b1..252fd9a 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -302,6 +302,22 @@ void xnthread_set_sync_window(struct xnthread *thread, int 
bits)
thread-u_window-state = thread-state | bits;
 }
 
+static inline int xnthread_try_grab(struct xnthread *thread,
+   struct xnsynch *synch)
+{
+   XENO_BUGON(NUCLEUS, xnsynch_fastlock_p(synch));
+
+   if (xnsynch_owner(synch) != NULL)
+   return 0;
+
+   xnsynch_set_owner(synch, thread);
+
+   if (xnthread_test_state(thread, XNOTHER))
+   xnthread_inc_rescnt(thread);
+
+   return 1;
+}
+
 /*
  * XXX: Mutual dependency issue with synch.h, we have to define
  * xnsynch_release() here.


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


[Xenomai-git] Philippe Gerum : cobalt/rtdm: fix resource count imbalance in mutex_lock op

2014-03-28 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 65d80f99b463e233d1e6345a606720314113f570
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=65d80f99b463e233d1e6345a606720314113f570

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Mar 28 12:12:52 2014 +0100

cobalt/rtdm: fix resource count imbalance in mutex_lock op

---

 kernel/cobalt/rtdm/drvlib.c |4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index 17178ee..a89decc 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -1528,9 +1528,7 @@ int rtdm_mutex_timedlock(rtdm_mutex_t *mutex, 
nanosecs_rel_t timeout,
 
if (unlikely(mutex-synch_base.status  RTDM_SYNCH_DELETED))
err = -EIDRM;
-   else if (likely(xnsynch_owner(mutex-synch_base) == NULL))
-   xnsynch_set_owner(mutex-synch_base, curr_thread);
-   else {
+   else if (!xnthread_try_grab(curr_thread, mutex-synch_base)) {
/* Redefinition to clarify XENO_ASSERT output */
#define mutex_owner xnsynch_owner(mutex-synch_base)
if (!XENO_ASSERT(RTDM, mutex_owner != curr_thread)) {


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