Re: [Xenomai-core] [PATCH 05/12] Factor out xnsynch_acquire/release

2008-10-16 Thread Gilles Chanteperdrix
Jan Kiszka wrote:

Ok.

-- 
Gilles.

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


[Xenomai-core] [PATCH 05/12] Factor out xnsynch_acquire/release

2008-10-16 Thread Jan Kiszka
This patch addresses the increasing divergence of owner-tracking vs.
owner-less xnsynch objects.

Services dealing with the former will include the new, lockless xnsynch
prologue for optimizing its fastpath. At the the same time, this
additional code should not disturb too much in those cases where we do
not track ownership (condition variables, events, semaphores etc.).
Moreover, I noticed that some of the existing code assumes XNSYNCH_NOPIP
means no ownership, which is surely not true. The already visible effect
is that lock stealing is needlessly restricted to XNSYNCH_PIP.

Going through the API, I dug out three diverging services and replaced
them with two new ones:

Owner-less xnsynch objects:
 - xnsynch_sleep_on
 - xnsynch_wakeup_one_sleeper
 - xnsynch_wakeup_this_sleeper

Owner-tracking xnsynch objects:
 - xnsynch_acquire
 - xnsynch_release

The latter type of objects are marked with the new flag XNSYNCH_OWNER,
used only for debugging and code documentation purposes in the current
implementation.

Signed-off-by: Jan Kiszka <[EMAIL PROTECTED]>
---
 include/nucleus/synch.h |   16 +
 include/rtdm/rtdm_driver.h  |2 
 ksrc/nucleus/synch.c|  418 +---
 ksrc/skins/native/cond.c|2 
 ksrc/skins/native/mutex.c   |7 
 ksrc/skins/native/task.c|5 
 ksrc/skins/posix/cond.c |2 
 ksrc/skins/posix/mutex.c|   10 -
 ksrc/skins/posix/mutex.h|6 
 ksrc/skins/rtai/sem.c   |   10 -
 ksrc/skins/rtdm/drvlib.c|   15 -
 ksrc/skins/vrtx/mx.c|6 
 ksrc/skins/vxworks/semLib.c |6 
 13 files changed, 326 insertions(+), 179 deletions(-)

Index: b/include/nucleus/synch.h
===
--- a/include/nucleus/synch.h
+++ b/include/nucleus/synch.h
@@ -30,10 +30,11 @@
 #define XNSYNCH_NOPIP   0x0
 #define XNSYNCH_PIP 0x2
 #define XNSYNCH_DREORD  0x4
+#define XNSYNCH_OWNER   0x8
 
 #if defined(__KERNEL__) || defined(__XENO_SIM__)
 
-#define XNSYNCH_CLAIMED 0x8/* Claimed by other thread(s) w/ PIP */
+#define XNSYNCH_CLAIMED 0x10   /* Claimed by other thread(s) w/ PIP */
 
 /* Spare flags usable by upper interfaces */
 #define XNSYNCH_SPARE0  0x0100
@@ -105,13 +106,18 @@ void xnsynch_sleep_on(xnsynch_t *synch,
 
 struct xnthread *xnsynch_wakeup_one_sleeper(xnsynch_t *synch);
 
-struct xnthread *xnsynch_peek_pendq(xnsynch_t *synch);
-
 xnpholder_t *xnsynch_wakeup_this_sleeper(xnsynch_t *synch,
 xnpholder_t *holder);
 
-int xnsynch_flush(xnsynch_t *synch,
- xnflags_t reason);
+void xnsynch_acquire(xnsynch_t *synch,
+xnticks_t timeout,
+xntmode_t timeout_mode);
+
+struct xnthread *xnsynch_release(xnsynch_t *synch);
+
+struct xnthread *xnsynch_peek_pendq(xnsynch_t *synch);
+
+int xnsynch_flush(xnsynch_t *synch, xnflags_t reason);
 
 void xnsynch_release_all_ownerships(struct xnthread *thread);
 
Index: b/ksrc/nucleus/synch.c
===
--- a/ksrc/nucleus/synch.c
+++ b/ksrc/nucleus/synch.c
@@ -59,6 +59,12 @@
  * - XNSYNCH_PRIO causes the threads waiting for the resource to pend
  * in priority order. Otherwise, FIFO ordering is used (XNSYNCH_FIFO).
  *
+ * - XNSYNCH_OWNER indicates that the synchronization object shall
+ * track its owning thread (required if XNSYNCH_PIP is selected). Note
+ * that setting this flag implies the use xnsynch_acquire and
+ * xnsynch_release instead of xnsynch_sleep_on and
+ * xnsynch_wakeup_one_sleeper/xnsynch_wakeup_this_sleeper.
+ *
  * - XNSYNCH_PIP causes the priority inheritance mechanism to be
  * automatically activated when a priority inversion is detected among
  * threads using this object. Otherwise, no priority inheritance takes
@@ -89,7 +95,7 @@ void xnsynch_init(xnsynch_t *synch, xnfl
initph(&synch->link);
 
if (flags & XNSYNCH_PIP)
-   flags |= XNSYNCH_PRIO;  /* Obviously... */
+   flags |= XNSYNCH_PRIO | XNSYNCH_OWNER;  /* Obviously... */
 
synch->status = flags & ~XNSYNCH_CLAIMED;
synch->owner = NULL;
@@ -98,6 +104,209 @@ void xnsynch_init(xnsynch_t *synch, xnfl
xnarch_init_display_context(synch);
 }
 
+/*!
+ * \fn void xnsynch_sleep_on(xnsynch_t *synch, xnticks_t timeout,
+ *   xntmode_t timeout_mode);
+ * \brief Sleep on an ownerless synchronization object.
+ *
+ * Makes the calling thread sleep on the specified synchronization
+ * object, waiting for it to be signaled.
+ *
+ * This service should be called by upper interfaces wanting the
+ * current thread to pend on the given resource. It must not be used
+ * with synchronization objects that are supposed to track ownership
+ * (XNSYNCH_OWNER).
+ *
+ * @param synch The descriptor address of the synchronization object
+ * to sleep on.
+ *
+ * @param timeout The timeout which may be used to limit the time the
+ * thread pends on t