Module: xenomai-head
Branch: master
Commit: c790d14c3e552fb3f26655c5c6f94ec8245d1931
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=c790d14c3e552fb3f26655c5c6f94ec8245d1931

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Sep 11 16:28:19 2009 +0200

native: use the info bits as returned by xnsynch_acquire/sleep_on

---

 ksrc/skins/native/buffer.c  |   26 +++++++--------
 ksrc/skins/native/cond.c    |   11 +++---
 ksrc/skins/native/event.c   |   19 ++++++----
 ksrc/skins/native/heap.c    |   10 +++---
 ksrc/skins/native/mutex.c   |   11 +++---
 ksrc/skins/native/queue.c   |   16 ++++----
 ksrc/skins/native/sem.c     |   13 +++----
 ksrc/skins/native/syscall.c |   19 ++++++-----
 ksrc/skins/native/task.c    |   76 ++++++++++++++++++++++--------------------
 9 files changed, 104 insertions(+), 97 deletions(-)

diff --git a/ksrc/skins/native/buffer.c b/ksrc/skins/native/buffer.c
index abee77c..2d364bb 100644
--- a/ksrc/skins/native/buffer.c
+++ b/ksrc/skins/native/buffer.c
@@ -319,6 +319,7 @@ ssize_t rt_buffer_write_inner(RT_BUFFER *bf,
 {
        xnthread_t *thread, *waiter;
        size_t len, rbytes, n;
+       xnflags_t info;
        u_long wrtoken;
        off_t wroff;
        ssize_t ret;
@@ -441,17 +442,15 @@ redo:
 
                thread = xnpod_current_thread();
                thread->wait_u.size = len;
-               xnsynch_sleep_on(&bf->osynch_base, timeout, timeout_mode);
-
-               if (xnthread_test_info(thread, XNRMID)) {
+               info = xnsynch_sleep_on(&bf->osynch_base,
+                                       timeout, timeout_mode);
+               if (info & XNRMID) {
                        ret = -EIDRM;   /* Buffer deleted while pending. */
                        break;
-               }
-               if (xnthread_test_info(thread, XNTIMEO)) {
+               } if (info & XNTIMEO) {
                        ret = -ETIMEDOUT;       /* Timeout. */
                        break;
-               }
-               if (xnthread_test_info(thread, XNBREAK)) {
+               } if (info & XNBREAK) {
                        ret = -EINTR;   /* Unblocked. */
                        break;
                }
@@ -477,6 +476,7 @@ ssize_t rt_buffer_read_inner(RT_BUFFER *bf,
 {
        xnthread_t *thread, *waiter;
        size_t len, rbytes, n;
+       xnflags_t info;
        u_long rdtoken;
        off_t rdoff;
        ssize_t ret;
@@ -612,17 +612,15 @@ redo:
 
                thread = xnpod_current_thread();
                thread->wait_u.bufd =  bufd;
-               xnsynch_sleep_on(&bf->isynch_base, timeout, timeout_mode);
-
-               if (xnthread_test_info(thread, XNRMID)) {
+               info = xnsynch_sleep_on(&bf->isynch_base,
+                                       timeout, timeout_mode);
+               if (info & XNRMID) {
                        ret = -EIDRM;   /* Buffer deleted while pending. */
                        break;
-               }
-               if (xnthread_test_info(thread, XNTIMEO)) {
+               } else if (info & XNTIMEO) {
                        ret = -ETIMEDOUT;       /* Timeout. */
                        break;
-               }
-               if (xnthread_test_info(thread, XNBREAK)) {
+               } if (info & XNBREAK) {
                        ret = -EINTR;   /* Unblocked. */
                        break;
                }
diff --git a/ksrc/skins/native/cond.c b/ksrc/skins/native/cond.c
index 02ba785..cea823e 100644
--- a/ksrc/skins/native/cond.c
+++ b/ksrc/skins/native/cond.c
@@ -377,6 +377,7 @@ int rt_cond_wait_inner(RT_COND *cond, RT_MUTEX *mutex,
 {
        int err, kicked = 0;
        xnthread_t *thread;
+       xnflags_t info;
        int lockcnt;
        spl_t s;
 
@@ -420,13 +421,13 @@ int rt_cond_wait_inner(RT_COND *cond, RT_MUTEX *mutex,
        xnsynch_release(&mutex->synch_base);
        /* Scheduling deferred */
 
-       xnsynch_sleep_on(&cond->synch_base, timeout, timeout_mode);
-
-       if (xnthread_test_info(thread, XNRMID))
+       info = xnsynch_sleep_on(&cond->synch_base,
+                               timeout, timeout_mode);
+       if (info & XNRMID)
                err = -EIDRM;   /* Condvar deleted while pending. */
-       else if (xnthread_test_info(thread, XNTIMEO))
+       else if (info & XNTIMEO)
                err = -ETIMEDOUT;       /* Timeout. */
-       else if (xnthread_test_info(thread, XNBREAK)) {
+       else if (info & XNBREAK) {
                err = -EINTR;   /* Unblocked. */
                kicked = xnthread_test_info(thread, XNKICKED);
        }
diff --git a/ksrc/skins/native/event.c b/ksrc/skins/native/event.c
index db5921b..5b2a8b5 100644
--- a/ksrc/skins/native/event.c
+++ b/ksrc/skins/native/event.c
@@ -369,6 +369,7 @@ int rt_event_wait_inner(RT_EVENT *event,
                        int mode, xntmode_t timeout_mode, RTIME timeout)
 {
        RT_TASK *task;
+       xnflags_t info;
        int err = 0;
        spl_t s;
 
@@ -413,17 +414,19 @@ int rt_event_wait_inner(RT_EVENT *event,
        task = xeno_current_task();
        task->wait_args.event.mode = mode;
        task->wait_args.event.mask = mask;
-       xnsynch_sleep_on(&event->synch_base, timeout, timeout_mode);
-       /* The returned mask is only significant if the operation has
-          succeeded, but do always write it back anyway. */
-       *mask_r = task->wait_args.event.mask;
-
-       if (xnthread_test_info(&task->thread_base, XNRMID))
+       info = xnsynch_sleep_on(&event->synch_base,
+                               timeout, timeout_mode);
+       if (info & XNRMID)
                err = -EIDRM;   /* Event group deleted while pending. */
-       else if (xnthread_test_info(&task->thread_base, XNTIMEO))
+       else if (info & XNTIMEO)
                err = -ETIMEDOUT;       /* Timeout. */
-       else if (xnthread_test_info(&task->thread_base, XNBREAK))
+       else if (info & XNBREAK)
                err = -EINTR;   /* Unblocked. */
+       /*
+        * The returned mask is only significant if the operation has
+        * succeeded, but do always write it back anyway.
+        */
+       *mask_r = task->wait_args.event.mask;
 
       unlock_and_exit:
 
diff --git a/ksrc/skins/native/heap.c b/ksrc/skins/native/heap.c
index a830d01..0a24735 100644
--- a/ksrc/skins/native/heap.c
+++ b/ksrc/skins/native/heap.c
@@ -515,6 +515,7 @@ int rt_heap_alloc(RT_HEAP *heap, size_t size, RTIME 
timeout, void **blockp)
 {
        void *block = NULL;
        xnthread_t *thread;
+       xnflags_t info;
        int err = 0;
        spl_t s;
 
@@ -576,13 +577,12 @@ int rt_heap_alloc(RT_HEAP *heap, size_t size, RTIME 
timeout, void **blockp)
        thread = xnpod_current_thread();
        thread->wait_u.buffer.size = size;
        thread->wait_u.buffer.ptr = NULL;
-       xnsynch_sleep_on(&heap->synch_base, timeout, XN_RELATIVE);
-
-       if (xnthread_test_info(thread, XNRMID))
+       info = xnsynch_sleep_on(&heap->synch_base, timeout, XN_RELATIVE);
+       if (info & XNRMID)
                err = -EIDRM;   /* Heap deleted while pending. */
-       else if (xnthread_test_info(thread, XNTIMEO))
+       else if (info & XNTIMEO)
                err = -ETIMEDOUT;       /* Timeout. */
-       else if (xnthread_test_info(thread, XNBREAK))
+       else if (info & XNBREAK)
                err = -EINTR;   /* Unblocked. */
        else
                block = thread->wait_u.buffer.ptr;
diff --git a/ksrc/skins/native/mutex.c b/ksrc/skins/native/mutex.c
index ce45d37..20eb484 100644
--- a/ksrc/skins/native/mutex.c
+++ b/ksrc/skins/native/mutex.c
@@ -327,6 +327,7 @@ int rt_mutex_acquire_inner(RT_MUTEX *mutex, RTIME timeout,
                           xntmode_t timeout_mode)
 {
        xnthread_t *thread;
+       xnflags_t info;
 
        if (xnpod_unblockable_p())
                return -EPERM;
@@ -366,12 +367,12 @@ int rt_mutex_acquire_inner(RT_MUTEX *mutex, RTIME timeout,
 #endif /* !CONFIG_XENO_FASTSYNCH */
        }
 
-       xnsynch_acquire(&mutex->synch_base, timeout, timeout_mode);
-
-       if (unlikely(xnthread_test_info(thread, XNBREAK | XNRMID | XNTIMEO))) {
-               if (xnthread_test_info(thread, XNBREAK))
+       info = xnsynch_acquire(&mutex->synch_base,
+                              timeout, timeout_mode);
+       if (unlikely(info)) {
+               if (info & XNBREAK)
                        return -EINTR;
-               else if (xnthread_test_info(thread, XNTIMEO))
+               else if (info & XNTIMEO)
                        return -ETIMEDOUT;
                else /* XNRMID */
                        return -EIDRM;
diff --git a/ksrc/skins/native/queue.c b/ksrc/skins/native/queue.c
index 60d5a49..8e2bb6f 100644
--- a/ksrc/skins/native/queue.c
+++ b/ksrc/skins/native/queue.c
@@ -745,6 +745,7 @@ ssize_t rt_queue_receive_inner(RT_QUEUE *q, void **bufp,
        xnthread_t *thread;
        xnholder_t *holder;
        ssize_t err = 0;
+       xnflags_t info;
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
@@ -772,17 +773,16 @@ ssize_t rt_queue_receive_inner(RT_QUEUE *q, void **bufp,
                        goto unlock_and_exit;
                }
 
-               xnsynch_sleep_on(&q->synch_base, timeout, timeout_mode);
-
-               thread = xnpod_current_thread();
-
-               if (xnthread_test_info(thread, XNRMID))
+               info = xnsynch_sleep_on(&q->synch_base,
+                                       timeout, timeout_mode);
+               if (info & XNRMID)
                        err = -EIDRM;   /* Queue deleted while pending. */
-               else if (xnthread_test_info(thread, XNTIMEO))
-                       err = -ETIMEDOUT;       /* Timeout. */
-               else if (xnthread_test_info(thread, XNBREAK))
+               else if (info & XNTIMEO)
+                       err = -ETIMEDOUT; /* Timeout. */
+               else if (info & XNBREAK)
                        err = -EINTR;   /* Unblocked. */
                else {
+                       thread = xnpod_current_thread();
                        msg = thread->wait_u.buffer.ptr;
                        thread->wait_u.buffer.ptr = NULL;
                }
diff --git a/ksrc/skins/native/sem.c b/ksrc/skins/native/sem.c
index 48640a1..0afea09 100644
--- a/ksrc/skins/native/sem.c
+++ b/ksrc/skins/native/sem.c
@@ -283,6 +283,7 @@ int rt_sem_delete(RT_SEM *sem)
 
 int rt_sem_p_inner(RT_SEM *sem, xntmode_t timeout_mode, RTIME timeout)
 {
+       xnflags_t info;
        int err = 0;
        spl_t s;
 
@@ -312,15 +313,13 @@ int rt_sem_p_inner(RT_SEM *sem, xntmode_t timeout_mode, 
RTIME timeout)
        if (sem->count > 0)
                --sem->count;
        else {
-               xnthread_t *thread = xnpod_current_thread();
-
-               xnsynch_sleep_on(&sem->synch_base, timeout, timeout_mode);
-
-               if (xnthread_test_info(thread, XNRMID))
+               info = xnsynch_sleep_on(&sem->synch_base,
+                                       timeout, timeout_mode);
+               if (info & XNRMID)
                        err = -EIDRM;   /* Semaphore deleted while pending. */
-               else if (xnthread_test_info(thread, XNTIMEO))
+               else if (info & XNTIMEO)
                        err = -ETIMEDOUT;       /* Timeout. */
-               else if (xnthread_test_info(thread, XNBREAK))
+               else if (info & XNBREAK)
                        err = -EINTR;   /* Unblocked. */
        }
 
diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c
index 3bd28e3..79ca84c 100644
--- a/ksrc/skins/native/syscall.c
+++ b/ksrc/skins/native/syscall.c
@@ -2885,6 +2885,7 @@ static int __rt_alarm_wait(struct pt_regs *regs)
        union xnsched_policy_param param;
        RT_ALARM_PLACEHOLDER ph;
        RT_ALARM *alarm;
+       xnflags_t info;
        int err = 0;
        spl_t s;
 
@@ -2909,11 +2910,10 @@ static int __rt_alarm_wait(struct pt_regs *regs)
                xnpod_set_thread_schedparam(thread, &xnsched_class_rt, &param);
        }
 
-       xnsynch_sleep_on(&alarm->synch_base, XN_INFINITE, XN_RELATIVE);
-
-       if (xnthread_test_info(thread, XNRMID))
+       info = xnsynch_sleep_on(&alarm->synch_base, XN_INFINITE, XN_RELATIVE);
+       if (info & XNRMID)
                err = -EIDRM;   /* Alarm deleted while pending. */
-       else if (xnthread_test_info(thread, XNBREAK))
+       else if (info & XNBREAK)
                err = -EINTR;   /* Unblocked. */
 
       unlock_and_exit:
@@ -3103,6 +3103,7 @@ static int __rt_intr_wait(struct pt_regs *regs)
        union xnsched_policy_param param;
        RT_INTR_PLACEHOLDER ph;
        xnthread_t *thread;
+       xnflags_t info;
        RTIME timeout;
        RT_INTR *intr;
        int err = 0;
@@ -3139,13 +3140,13 @@ static int __rt_intr_wait(struct pt_regs *regs)
                        xnpod_set_thread_schedparam(thread, &xnsched_class_rt, 
&param);
                }
 
-               xnsynch_sleep_on(&intr->synch_base, timeout, XN_RELATIVE);
-
-               if (xnthread_test_info(thread, XNRMID))
+               info = xnsynch_sleep_on(&intr->synch_base,
+                                       timeout, XN_RELATIVE);
+               if (info & XNRMID)
                        err = -EIDRM;   /* Interrupt object deleted while 
pending. */
-               else if (xnthread_test_info(thread, XNTIMEO))
+               else if (info & XNTIMEO)
                        err = -ETIMEDOUT;       /* Timeout. */
-               else if (xnthread_test_info(thread, XNBREAK))
+               else if (info & XNBREAK)
                        err = -EINTR;   /* Unblocked. */
                else
                        err = intr->pending;
diff --git a/ksrc/skins/native/task.c b/ksrc/skins/native/task.c
index ef10eb1..396eaa0 100644
--- a/ksrc/skins/native/task.c
+++ b/ksrc/skins/native/task.c
@@ -108,6 +108,7 @@ void __native_task_unsafe(RT_TASK *task)
 int __native_task_safewait(RT_TASK *task)
 {
        /* Must be called nklock locked, interrupts off. */
+       xnflags_t info;
        u_long cstamp;
 
        if (task->safelock == 0)
@@ -116,13 +117,11 @@ int __native_task_safewait(RT_TASK *task)
        cstamp = task->cstamp;
 
        do {
-               xnsynch_sleep_on(&task->safesynch, XN_INFINITE, XN_RELATIVE);
-
-               if (xnthread_test_info
-                   (&xeno_current_task()->thread_base, XNBREAK))
-                       return -EINTR;
-       }
-       while (task->safelock > 0);
+         info = xnsynch_sleep_on(&task->safesynch,
+                                 XN_INFINITE, XN_RELATIVE);
+         if (info & XNBREAK)
+                 return -EINTR;
+       } while (task->safelock > 0);
 
        if (task->cstamp != cstamp)
                return -EIDRM;
@@ -1719,6 +1718,7 @@ ssize_t rt_task_send(RT_TASK *task,
                     RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r, RTIME timeout)
 {
        RT_TASK *client;
+       xnflags_t info;
        size_t rsize;
        ssize_t err;
        spl_t s;
@@ -1770,30 +1770,32 @@ ssize_t rt_task_send(RT_TASK *task,
        else
                client->wait_args.mps.mcb_r.size = 0;
 
-       /* Wake up the server if it is currently waiting for a
-          message, then sleep on the send queue, waiting for the
-          remote reply. xnsynch_sleep_on() will reschedule as
-          needed. */
-
+       /*
+        * Wake up the server if it is currently waiting for a
+        * message, then sleep on the send queue, waiting for the
+        * remote reply. xnsynch_sleep_on() will reschedule as
+        * needed.
+        */
        xnsynch_flush(&task->mrecv, 0);
 
-       /* Since the server is perpetually marked as the current owner
-          of its own send queue which has been declared as a
-          PIP-enabled object, it will inherit the priority of the
-          client in the case required by the priority inheritance
-          protocol (i.e. prio(client) > prio(server)). */
-
-       xnsynch_acquire(&task->msendq, timeout, XN_RELATIVE);
-
-       /* At this point, the server task might have exited right
+       /*
+        * Since the server is perpetually marked as the current owner
+        * of its own send queue which has been declared as a
+        * PIP-enabled object, it will inherit the priority of the
+        * client in the case required by the priority inheritance
+        * protocol (i.e. prio(client) > prio(server)).
+        */
+       info = xnsynch_acquire(&task->msendq, timeout, XN_RELATIVE);
+       /*
+        * At this point, the server task might have exited right
         * after having replied to us, so do not make optimistic
-        * assumption regarding its existence. */
-
-       if (xnthread_test_info(&client->thread_base, XNRMID))
+        * assumption regarding its existence.
+        */
+       if (info & XNRMID)
                err = -EIDRM;   /* Receiver deleted while pending. */
-       else if (xnthread_test_info(&client->thread_base, XNTIMEO))
+       else if (info & XNTIMEO)
                err = -ETIMEDOUT;       /* Timeout. */
-       else if (xnthread_test_info(&client->thread_base, XNBREAK))
+       else if (info & XNBREAK)
                err = -EINTR;   /* Unblocked. */
        else {
                rsize = client->wait_args.mps.mcb_r.size;
@@ -1912,6 +1914,7 @@ int rt_task_receive(RT_TASK_MCB *mcb_r, RTIME timeout)
 {
        RT_TASK *server, *client;
        xnpholder_t *holder;
+       xnflags_t info;
        size_t rsize;
        int err;
        spl_t s;
@@ -1942,18 +1945,19 @@ int rt_task_receive(RT_TASK_MCB *mcb_r, RTIME timeout)
                goto unlock_and_exit;
        }
 
-       /* Wait on our receive slot for some client to enqueue itself in
-          our send queue. */
-
-       xnsynch_sleep_on(&server->mrecv, timeout, XN_RELATIVE);
-
-       /* XNRMID cannot happen, since well, the current task would be the
-          deleted object, so... */
-
-       if (xnthread_test_info(&server->thread_base, XNTIMEO)) {
+       /*
+        * Wait on our receive slot for some client to enqueue itself
+        * in our send queue.
+        */
+       info = xnsynch_sleep_on(&server->mrecv, timeout, XN_RELATIVE);
+       /*
+        * XNRMID cannot happen, since well, the current task would be the
+        * deleted object, so...
+        */
+       if (info & XNTIMEO) {
                err = -ETIMEDOUT;       /* Timeout. */
                goto unlock_and_exit;
-       } else if (xnthread_test_info(&server->thread_base, XNBREAK)) {
+       } else if (info & XNBREAK) {
                err = -EINTR;   /* Unblocked. */
                goto unlock_and_exit;
        }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to