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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Jun 29 15:27:13 2013 +0200

cobalt/kernel: use non-atomic bitwise operations in atomic sections

---

 include/cobalt/kernel/synch.h |   11 +++++++++--
 kernel/cobalt/pipe.c          |    2 +-
 kernel/cobalt/posix/event.c   |    4 ++--
 kernel/cobalt/rtdm/drvlib.c   |   12 ++++++------
 kernel/cobalt/shadow.c        |   12 ++++++++++--
 5 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index 1230d49..a596ae3 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -62,8 +62,15 @@ typedef struct xnsynch {
        void (*cleanup)(struct xnsynch *synch); /* Cleanup handler */
 } xnsynch_t;
 
-#define xnsynch_set_flags(synch,flags)         setbits((synch)->status,flags)
-#define xnsynch_clear_flags(synch,flags)       clrbits((synch)->status,flags)
+static inline void xnsynch_set_status(struct xnsynch *synch, int bits)
+{
+       synch->status |= bits;
+}
+
+static inline void xnsynch_clear_status(struct xnsynch *synch, int bits)
+{
+       synch->status &= ~bits;
+}
 
 #define xnsynch_for_each_sleeper(__pos, __synch)               \
        list_for_each_entry(__pos, &(__synch)->pendq, plink)
diff --git a/kernel/cobalt/pipe.c b/kernel/cobalt/pipe.c
index a978072..46343d9 100644
--- a/kernel/cobalt/pipe.c
+++ b/kernel/cobalt/pipe.c
@@ -639,7 +639,7 @@ EXPORT_SYMBOL_GPL(xnpipe_flush);
                xnpipe_flushq((__state), inq, free_ibuf, (__s));        \
                (__state)->status &= ~XNPIPE_USER_CONN;                 \
                if ((__state)->status & XNPIPE_KERN_LCLOSE) {           \
-                       clrbits((__state)->status, XNPIPE_KERN_LCLOSE); \
+                       (__state)->status &= ~XNPIPE_KERN_LCLOSE;       \
                        xnlock_put_irqrestore(&nklock, (__s));          \
                        (__state)->ops.release((__state)->xstate);      \
                        xnlock_get_irqsave(&nklock, (__s));             \
diff --git a/kernel/cobalt/posix/event.c b/kernel/cobalt/posix/event.c
index 3697491..4c779af 100644
--- a/kernel/cobalt/posix/event.c
+++ b/kernel/cobalt/posix/event.c
@@ -148,7 +148,7 @@ int cobalt_event_wait(struct cobalt_event_shadow __user 
*u_evtsh,
                goto out;
        }
 
-       setbits(datp->flags, COBALT_EVENT_PENDED);
+       datp->flags |= COBALT_EVENT_PENDED;
        rbits = datp->value & bits;
        testval = mode & COBALT_EVENT_ANY ? rbits : datp->value;
        if (rbits && rbits == testval)
@@ -177,7 +177,7 @@ int cobalt_event_wait(struct cobalt_event_shadow __user 
*u_evtsh,
                rbits = ewc.value;
 done:
        if (!xnsynch_pended_p(&event->synch))
-               clrbits(datp->flags, COBALT_EVENT_PENDED);
+               datp->flags &= ~COBALT_EVENT_PENDED;
 out:
        xnlock_put_irqrestore(&nklock, s);
 
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index 3e7fb0d..787ceac 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -639,7 +639,7 @@ void __rtdm_synch_flush(xnsynch_t *synch, unsigned long 
reason)
        xnlock_get_irqsave(&nklock, s);
 
        if (reason == XNRMID)
-               xnsynch_set_flags(synch, RTDM_SYNCH_DELETED);
+               xnsynch_set_status(synch, RTDM_SYNCH_DELETED);
 
        if (likely(xnsynch_flush(synch, reason) == XNSYNCH_RESCHED))
                xnpod_schedule();
@@ -752,7 +752,7 @@ void rtdm_event_init(rtdm_event_t *event, unsigned long 
pending)
 
        xnsynch_init(&event->synch_base, XNSYNCH_PRIO, NULL);
        if (pending)
-               xnsynch_set_flags(&event->synch_base, RTDM_EVENT_PENDING);
+               xnsynch_set_status(&event->synch_base, RTDM_EVENT_PENDING);
        xnselect_init(&event->select_block);
 
        xnlock_put_irqrestore(&nklock, s);
@@ -830,7 +830,7 @@ void rtdm_event_signal(rtdm_event_t *event)
 
        xnlock_get_irqsave(&nklock, s);
 
-       xnsynch_set_flags(&event->synch_base, RTDM_EVENT_PENDING);
+       xnsynch_set_status(&event->synch_base, RTDM_EVENT_PENDING);
        if (xnsynch_flush(&event->synch_base, 0))
                resched = 1;
        if (xnselect_signal(&event->select_block, 1))
@@ -933,7 +933,7 @@ int rtdm_event_timedwait(rtdm_event_t *event, 
nanosecs_rel_t timeout,
        if (unlikely(event->synch_base.status & RTDM_SYNCH_DELETED))
                err = -EIDRM;
        else if (likely(event->synch_base.status & RTDM_EVENT_PENDING)) {
-               xnsynch_clear_flags(&event->synch_base, RTDM_EVENT_PENDING);
+               xnsynch_clear_status(&event->synch_base, RTDM_EVENT_PENDING);
                xnselect_signal(&event->select_block, 0);
        } else {
                /* non-blocking mode */
@@ -955,7 +955,7 @@ int rtdm_event_timedwait(rtdm_event_t *event, 
nanosecs_rel_t timeout,
 
                if (likely
                    (!xnthread_test_info(thread, XNTIMEO | XNRMID | XNBREAK))) {
-                       xnsynch_clear_flags(&event->synch_base,
+                       xnsynch_clear_status(&event->synch_base,
                                            RTDM_EVENT_PENDING);
                        xnselect_signal(&event->select_block, 0);
                } else if (xnthread_test_info(thread, XNTIMEO))
@@ -998,7 +998,7 @@ void rtdm_event_clear(rtdm_event_t *event)
 
        xnlock_get_irqsave(&nklock, s);
 
-       xnsynch_clear_flags(&event->synch_base, RTDM_EVENT_PENDING);
+       xnsynch_clear_status(&event->synch_base, RTDM_EVENT_PENDING);
        xnselect_signal(&event->select_block, 0);
 
        xnlock_put_irqrestore(&nklock, s);
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 8dcfec9..2995eae 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -276,14 +276,22 @@ static void request_syscall_restart(struct xnthread 
*thread,
 
 static inline void lock_timers(void)
 {
+       spl_t s;
+
+       xnlock_get_irqsave(&nklock, s);
        atomic_inc(&nkpod->timerlck);
-       setbits(nkclock.status, XNTBLCK);
+       nkclock.status |= XNTBLCK;
+       xnlock_put_irqrestore(&nklock, s);
 }
 
 static inline void unlock_timers(void)
 {
+       spl_t s;
+
+       xnlock_get_irqsave(&nklock, s);
        if (atomic_dec_and_test(&nkpod->timerlck))
-               clrbits(nkclock.status, XNTBLCK);
+               nkclock.status &= ~XNTBLCK;
+       xnlock_put_irqrestore(&nklock, s);
 }
 
 static int enter_personality(struct xnpersonality *personality)


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

Reply via email to