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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun May  5 16:24:47 2013 +0200

alchemy/task: fix task mode handling upon creation/shadowing

T_LOCK and T_WARNSW may be set for the task mode when creating or
shadowing a task. T_JOINABLE may be set only when creating a new task.

Also, do not mention the obsolete T_SUSP flag in the documentation
anymore.

---

 lib/alchemy/task.c |   49 +++++++++++++++++++++++++++++++------------------
 1 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index fce6f40..aecbb13 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -168,15 +168,12 @@ static int task_prologue(struct alchemy_task *tcb)
        threadobj_wait_start();
 
        threadobj_lock(&tcb->thobj);
-
-       if (tcb->mode & T_LOCK)
-               threadobj_lock_sched(&tcb->thobj);
-
+       ret = threadobj_set_mode(0, tcb->mode, NULL);
        threadobj_unlock(&tcb->thobj);
 
        COPPERPLATE_UNPROTECT(svc);
 
-       return 0;
+       return ret;
 }
 
 static void *task_trampoline(void *arg)
@@ -211,9 +208,6 @@ static int create_tcb(struct alchemy_task **tcbp, RT_TASK 
*task,
        if (ret)
                return ret;
 
-       if (mode & ~T_LOCK)
-               return -EINVAL;
-
        tcb = threadobj_alloc(struct alchemy_task, thobj,
                              union alchemy_wait_union);
        if (tcb == NULL)
@@ -300,15 +294,22 @@ static void delete_tcb(struct alchemy_task *tcb)
  * in the [0 .. 99] range, where 0 is the lowest effective priority. 
  *
  * @param mode The task creation mode. The following flags can be
- * OR'ed into this bitmask, each of them affecting the new task:
- *
- * - T_SUSP causes the task to start in suspended mode; a call to
- * rt_task_resume() is required to actually start its execution.
+ * OR'ed into this bitmask:
  *
  * - T_JOINABLE allows another task to wait on the termination of the
  * new task. rt_task_join() shall be called for this task to clean up
  * any resources after its termination.
  *
+ * - T_LOCK causes the new task to lock the scheduler prior to
+ * entering the user routine specified by rt_task_start(). A call to
+ * rt_task_set_mode() from the new task is required to drop this lock.
+ *
+ * - When running over the Cobalt core, T_WARNSW causes the SIGXCPU
+ * signal to be sent to the current task whenever it switches to the
+ * secondary mode. This feature is useful to detect unwanted
+ * migrations to the Linux domain. This flag has no effect over the
+ * Mercury core.
+ *
  * @return 0 is returned upon success. Otherwise:
  *
  * - -EINVAL is returned if either @a prio, @a mode or @a stksize are
@@ -352,6 +353,9 @@ int rt_task_create(RT_TASK *task, const char *name,
        int detachstate, ret;
        struct service svc;
 
+       if (mode & ~(T_LOCK | T_WARNSW | T_JOINABLE))
+               return -EINVAL;
+
        COPPERPLATE_PROTECT(svc);
 
        ret = create_tcb(&tcb, task, name, prio, mode);
@@ -641,16 +645,22 @@ out:
  * @param prio The base priority of the task. This value must be in
  * the [0 .. 99] range, where 0 is the lowest effective priority.
  *
- * @param mode The task creation mode. The following flags can be
- * OR'ed into this bitmask, each of them affecting the new task:
+ * @param mode The task shadowing mode. The following flags can be
+ * OR'ed into this bitmask:
  *
- * - T_SUSP causes the task to suspend before returning from this
- * service; a call to rt_task_resume() is required to resume
- * execution.
+ * - T_LOCK causes the current task to lock the scheduler before
+ * returning to the caller. A call to rt_task_set_mode() from the
+ * current task is required to drop this lock.
+ *
+ * - When running over the Cobalt core, T_WARNSW causes the SIGXCPU
+ * signal to be sent to the current task whenever it switches to the
+ * secondary mode. This feature is useful to detect unwanted
+ * migrations to the Linux domain. This flag has no effect over the
+ * Mercury core.
  *
  * @return 0 is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if either @a prio or @a mode are invalid.
+ * - -EINVAL is returned if @a prio is invalid.
  *
  * - -ENOMEM is returned if the system fails to get memory from the
  * main heap in order to create the task extension.
@@ -685,6 +695,9 @@ int rt_task_shadow(RT_TASK *task, const char *name, int 
prio, int mode)
        pthread_t self;
        int ret;
 
+       if (mode & ~(T_LOCK | T_WARNSW))
+               return -EINVAL;
+
        COPPERPLATE_PROTECT(svc);
 
        /*


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

Reply via email to