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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Nov 20 17:53:26 2011 +0100

alchemy: fail upon calls from async context with blocking timeouts

To help debugging, we want to trap calls to Alchemy services from
asynchronous contexts which ask for a blocking timeout (i.e. !=
TM_NONBLOCK).

All existing checks are fixed in a way which triggers -EPERM early in
such situation, despite the relevant services might not have to block
to satisfy the request.

---

 lib/alchemy/buffer.c |   16 ++++++----------
 lib/alchemy/event.c  |    8 +++-----
 lib/alchemy/heap.c   |    7 +------
 lib/alchemy/pipe.c   |    5 +----
 lib/alchemy/queue.c  |    8 +++-----
 5 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c
index 2a17fae..07f34f8 100644
--- a/lib/alchemy/buffer.c
+++ b/lib/alchemy/buffer.c
@@ -180,6 +180,9 @@ ssize_t rt_buffer_read_until(RT_BUFFER *bf,
        if (len == 0)
                return 0;
 
+       if (timeout != TM_NONBLOCK && !threadobj_current_p())
+               return -EPERM;
+
        COPPERPLATE_PROTECT(svc);
 
        bcb = get_alchemy_buffer(bf, &syns, &ret);
@@ -244,11 +247,6 @@ redo:
                        goto done;
                }
 
-               if (!threadobj_current_p()) {
-                       ret = -EPERM;
-                       goto done;
-               }
-
                /*
                 * Check whether writers are already waiting for
                 * sending data, while we are about to wait for
@@ -310,6 +308,9 @@ ssize_t rt_buffer_write_until(RT_BUFFER *bf,
        if (len == 0)
                return 0;
 
+       if (timeout != TM_NONBLOCK && !threadobj_current_p())
+               return -EPERM;
+
        COPPERPLATE_PROTECT(svc);
 
        bcb = get_alchemy_buffer(bf, &syns, &ret);
@@ -374,11 +375,6 @@ ssize_t rt_buffer_write_until(RT_BUFFER *bf,
                        goto done;
                }
 
-               if (!threadobj_current_p()) {
-                       ret = -EPERM;
-                       goto done;
-               }
-
                if (wait == NULL) {
                        timespec = alchemy_get_timespec(timeout, &ts);
                        wait = threadobj_prepare_wait(struct 
alchemy_buffer_wait);
diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c
index b10f8bc..a793772 100644
--- a/lib/alchemy/event.c
+++ b/lib/alchemy/event.c
@@ -150,6 +150,9 @@ int rt_event_wait_until(RT_EVENT *event,
        struct service svc;
        int ret = 0;
 
+       if (timeout != TM_NONBLOCK && !threadobj_current_p())
+               return -EPERM;
+
        COPPERPLATE_PROTECT(svc);
 
        evcb = get_alchemy_event(event, &syns, &ret);
@@ -173,11 +176,6 @@ int rt_event_wait_until(RT_EVENT *event,
                goto done;
        }
 
-       if (!threadobj_current_p()) {
-               ret = -EPERM;
-               goto done;
-       }
-
        wait = threadobj_prepare_wait(struct alchemy_event_wait);
        wait->mask = mask;
        wait->mode = mode;
diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c
index ca1a525..85e9c2f 100644
--- a/lib/alchemy/heap.c
+++ b/lib/alchemy/heap.c
@@ -165,7 +165,7 @@ int rt_heap_alloc(RT_HEAP *heap,
        void *p = NULL;
        int ret = 0;
 
-       if (threadobj_irq_p())
+       if (timeout != TM_NONBLOCK && !threadobj_current_p())
                return -EPERM;
 
        COPPERPLATE_PROTECT(svc);
@@ -200,11 +200,6 @@ int rt_heap_alloc(RT_HEAP *heap,
                goto done;
        }
 
-       if (!threadobj_current_p()) {
-               ret = -EPERM;
-               goto done;
-       }
-
        timespec = alchemy_get_timespec(timeout, &ts);
 
        wait = threadobj_prepare_wait(struct alchemy_heap_wait);
diff --git a/lib/alchemy/pipe.c b/lib/alchemy/pipe.c
index 417e451..1315f21 100644
--- a/lib/alchemy/pipe.c
+++ b/lib/alchemy/pipe.c
@@ -179,7 +179,7 @@ ssize_t rt_pipe_read_until(RT_PIPE *pipe,
        int err, flags;
        ssize_t ret;
 
-       if (!threadobj_current_p())
+       if (timeout != TM_NONBLOCK && !threadobj_current_p())
                return -EPERM;
 
        COPPERPLATE_PROTECT(svc);
@@ -230,9 +230,6 @@ static ssize_t do_write_pipe(RT_PIPE *pipe,
        ssize_t ret;
        int err;
 
-       if (threadobj_irq_p())
-               return -EPERM;
-
        COPPERPLATE_PROTECT(svc);
 
        pcb = find_alchemy_pipe(pipe, &err);
diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 33d17d5..4b80983 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -332,6 +332,9 @@ ssize_t rt_queue_receive_until(RT_QUEUE *queue,
        ssize_t ret;
        int err = 0;
 
+       if (timeout != TM_NONBLOCK && !threadobj_current_p())
+               return -EPERM;
+
        COPPERPLATE_PROTECT(svc);
 
        qcb = get_alchemy_queue(queue, &syns, &err);
@@ -354,11 +357,6 @@ ssize_t rt_queue_receive_until(RT_QUEUE *queue,
                goto done;
        }
 
-       if (!threadobj_current_p()) {
-               ret = -EPERM;
-               goto done;
-       }
-
        wait = threadobj_prepare_wait(struct alchemy_queue_wait);
        timespec = alchemy_get_timespec(timeout, &ts);
 


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

Reply via email to