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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Jul 26 17:05:06 2017 +0200

alchemy: return error codes from synchronized cluster ops unmodified

Stop remapping { EPERM, ENOMEM } -> EEXIST upon syncluster_addobj()
failure, this creates confusion regarding the actual cause of the
issue. Besides, this serves no purpose since the hash table ops do
return EEXIST as expected upon any attempt to index an object with a
conflicting name.

At this chance, fix up the documentation about receiving the EPERM
status.

http://www.xenomai.org/pipermail/xenomai/2017-July/037476.html

---

 lib/alchemy/buffer.c |   11 +++++------
 lib/alchemy/cond.c   |   10 +++++-----
 lib/alchemy/event.c  |   10 +++++-----
 lib/alchemy/heap.c   |   11 +++++------
 lib/alchemy/mutex.c  |   10 +++++-----
 lib/alchemy/pipe.c   |   11 +++++------
 lib/alchemy/queue.c  |   11 +++++------
 lib/alchemy/sem.c    |   10 +++++-----
 lib/alchemy/task.c   |   11 ++++++++++-
 9 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c
index ac4a9ba..4e81445 100644
--- a/lib/alchemy/buffer.c
+++ b/lib/alchemy/buffer.c
@@ -202,10 +202,10 @@ fnref_register(libalchemy, buffer_finalize);
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered buffer.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @note Buffers can be shared by multiple processes which belong to
  * the same Xenomai session.
@@ -263,10 +263,9 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name,
                warning("failed to export buffer %s to registry, %s",
                        bcb->name, symerror(ret));
 
-       if (syncluster_addobj(&alchemy_buffer_table, bcb->name, &bcb->cobj)) {
-               ret = -EEXIST;
+       ret = syncluster_addobj(&alchemy_buffer_table, bcb->name, &bcb->cobj);
+       if (ret)
                goto fail_register;
-       }
 
        bf->handle = mainheap_ref(bcb, uintptr_t);
 
diff --git a/lib/alchemy/cond.c b/lib/alchemy/cond.c
index 1f424b1..8c9adbb 100644
--- a/lib/alchemy/cond.c
+++ b/lib/alchemy/cond.c
@@ -95,10 +95,10 @@ static struct registry_operations registry_ops;
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered condition variable.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @note Condition variables can be shared by multiple processes which
  * belong to the same Xenomai session.
@@ -156,11 +156,11 @@ int rt_cond_create(RT_COND *cond, const char *name)
                ret = 0;
        }
 
-       if (syncluster_addobj(&alchemy_cond_table, ccb->name, &ccb->cobj)) {
+       ret = syncluster_addobj(&alchemy_cond_table, ccb->name, &ccb->cobj);
+       if (ret) {
                registry_destroy_file(&ccb->fsobj);
                __RT(pthread_cond_destroy(&ccb->cond));
                xnfree(ccb);
-               ret = -EEXIST;
        } else
                cond->handle = mainheap_ref(ccb, uintptr_t);
 out:
diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c
index 15379fc..40bd15e 100644
--- a/lib/alchemy/event.c
+++ b/lib/alchemy/event.c
@@ -157,10 +157,10 @@ fnref_register(libalchemy, event_finalize);
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered event flag group.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @note Event flag groups can be shared by multiple processes which
  * belong to the same Xenomai session.
@@ -213,11 +213,11 @@ int rt_event_create(RT_EVENT *event, const char *name,
                ret = 0;
        }
 
-       if (syncluster_addobj(&alchemy_event_table, evcb->name, &evcb->cobj)) {
+       ret = syncluster_addobj(&alchemy_event_table, evcb->name, &evcb->cobj);
+       if (ret) {
                registry_destroy_file(&evcb->fsobj);
                eventobj_uninit(&evcb->evobj);
                xnfree(evcb);
-               ret = -EEXIST;
        } else
                event->handle = mainheap_ref(evcb, uintptr_t);
 out:
diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c
index 84daed3..4715375 100644
--- a/lib/alchemy/heap.c
+++ b/lib/alchemy/heap.c
@@ -204,10 +204,10 @@ fnref_register(libalchemy, heap_finalize);
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered heap.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @note Heaps can be shared by multiple processes which belong to the
  * same Xenomai session.
@@ -264,10 +264,9 @@ int rt_heap_create(RT_HEAP *heap,
                warning("failed to export heap %s to registry, %s",
                        hcb->name, symerror(ret));
 
-       if (syncluster_addobj(&alchemy_heap_table, hcb->name, &hcb->cobj)) {
-               ret = -EEXIST;
+       ret = syncluster_addobj(&alchemy_heap_table, hcb->name, &hcb->cobj);
+       if (ret)
                goto fail_register;
-       }
 
        heap->handle = mainheap_ref(hcb, uintptr_t);
 
diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c
index 99ba8c6..ffdc2db 100644
--- a/lib/alchemy/mutex.c
+++ b/lib/alchemy/mutex.c
@@ -95,10 +95,10 @@ static struct registry_operations registry_ops;
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered mutex.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @note Mutexes can be shared by multiple processes which belong to
  * the same Xenomai session.
@@ -152,10 +152,10 @@ int rt_mutex_create(RT_MUTEX *mutex, const char *name)
                ret = 0;
        }
 
-       if (syncluster_addobj(&alchemy_mutex_table, mcb->name, &mcb->cobj)) {
+       ret = syncluster_addobj(&alchemy_mutex_table, mcb->name, &mcb->cobj);
+       if (ret) {
                registry_destroy_file(&mcb->fsobj);
                xnfree(mcb);
-               ret = -EEXIST;
        } else
                mutex->handle = mainheap_ref(mcb, uintptr_t);
 out:
diff --git a/lib/alchemy/pipe.c b/lib/alchemy/pipe.c
index 1b6c4a7..54d0164 100644
--- a/lib/alchemy/pipe.c
+++ b/lib/alchemy/pipe.c
@@ -124,10 +124,10 @@ DEFINE_LOOKUP_PRIVATE(pipe, RT_PIPE);
  *
  * - -EBUSY is returned if @a minor is already open.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  */
 #ifndef DOXYGEN_CPP
 CURRENT_IMPL(int, rt_pipe_create,
@@ -210,10 +210,9 @@ int rt_pipe_create(RT_PIPE *pipe,
        pcb->minor = minor;
        pcb->magic = pipe_magic;
 
-       if (syncluster_addobj(&alchemy_pipe_table, pcb->name, &pcb->cobj)) {
-               ret = -EEXIST;
+       ret = syncluster_addobj(&alchemy_pipe_table, pcb->name, &pcb->cobj);
+       if (ret)
                goto fail_register;
-       }
 
        pipe->handle = mainheap_ref(pcb, uintptr_t);
 
diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index de85543..b720059 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -182,10 +182,10 @@ fnref_register(libalchemy, queue_finalize);
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered queue.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @note Queues can be shared by multiple processes which belong to
  * the same Xenomai session.
@@ -263,10 +263,9 @@ int rt_queue_create(RT_QUEUE *queue, const char *name,
                warning("failed to export queue %s to registry, %s",
                        qcb->name, symerror(ret));
 
-       if (syncluster_addobj(&alchemy_queue_table, qcb->name, &qcb->cobj)) {
-               ret = -EEXIST;
+       ret = syncluster_addobj(&alchemy_queue_table, qcb->name, &qcb->cobj);
+       if (ret)
                goto fail_register;
-       }
 
        queue->handle = mainheap_ref(qcb, uintptr_t);
 
diff --git a/lib/alchemy/sem.c b/lib/alchemy/sem.c
index 259bf2f..9e43c6b 100644
--- a/lib/alchemy/sem.c
+++ b/lib/alchemy/sem.c
@@ -167,10 +167,10 @@ fnref_register(libalchemy, sem_finalize);
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered semaphore.
  *
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @note Semaphores can be shared by multiple processes which belong
  * to the same Xenomai session.
@@ -224,11 +224,11 @@ int rt_sem_create(RT_SEM *sem, const char *name,
                ret = 0;
        }
 
-       if (syncluster_addobj(&alchemy_sem_table, scb->name, &scb->cobj)) {
+       ret = syncluster_addobj(&alchemy_sem_table, scb->name, &scb->cobj);
+       if (ret) {
                registry_destroy_file(&scb->fsobj);
                semobj_uninit(&scb->smobj);
                xnfree(scb);
-               ret = -EEXIST;
        } else
                sem->handle = mainheap_ref(scb, uintptr_t);
 out:
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index 12acafc..079d11b 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -253,6 +253,9 @@ static int create_tcb(struct alchemy_task **tcbp, RT_TASK 
*task,
        struct alchemy_task *tcb;
        int ret;
 
+       if (threadobj_irq_p())
+               return -EPERM;
+
        ret = check_task_priority(prio);
        if (ret)
                return ret;
@@ -384,7 +387,10 @@ fail_syncinit:
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered task.
  *
- * @apitags{mode-unrestricted, switch-secondary}
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt or non-Xenomai thread.
+ *
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
  *
  * @sideeffect
  * - When running over the Cobalt core:
@@ -700,6 +706,9 @@ out:
  *
  * - -EBUSY is returned if the caller is not a regular POSIX thread.
  *
+ * - -EPERM is returned if this service was called from an invalid
+ * context, e.g. interrupt handler.
+ *
  * @apitags{pthread-only, switch-secondary, switch-primary}
  *
  * @sideeffect Over Cobalt, if the caller is a plain POSIX thread, it


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

Reply via email to