Module: xenomai-forge
Branch: rtdm-api-waitqueues
Commit: 5f35a0e6b883ee3721f234a3a5a034a8510b1f35
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5f35a0e6b883ee3721f234a3a5a034a8510b1f35

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Apr 10 11:41:43 2014 +0200

drivers/ipc: move to new-style atomic sections

---

 kernel/drivers/ipc/bufp.c |  105 ++++++++++---------
 kernel/drivers/ipc/iddp.c |  245 +++++++++++++++++++++++----------------------
 kernel/drivers/ipc/xddp.c |   92 +++++++++--------
 3 files changed, 227 insertions(+), 215 deletions(-)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 4363c68..d65f86f 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -666,6 +666,7 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
 {
        struct bufp_socket *sk = priv->state;
        int ret = 0, port, fd;
+       spl_t s;
 
        if (sa->sipc_family != AF_RTIPC)
                return -EINVAL;
@@ -674,11 +675,12 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
            sa->sipc_port >= CONFIG_XENO_OPT_BUFP_NRPORT)
                return -EINVAL;
 
-       RTDM_EXECUTE_ATOMICALLY(
-               if (test_bit(_BUFP_BOUND, &sk->status) ||
-                   __test_and_set_bit(_BUFP_BINDING, &sk->status))
-                       ret = -EADDRINUSE;
-       );
+       rtdm_atomic_enter(s);
+       if (test_bit(_BUFP_BOUND, &sk->status) ||
+           __test_and_set_bit(_BUFP_BINDING, &sk->status))
+               ret = -EADDRINUSE;
+       rtdm_atomic_leave(s);
+       
        if (ret)
                return ret;
 
@@ -718,10 +720,10 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
                }
        }
 
-       RTDM_EXECUTE_ATOMICALLY(
-               __clear_bit(_BUFP_BINDING, &sk->status);
-               __set_bit(_BUFP_BOUND, &sk->status);
-       );
+       rtdm_atomic_enter(s);
+       __clear_bit(_BUFP_BINDING, &sk->status);
+       __set_bit(_BUFP_BOUND, &sk->status);
+       rtdm_atomic_leave(s);
 
        return 0;
 fail:
@@ -737,6 +739,7 @@ static int __bufp_connect_socket(struct bufp_socket *sk,
        struct bufp_socket *rsk;
        xnhandle_t h;
        int ret;
+       spl_t s;
 
        if (sa == NULL) {
                sa = &nullsa;
@@ -772,26 +775,26 @@ static int __bufp_connect_socket(struct bufp_socket *sk,
                if (ret)
                        return ret;
 
-               RTDM_EXECUTE_ATOMICALLY(
-                       rsk = xnregistry_lookup(h, NULL);
-                       if (rsk == NULL || rsk->magic != BUFP_SOCKET_MAGIC)
-                               ret = -EINVAL;
-                       else
-                               /* Fetch labeled port number. */
-                               sa->sipc_port = rsk->name.sipc_port;
-               );
+               rtdm_atomic_enter(s);
+               rsk = xnregistry_lookup(h, NULL);
+               if (rsk == NULL || rsk->magic != BUFP_SOCKET_MAGIC)
+                       ret = -EINVAL;
+               else
+                       /* Fetch labeled port number. */
+                       sa->sipc_port = rsk->name.sipc_port;
+               rtdm_atomic_leave(s);
                if (ret)
                        return ret;
        }
 
 set_assoc:
-       RTDM_EXECUTE_ATOMICALLY(
-               if (!test_bit(_BUFP_BOUND, &sk->status))
-                       /* Set default name. */
-                       sk->name = *sa;
-               /* Set default destination. */
-               sk->peer = *sa;
-       );
+       rtdm_atomic_enter(s);
+       if (!test_bit(_BUFP_BOUND, &sk->status))
+               /* Set default name. */
+               sk->name = *sa;
+       /* Set default destination. */
+       sk->peer = *sa;
+       rtdm_atomic_leave(s);
 
        return 0;
 }
@@ -805,6 +808,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
        struct timeval tv;
        int ret = 0;
        size_t len;
+       spl_t s;
 
        if (rtipc_get_arg(user_info, &sopt, arg, sizeof(sopt)))
                return -EFAULT;
@@ -850,17 +854,17 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
                        return -EFAULT;
                if (len == 0)
                        return -EINVAL;
-               RTDM_EXECUTE_ATOMICALLY(
-                       /*
-                        * We may not do this more than once, and we
-                        * have to do this before the first binding.
-                        */
-                       if (test_bit(_BUFP_BOUND, &sk->status) ||
-                           test_bit(_BUFP_BINDING, &sk->status))
-                               ret = -EALREADY;
-                       else
-                               sk->bufsz = len;
-               );
+               rtdm_atomic_enter(s);
+               /*
+                * We may not do this more than once, and we have to
+                * do this before the first binding.
+                */
+               if (test_bit(_BUFP_BOUND, &sk->status) ||
+                   test_bit(_BUFP_BINDING, &sk->status))
+                       ret = -EALREADY;
+               else
+                       sk->bufsz = len;
+               rtdm_atomic_leave(s);
                break;
 
        case BUFP_LABEL:
@@ -869,18 +873,18 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
                if (rtipc_get_arg(user_info, &plabel,
                                  sopt.optval, sizeof(plabel)))
                        return -EFAULT;
-               RTDM_EXECUTE_ATOMICALLY(
-                       /*
-                        * We may attach a label to a client socket
-                        * which was previously bound in BUFP.
-                        */
-                       if (test_bit(_BUFP_BINDING, &sk->status))
-                               ret = -EALREADY;
-                       else {
-                               strcpy(sk->label, plabel.label);
-                               sk->label[XNOBJECT_NAME_LEN-1] = 0;
-                       }
-               );
+               rtdm_atomic_enter(s);
+               /*
+                * We may attach a label to a client socket which was
+                * previously bound in BUFP.
+                */
+               if (test_bit(_BUFP_BINDING, &sk->status))
+                       ret = -EALREADY;
+               else {
+                       strcpy(sk->label, plabel.label);
+                       sk->label[XNOBJECT_NAME_LEN-1] = 0;
+               }
+               rtdm_atomic_leave(s);
                break;
 
        default:
@@ -899,6 +903,7 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
        struct timeval tv;
        socklen_t len;
        int ret = 0;
+       spl_t s;
 
        if (rtipc_get_arg(user_info, &sopt, arg, sizeof(sopt)))
                return -EFAULT;
@@ -942,9 +947,9 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
        case BUFP_LABEL:
                if (len < sizeof(plabel))
                        return -EINVAL;
-               RTDM_EXECUTE_ATOMICALLY(
-                       strcpy(plabel.label, sk->label);
-               );
+               rtdm_atomic_enter(s);
+               strcpy(plabel.label, sk->label);
+               rtdm_atomic_leave(s);
                if (rtipc_put_arg(user_info, sopt.optval,
                                  &plabel, sizeof(plabel)))
                        return -EFAULT;
diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index cd2d7c8..40a855f 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -44,24 +44,19 @@ struct iddp_socket {
        int magic;
        struct sockaddr_ipc name;
        struct sockaddr_ipc peer;
-
        struct xnheap *bufpool;
        struct xnheap privpool;
-       rtdm_event_t *poolevt;
-       rtdm_event_t privevt;
-       int *poolwait;
-       int privwait;
+       rtdm_waitqueue_t *poolwaitq;
+       rtdm_waitqueue_t privwaitq;
        size_t poolsz;
        rtdm_sem_t insem;
        struct list_head inq;
        u_long status;
        xnhandle_t handle;
        char label[XNOBJECT_NAME_LEN];
-
        nanosecs_rel_t rx_timeout;
        nanosecs_rel_t tx_timeout;
        unsigned long stalls;   /* Buffer stall counter. */
-
        struct rtipc_private *priv;
 };
 
@@ -72,9 +67,7 @@ static struct sockaddr_ipc nullsa = {
 
 static struct xnmap *portmap;
 
-static rtdm_event_t poolevt;
-
-static int poolwait;
+static rtdm_waitqueue_t poolwaitq;
 
 #define _IDDP_BINDING  0
 #define _IDDP_BOUND    1
@@ -131,6 +124,7 @@ __iddp_alloc_mbuf(struct iddp_socket *sk, size_t len,
        struct iddp_message *mbuf = NULL;
        rtdm_toseq_t timeout_seq;
        int ret = 0;
+       spl_t s;
 
        rtdm_toseq_init(&timeout_seq, timeout);
 
@@ -151,20 +145,12 @@ __iddp_alloc_mbuf(struct iddp_socket *sk, size_t len,
                 * memory pressure on the pool, but in this case, the
                 * pool size should be adjusted.
                 */
-               RTDM_EXECUTE_ATOMICALLY(
-                       /*
-                        * membars are implicitly issued when required
-                        * by this construct.
-                        */
-                       ++sk->stalls;
-                       (*sk->poolwait)++;
-                       ret = rtdm_event_timedwait(sk->poolevt,
-                                                  timeout,
-                                                  &timeout_seq);
-                       (*sk->poolwait)--;
-                       if (unlikely(ret == -EIDRM))
-                               ret = -ECONNRESET;
-               );
+               rtdm_waitqueue_lock(sk->poolwaitq, s);
+               ++sk->stalls;
+               ret = rtdm_timedwait_locked(sk->poolwaitq, timeout, 
&timeout_seq);
+               rtdm_waitqueue_unlock(sk->poolwaitq, s);
+               if (unlikely(ret == -EIDRM))
+                       ret = -ECONNRESET;
                if (ret)
                        break;
        }
@@ -178,11 +164,7 @@ static void __iddp_free_mbuf(struct iddp_socket *sk,
                             struct iddp_message *mbuf)
 {
        xnheap_free(sk->bufpool, mbuf);
-       RTDM_EXECUTE_ATOMICALLY(
-               /* Wake up sleepers if any. */
-               if (*sk->poolwait > 0)
-                       rtdm_event_pulse(sk->poolevt);
-       );
+       rtdm_waitqueue_broadcast(sk->poolwaitq);
 }
 
 static void __iddp_flush_pool(struct xnheap *heap,
@@ -200,8 +182,7 @@ static int iddp_socket(struct rtipc_private *priv,
        sk->name = nullsa;      /* Unbound */
        sk->peer = nullsa;
        sk->bufpool = &kheap;
-       sk->poolevt = &poolevt;
-       sk->poolwait = &poolwait;
+       sk->poolwaitq = &poolwaitq;
        sk->poolsz = 0;
        sk->status = 0;
        sk->handle = 0;
@@ -211,7 +192,7 @@ static int iddp_socket(struct rtipc_private *priv,
        *sk->label = 0;
        INIT_LIST_HEAD(&sk->inq);
        rtdm_sem_init(&sk->insem, 0);
-       rtdm_event_init(&sk->privevt, 0);
+       rtdm_waitqueue_init(&sk->privwaitq);
        sk->priv = priv;
 
        return 0;
@@ -227,7 +208,7 @@ static int iddp_close(struct rtipc_private *priv,
                xnmap_remove(portmap, sk->name.sipc_port);
 
        rtdm_sem_destroy(&sk->insem);
-       rtdm_event_destroy(&sk->privevt);
+       rtdm_waitqueue_destroy(&sk->privwaitq);
 
        if (sk->handle)
                xnregistry_remove(sk->handle);
@@ -256,10 +237,12 @@ static ssize_t __iddp_recvmsg(struct rtipc_private *priv,
 {
        struct iddp_socket *sk = priv->state;
        ssize_t maxlen, len, wrlen, vlen;
+       rtdm_toseq_t timeout_seq, *toseq;
        int nvec, rdoff, ret, dofree;
        struct iddp_message *mbuf;
        nanosecs_rel_t timeout;
        struct xnbufd bufd;
+       spl_t s;
 
        if (!test_bit(_IDDP_BOUND, &sk->status))
                return -EAGAIN;
@@ -268,35 +251,51 @@ static ssize_t __iddp_recvmsg(struct rtipc_private *priv,
        if (maxlen == 0)
                return 0;
 
-       /* We want to pick one buffer from the queue. */
-       timeout = (flags & MSG_DONTWAIT) ? RTDM_TIMEOUT_NONE : sk->rx_timeout;
-       ret = rtdm_sem_timeddown(&sk->insem, timeout, NULL);
-       if (unlikely(ret)) {
-               if (ret == -EIDRM)
-                       return -ECONNRESET;
-               return ret;
+       if (flags & MSG_DONTWAIT) {
+               timeout = RTDM_TIMEOUT_NONE;
+               toseq = NULL;
+       } else {
+               timeout = sk->rx_timeout;
+               toseq = &timeout_seq;
        }
 
-       RTDM_EXECUTE_ATOMICALLY(
-               /* Pull heading message from input queue. */
-               mbuf = list_entry(sk->inq.next, struct iddp_message, next);
-               rdoff = mbuf->rdoff;
-               len = mbuf->len - rdoff;
-               if (saddr) {
-                       saddr->sipc_family = AF_RTIPC;
-                       saddr->sipc_port = mbuf->from;
-               }
-               if (maxlen >= len) {
-                       list_del(&mbuf->next);
-                       dofree = 1;
-               } else {
-                       /* Buffer is only partially read: repost. */
-                       mbuf->rdoff += maxlen;
-                       len = maxlen;
-                       dofree = 0;
-                       rtdm_sem_up(&sk->insem);
+       /* We want to pick one buffer from the queue. */
+       
+       for (;;) {
+               ret = rtdm_sem_timeddown(&sk->insem, timeout, toseq);
+               if (unlikely(ret)) {
+                       if (ret == -EIDRM)
+                               return -ECONNRESET;
+                       return ret;
                }
-       );
+               /* We may have spurious wakeups. */
+               rtdm_atomic_enter(s);
+               if (!list_empty(&sk->inq))
+                       break;
+               rtdm_atomic_leave(s);
+       }
+
+       /* Pull heading message from input queue. */
+       mbuf = list_entry(sk->inq.next, struct iddp_message, next);
+       rdoff = mbuf->rdoff;
+       len = mbuf->len - rdoff;
+       if (saddr) {
+               saddr->sipc_family = AF_RTIPC;
+               saddr->sipc_port = mbuf->from;
+       }
+       if (maxlen >= len) {
+               list_del(&mbuf->next);
+               dofree = 1;
+       } else {
+               /* Buffer is only partially read: repost. */
+               mbuf->rdoff += maxlen;
+               len = maxlen;
+               dofree = 0;
+       }
+       rtdm_atomic_leave(s);
+
+       if (!dofree)
+               rtdm_sem_up(&sk->insem);
 
        /* Now, write "len" bytes from mbuf->data to the vector cells */
        for (nvec = 0, wrlen = len; nvec < iovlen && wrlen > 0; nvec++) {
@@ -392,6 +391,7 @@ static ssize_t __iddp_sendmsg(struct rtipc_private *priv,
        int nvec, wroff, ret;
        struct xnbufd bufd;
        void *p;
+       spl_t s;
 
        len = rtipc_get_iov_flatlen(iov, iovlen);
        if (len == 0)
@@ -440,14 +440,14 @@ static ssize_t __iddp_sendmsg(struct rtipc_private *priv,
                wroff += vlen;
        }
 
-       RTDM_EXECUTE_ATOMICALLY(
-               mbuf->from = sk->name.sipc_port;
-               if (flags & MSG_OOB)
-                       list_add(&mbuf->next, &rsk->inq);
-               else
-                       list_add_tail(&mbuf->next, &rsk->inq);
-               rtdm_sem_up(&rsk->insem);
-       );
+       rtdm_atomic_enter(s);
+       mbuf->from = sk->name.sipc_port;
+       if (flags & MSG_OOB)
+               list_add(&mbuf->next, &rsk->inq);
+       else
+               list_add_tail(&mbuf->next, &rsk->inq);
+       rtdm_atomic_leave(s);
+       rtdm_sem_up(&rsk->insem);
 
        rtdm_context_unlock(rcontext);
 
@@ -534,6 +534,7 @@ static int __iddp_bind_socket(struct rtipc_private *priv,
        int ret = 0, port, fd;
        void *poolmem;
        size_t poolsz;
+       spl_t s;
 
        if (sa->sipc_family != AF_RTIPC)
                return -EINVAL;
@@ -542,11 +543,11 @@ static int __iddp_bind_socket(struct rtipc_private *priv,
            sa->sipc_port >= CONFIG_XENO_OPT_IDDP_NRPORT)
                return -EINVAL;
 
-       RTDM_EXECUTE_ATOMICALLY(
-               if (test_bit(_IDDP_BOUND, &sk->status) ||
-                   __test_and_set_bit(_IDDP_BINDING, &sk->status))
-                       ret = -EADDRINUSE;
-       );
+       rtdm_atomic_enter(s);
+       if (test_bit(_IDDP_BOUND, &sk->status) ||
+           __test_and_set_bit(_IDDP_BINDING, &sk->status))
+               ret = -EADDRINUSE;
+       rtdm_atomic_leave(s);
        if (ret)
                return ret;
 
@@ -580,8 +581,7 @@ static int __iddp_bind_socket(struct rtipc_private *priv,
                }
                xnheap_set_label(&sk->privpool, "ippd: %d", port);
 
-               sk->poolevt = &sk->privevt;
-               sk->poolwait = &sk->privwait;
+               sk->poolwaitq = &sk->privwaitq;
                sk->bufpool = &sk->privpool;
        }
 
@@ -601,10 +601,10 @@ static int __iddp_bind_socket(struct rtipc_private *priv,
                }
        }
 
-       RTDM_EXECUTE_ATOMICALLY(
-               __clear_bit(_IDDP_BINDING, &sk->status);
-               __set_bit(_IDDP_BOUND, &sk->status);
-       );
+       rtdm_atomic_enter(s);
+       __clear_bit(_IDDP_BINDING, &sk->status);
+       __set_bit(_IDDP_BOUND, &sk->status);
+       rtdm_atomic_leave(s);
 
        return 0;
 fail:
@@ -620,6 +620,7 @@ static int __iddp_connect_socket(struct iddp_socket *sk,
        struct iddp_socket *rsk;
        xnhandle_t h;
        int ret;
+       spl_t s;
 
        if (sa == NULL) {
                sa = &nullsa;
@@ -655,26 +656,26 @@ static int __iddp_connect_socket(struct iddp_socket *sk,
                if (ret)
                        return ret;
 
-               RTDM_EXECUTE_ATOMICALLY(
-                       rsk = xnregistry_lookup(h, NULL);
-                       if (rsk == NULL || rsk->magic != IDDP_SOCKET_MAGIC)
-                               ret = -EINVAL;
-                       else
-                               /* Fetch labeled port number. */
-                               sa->sipc_port = rsk->name.sipc_port;
-               );
+               rtdm_atomic_enter(s);
+               rsk = xnregistry_lookup(h, NULL);
+               if (rsk == NULL || rsk->magic != IDDP_SOCKET_MAGIC)
+                       ret = -EINVAL;
+               else
+                       /* Fetch labeled port number. */
+                       sa->sipc_port = rsk->name.sipc_port;
+               rtdm_atomic_leave(s);
                if (ret)
                        return ret;
        }
 
 set_assoc:
-       RTDM_EXECUTE_ATOMICALLY(
-               if (!test_bit(_IDDP_BOUND, &sk->status))
-                       /* Set default name. */
-                       sk->name = *sa;
-               /* Set default destination. */
-               sk->peer = *sa;
-       );
+       rtdm_atomic_enter(s);
+       if (!test_bit(_IDDP_BOUND, &sk->status))
+               /* Set default name. */
+               sk->name = *sa;
+       /* Set default destination. */
+       sk->peer = *sa;
+       rtdm_atomic_leave(s);
 
        return 0;
 }
@@ -688,6 +689,7 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
        struct timeval tv;
        int ret = 0;
        size_t len;
+       spl_t s;
 
        if (rtipc_get_arg(user_info, &sopt, arg, sizeof(sopt)))
                return -EFAULT;
@@ -733,17 +735,17 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
                        return -EFAULT;
                if (len == 0)
                        return -EINVAL;
-               RTDM_EXECUTE_ATOMICALLY(
-                       /*
-                        * We may not do this more than once, and we
-                        * have to do this before the first binding.
-                        */
-                       if (test_bit(_IDDP_BOUND, &sk->status) ||
-                           test_bit(_IDDP_BINDING, &sk->status))
-                               ret = -EALREADY;
-                       else
-                               sk->poolsz = len;
-               );
+               rtdm_atomic_enter(s);
+               /*
+                * We may not do this more than once, and we have to
+                * do this before the first binding.
+                */
+               if (test_bit(_IDDP_BOUND, &sk->status) ||
+                   test_bit(_IDDP_BINDING, &sk->status))
+                       ret = -EALREADY;
+               else
+                       sk->poolsz = len;
+               rtdm_atomic_leave(s);
                break;
 
        case IDDP_LABEL:
@@ -752,18 +754,18 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
                if (rtipc_get_arg(user_info, &plabel,
                                  sopt.optval, sizeof(plabel)))
                        return -EFAULT;
-               RTDM_EXECUTE_ATOMICALLY(
-                       /*
-                        * We may attach a label to a client socket
-                        * which was previously bound in IDDP.
-                        */
-                       if (test_bit(_IDDP_BINDING, &sk->status))
-                               ret = -EALREADY;
-                       else {
-                               strcpy(sk->label, plabel.label);
-                               sk->label[XNOBJECT_NAME_LEN-1] = 0;
-                       }
-               );
+               rtdm_atomic_enter(s);
+               /*
+                * We may attach a label to a client socket which was
+                * previously bound in IDDP.
+                */
+               if (test_bit(_IDDP_BINDING, &sk->status))
+                       ret = -EALREADY;
+               else {
+                       strcpy(sk->label, plabel.label);
+                       sk->label[XNOBJECT_NAME_LEN-1] = 0;
+               }
+               rtdm_atomic_leave(s);
                break;
 
        default:
@@ -782,6 +784,7 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
        struct timeval tv;
        socklen_t len;
        int ret = 0;
+       spl_t s;
 
        if (rtipc_get_arg(user_info, &sopt, arg, sizeof(sopt)))
                return -EFAULT;
@@ -825,9 +828,9 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
        case IDDP_LABEL:
                if (len < sizeof(plabel))
                        return -EINVAL;
-               RTDM_EXECUTE_ATOMICALLY(
-                       strcpy(plabel.label, sk->label);
-               );
+               rtdm_atomic_enter(s);
+               strcpy(plabel.label, sk->label);
+               rtdm_atomic_leave(s);
                if (rtipc_put_arg(user_info, sopt.optval,
                                  &plabel, sizeof(plabel)))
                        return -EFAULT;
@@ -914,14 +917,14 @@ static int iddp_init(void)
        if (portmap == NULL)
                return -ENOMEM;
 
-       rtdm_event_init(&poolevt, 0);
+       rtdm_waitqueue_init(&poolwaitq);
 
        return 0;
 }
 
 static void iddp_exit(void)
 {
-       rtdm_event_destroy(&poolevt);
+       rtdm_waitqueue_destroy(&poolwaitq);
        xnmap_delete(portmap);
 }
 
diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
index 728a6ed..b05f714 100644
--- a/kernel/drivers/ipc/xddp.c
+++ b/kernel/drivers/ipc/xddp.c
@@ -665,6 +665,7 @@ static int __xddp_bind_socket(struct rtipc_private *priv,
        size_t poolsz;
        void *poolmem;
        int ret = 0;
+       spl_t s;
 
        if (sa->sipc_family != AF_RTIPC)
                return -EINVAL;
@@ -674,11 +675,11 @@ static int __xddp_bind_socket(struct rtipc_private *priv,
            sa->sipc_port >= CONFIG_XENO_OPT_PIPE_NRDEV)
                return -EINVAL;
 
-       RTDM_EXECUTE_ATOMICALLY(
-               if (test_bit(_XDDP_BOUND, &sk->status) ||
-                   __test_and_set_bit(_XDDP_BINDING, &sk->status))
-                       ret = -EADDRINUSE;
-       );
+       rtdm_atomic_enter(s);
+       if (test_bit(_XDDP_BOUND, &sk->status) ||
+           __test_and_set_bit(_XDDP_BINDING, &sk->status))
+               ret = -EADDRINUSE;
+       rtdm_atomic_leave(s);
        if (ret)
                return ret;
 
@@ -752,11 +753,11 @@ static int __xddp_bind_socket(struct rtipc_private *priv,
                }
        }
 
-       RTDM_EXECUTE_ATOMICALLY(
-               portmap[sk->minor] = sk->fd;
-               __clear_bit(_XDDP_BINDING, &sk->status);
-               __set_bit(_XDDP_BOUND, &sk->status);
-       );
+       rtdm_atomic_enter(s);
+       portmap[sk->minor] = sk->fd;
+       __clear_bit(_XDDP_BINDING, &sk->status);
+       __set_bit(_XDDP_BOUND, &sk->status);
+       rtdm_atomic_leave(s);
 
        return 0;
 }
@@ -767,6 +768,7 @@ static int __xddp_connect_socket(struct xddp_socket *sk,
        struct xddp_socket *rsk;
        xnhandle_t h;
        int ret;
+       spl_t s;
 
        if (sa == NULL) {
                sa = &nullsa;
@@ -802,26 +804,26 @@ static int __xddp_connect_socket(struct xddp_socket *sk,
                if (ret)
                        return ret;
 
-               RTDM_EXECUTE_ATOMICALLY(
-                       rsk = xnregistry_lookup(h, NULL);
-                       if (rsk == NULL || rsk->magic != XDDP_SOCKET_MAGIC)
-                               ret = -EINVAL;
-                       else
-                               /* Fetch labeled port number. */
-                               sa->sipc_port = rsk->minor;
-               );
+               rtdm_atomic_enter(s);
+               rsk = xnregistry_lookup(h, NULL);
+               if (rsk == NULL || rsk->magic != XDDP_SOCKET_MAGIC)
+                       ret = -EINVAL;
+               else
+                       /* Fetch labeled port number. */
+                       sa->sipc_port = rsk->minor;
+               rtdm_atomic_leave(s);
                if (ret)
                        return ret;
        }
 
 set_assoc:
-       RTDM_EXECUTE_ATOMICALLY(
-               if (!test_bit(_XDDP_BOUND, &sk->status))
-                       /* Set default name. */
-                       sk->name = *sa;
-               /* Set default destination. */
-               sk->peer = *sa;
-       );
+       rtdm_atomic_enter(s);
+       if (!test_bit(_XDDP_BOUND, &sk->status))
+               /* Set default name. */
+               sk->name = *sa;
+       /* Set default destination. */
+       sk->peer = *sa;
+       rtdm_atomic_leave(s);
 
        return 0;
 }
@@ -837,6 +839,7 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
        struct timeval tv;
        int ret = 0;
        size_t len;
+       spl_t s;
 
        if (rtipc_get_arg(user_info, &sopt, arg, sizeof(sopt)))
                return -EFAULT;
@@ -895,13 +898,13 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
                        return -EFAULT;
                if (len == 0)
                        return -EINVAL;
-               RTDM_EXECUTE_ATOMICALLY(
-                       if (test_bit(_XDDP_BOUND, &sk->status) ||
-                           test_bit(_XDDP_BINDING, &sk->status))
-                               ret = -EALREADY;
-                       else
-                               sk->poolsz = len;
-               );
+               rtdm_atomic_enter(s);
+               if (test_bit(_XDDP_BOUND, &sk->status) ||
+                   test_bit(_XDDP_BINDING, &sk->status))
+                       ret = -EALREADY;
+               else
+                       sk->poolsz = len;
+               rtdm_atomic_leave(s);
                break;
 
        case XDDP_MONITOR:
@@ -922,15 +925,15 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
                if (rtipc_get_arg(user_info, &plabel,
                                  sopt.optval, sizeof(plabel)))
                        return -EFAULT;
-               RTDM_EXECUTE_ATOMICALLY(
-                       if (test_bit(_XDDP_BOUND, &sk->status) ||
-                           test_bit(_XDDP_BINDING, &sk->status))
-                               ret = -EALREADY;
-                       else {
-                               strcpy(sk->label, plabel.label);
-                               sk->label[XNOBJECT_NAME_LEN-1] = 0;
-                       }
-               );
+               rtdm_atomic_enter(s);
+               if (test_bit(_XDDP_BOUND, &sk->status) ||
+                   test_bit(_XDDP_BINDING, &sk->status))
+                       ret = -EALREADY;
+               else {
+                       strcpy(sk->label, plabel.label);
+                       sk->label[XNOBJECT_NAME_LEN-1] = 0;
+               }
+               rtdm_atomic_leave(s);
                break;
 
        default:
@@ -949,6 +952,7 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
        struct timeval tv;
        socklen_t len;
        int ret = 0;
+       spl_t s;
 
        if (rtipc_get_arg(user_info, &sopt, arg, sizeof(sopt)))
                return -EFAULT;
@@ -983,9 +987,9 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
        case XDDP_LABEL:
                if (len < sizeof(plabel))
                        return -EINVAL;
-               RTDM_EXECUTE_ATOMICALLY(
-                       strcpy(plabel.label, sk->label);
-               );
+               rtdm_atomic_enter(s);
+               strcpy(plabel.label, sk->label);
+               rtdm_atomic_leave(s);
                if (rtipc_put_arg(user_info, sopt.optval,
                                  &plabel, sizeof(plabel)))
                        return -EFAULT;


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

Reply via email to