Module: xenomai-forge
Branch: next
Commit: d0892b1340b7b9bb05092d09d94499caba8268da
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=d0892b1340b7b9bb05092d09d94499caba8268da

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..dd9ee68 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, XNWEAK))
+               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

Reply via email to