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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Nov 19 14:39:08 2011 +0100

alchemy: send -EINVAL upon request on invalid/dead object

For clarity, -EIDRM is only returned by blocking services when the
object was killed while pending at it. Otherwise, Alchemy calls always
return -EINVAL when the object was invalid on entry.

---

 lib/alchemy/alarm.c  |   10 +---------
 lib/alchemy/buffer.c |   10 +---------
 lib/alchemy/cond.c   |    7 +------
 lib/alchemy/event.c  |   10 +---------
 lib/alchemy/heap.c   |   10 +---------
 lib/alchemy/mutex.c  |    7 +------
 lib/alchemy/pipe.c   |    7 -------
 lib/alchemy/queue.c  |   10 +---------
 lib/alchemy/sem.c    |    7 -------
 lib/alchemy/task.c   |   12 ++++--------
 10 files changed, 11 insertions(+), 79 deletions(-)

diff --git a/lib/alchemy/alarm.c b/lib/alchemy/alarm.c
index c86fc6d..785e04a 100644
--- a/lib/alchemy/alarm.c
+++ b/lib/alchemy/alarm.c
@@ -43,9 +43,6 @@ static struct alchemy_alarm *get_alchemy_alarm(RT_ALARM 
*alarm, int *err_r)
        if (acb == NULL || ((intptr_t)acb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (acb->magic == ~alarm_magic)
-               goto dead_handle;
-
        if (acb->magic != alarm_magic)
                goto bad_handle;
 
@@ -55,14 +52,9 @@ static struct alchemy_alarm *get_alchemy_alarm(RT_ALARM 
*alarm, int *err_r)
        /* Recheck under lock. */
        if (acb->magic == alarm_magic)
                return acb;
-
-dead_handle:
-       /* Removed under our feet. */
-       *err_r = -EIDRM;
-       return NULL;
-
 bad_handle:
        *err_r = -EINVAL;
+
        return NULL;
 }
 
diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c
index f0d03a6..2a17fae 100644
--- a/lib/alchemy/buffer.c
+++ b/lib/alchemy/buffer.c
@@ -44,9 +44,6 @@ static struct alchemy_buffer *get_alchemy_buffer(RT_BUFFER 
*bf,
        if (bcb == NULL || ((intptr_t)bcb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (bcb->magic == ~buffer_magic)
-               goto dead_handle;
-
        if (bcb->magic != buffer_magic)
                goto bad_handle;
 
@@ -56,14 +53,9 @@ static struct alchemy_buffer *get_alchemy_buffer(RT_BUFFER 
*bf,
        /* Recheck under lock. */
        if (bcb->magic == buffer_magic)
                return bcb;
-
-dead_handle:
-       /* Removed under our feet. */
-       *err_r = -EIDRM;
-       return NULL;
-
 bad_handle:
        *err_r = -EINVAL;
+
        return NULL;
 }
 
diff --git a/lib/alchemy/cond.c b/lib/alchemy/cond.c
index 5d3a6ba..3dedfbb 100644
--- a/lib/alchemy/cond.c
+++ b/lib/alchemy/cond.c
@@ -48,16 +48,11 @@ static struct alchemy_cond *find_alchemy_cond(RT_COND 
*cond, int *err_r)
        if (ccb == NULL || ((intptr_t)ccb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (ccb->magic == ~cond_magic) {
-               *err_r = -EIDRM;
-               return NULL;
-       }
-
        if (ccb->magic == cond_magic)
                return ccb;
-
 bad_handle:
        *err_r = -EINVAL;
+
        return NULL;
 }
 
diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c
index fa8a98f..b10f8bc 100644
--- a/lib/alchemy/event.c
+++ b/lib/alchemy/event.c
@@ -44,9 +44,6 @@ static struct alchemy_event *get_alchemy_event(RT_EVENT 
*event,
        if (evcb == NULL || ((intptr_t)evcb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (evcb->magic == ~event_magic)
-               goto dead_handle;
-
        if (evcb->magic != event_magic)
                goto bad_handle;
 
@@ -56,14 +53,9 @@ static struct alchemy_event *get_alchemy_event(RT_EVENT 
*event,
        /* Recheck under lock. */
        if (evcb->magic == event_magic)
                return evcb;
-
-dead_handle:
-       /* Removed under our feet. */
-       *err_r = -EIDRM;
-       return NULL;
-
 bad_handle:
        *err_r = -EINVAL;
+
        return NULL;
 }
 
diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c
index f09b028..ca1a525 100644
--- a/lib/alchemy/heap.c
+++ b/lib/alchemy/heap.c
@@ -44,9 +44,6 @@ static struct alchemy_heap *get_alchemy_heap(RT_HEAP *heap,
        if (hcb == NULL || ((intptr_t)hcb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (hcb->magic == ~heap_magic)
-               goto dead_handle;
-
        if (hcb->magic != heap_magic)
                goto bad_handle;
 
@@ -56,14 +53,9 @@ static struct alchemy_heap *get_alchemy_heap(RT_HEAP *heap,
        /* Recheck under lock. */
        if (hcb->magic == heap_magic)
                return hcb;
-
-dead_handle:
-       /* Removed under our feet. */
-       *err_r = -EIDRM;
-       return NULL;
-
 bad_handle:
        *err_r = -EINVAL;
+
        return NULL;
 }
 
diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c
index 91a54d7..ee3fc96 100644
--- a/lib/alchemy/mutex.c
+++ b/lib/alchemy/mutex.c
@@ -48,16 +48,11 @@ struct alchemy_mutex *find_alchemy_mutex(RT_MUTEX *mutex, 
int *err_r)
        if (mcb == NULL || ((intptr_t)mcb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (mcb->magic == ~mutex_magic) {
-               *err_r = -EIDRM;
-               return NULL;
-       }
-
        if (mcb->magic == mutex_magic)
                return mcb;
-
 bad_handle:
        *err_r = -EINVAL;
+
        return NULL;
 }
 
diff --git a/lib/alchemy/pipe.c b/lib/alchemy/pipe.c
index 2bd2de5..417e451 100644
--- a/lib/alchemy/pipe.c
+++ b/lib/alchemy/pipe.c
@@ -47,18 +47,11 @@ static struct alchemy_pipe *find_alchemy_pipe(RT_PIPE 
*pipe, int *err_r)
        if (pcb == NULL || ((intptr_t)pcb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (pcb->magic == ~pipe_magic)
-               goto dead_handle;
-
        if (pcb->magic == pipe_magic)
                return pcb;
 bad_handle:
        *err_r = -EINVAL;
-       return NULL;
 
-dead_handle:
-       /* Removed under our feet. */
-       *err_r = -EIDRM;
        return NULL;
 }
 
diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 9e6cdd0..33d17d5 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -44,9 +44,6 @@ static struct alchemy_queue *get_alchemy_queue(RT_QUEUE 
*queue,
        if (qcb == NULL || ((intptr_t)qcb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (qcb->magic == ~queue_magic)
-               goto dead_handle;
-
        if (qcb->magic != queue_magic)
                goto bad_handle;
 
@@ -56,14 +53,9 @@ static struct alchemy_queue *get_alchemy_queue(RT_QUEUE 
*queue,
        /* Recheck under lock. */
        if (qcb->magic == queue_magic)
                return qcb;
-
-dead_handle:
-       /* Removed under our feet. */
-       *err_r = -EIDRM;
-       return NULL;
-
 bad_handle:
        *err_r = -EINVAL;
+
        return NULL;
 }
 
diff --git a/lib/alchemy/sem.c b/lib/alchemy/sem.c
index d170ab5..b3fa93c 100644
--- a/lib/alchemy/sem.c
+++ b/lib/alchemy/sem.c
@@ -43,18 +43,11 @@ static struct alchemy_sem *find_alchemy_sem(RT_SEM *sem, 
int *err_r)
        if (scb == NULL || ((intptr_t)scb & (sizeof(intptr_t)-1)) != 0)
                goto bad_handle;
 
-       if (scb->magic == ~sem_magic)
-               goto dead_handle;
-
        if (scb->magic == sem_magic)
                return scb;
 bad_handle:
        *err_r = -EINVAL;
-       return NULL;
 
-dead_handle:
-       /* Removed under our feet. */
-       *err_r = -EIDRM;
        return NULL;
 }
 
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index 8891e41..8178fbe 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -62,12 +62,6 @@ static struct alchemy_task *find_alchemy_task(RT_TASK *task, 
int *err_r)
        magic = threadobj_get_magic(&tcb->thobj);
        if (magic == task_magic)
                return tcb;
-
-       if (magic == ~task_magic) {
-               *err_r = -EIDRM;
-               return NULL;
-       }
-
 bad_handle:
        *err_r = -EINVAL;
 
@@ -102,13 +96,15 @@ struct alchemy_task *get_alchemy_task(RT_TASK *task, int 
*err_r)
         * chance is pthread_mutex_lock() detecting a wrong mutex kind
         * and bailing out.
         */
-       if (tcb == NULL || threadobj_lock(&tcb->thobj) == -EINVAL)
+       if (tcb == NULL || threadobj_lock(&tcb->thobj) == -EINVAL) {
+               *err_r = -EINVAL;
                return NULL;
+       }
 
        /* Check the magic word again, while we hold the lock. */
        if (threadobj_get_magic(&tcb->thobj) != task_magic) {
                threadobj_unlock(&tcb->thobj);
-               *err_r = -EIDRM;
+               *err_r = -EINVAL;
                return NULL;
        }
 


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

Reply via email to