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

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

copperplate/internal, lib/cobalt: allow specifying detach state of threads

---

 include/alchemy/task.h     |    1 +
 lib/alchemy/task.c         |    8 ++++++--
 lib/cobalt/thread.c        |    5 ++++-
 lib/copperplate/internal.c |    6 ++++--
 lib/copperplate/internal.h |    1 +
 lib/copperplate/timerobj.c |    1 +
 lib/psos/task.c            |    3 ++-
 lib/vxworks/taskLib.c      |    3 ++-
 8 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/include/alchemy/task.h b/include/alchemy/task.h
index 95bc32b..0dd7d22 100644
--- a/include/alchemy/task.h
+++ b/include/alchemy/task.h
@@ -39,6 +39,7 @@
 #define T_JOINABLE     __THREAD_M_SPARE0
 /* Deprecated, compat only. */
 #define T_FPU          0x0
+#define T_JOINABLE     __THREAD_M_SPARE0
 
 struct RT_TASK {
        uintptr_t handle;
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index bb37ef0..8664efa 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -349,8 +349,8 @@ int rt_task_create(RT_TASK *task, const char *name,
                   int stksize, int prio, int mode)
 {
        struct alchemy_task *tcb;
+       int detachstate, ret;
        struct service svc;
-       int ret;
 
        COPPERPLATE_PROTECT(svc);
 
@@ -361,8 +361,12 @@ int rt_task_create(RT_TASK *task, const char *name,
        /* We want this to be set prior to spawning the thread. */
        tcb->self = *task;
 
+       detachstate = mode & T_JOINABLE ?
+               PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED;
+
        ret = __bt(copperplate_create_thread(prio, task_trampoline, tcb,
-                                            stksize, &tcb->thobj.tid));
+                                            stksize, detachstate,
+                                            &tcb->thobj.tid));
        if (ret)
                delete_tcb(tcb);
 out:
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index c21883c..6da99d3 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -246,10 +246,10 @@ int pthread_create_ex(pthread_t *tid,
                      const pthread_attr_ex_t *attr_ex,
                      void *(*start) (void *), void *arg)
 {
+       int inherit, detachstate, ret;
        struct pthread_iargs iargs;
        struct sched_param param;
        pthread_attr_t attr;
-       int inherit, ret;
        pthread_t ltid;
        size_t stksz;
 
@@ -284,6 +284,7 @@ int pthread_create_ex(pthread_t *tid,
                 */
                pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
 
+       pthread_attr_getdetachstate(&attr, &detachstate);
        pthread_attr_getstacksize(&attr, &stksz);
        pthread_attr_setstacksize(&attr, xeno_stacksize(stksz));
 
@@ -306,6 +307,8 @@ int pthread_create_ex(pthread_t *tid,
        ret = iargs.ret;
        if (ret == 0)
                *tid = ltid;
+       else if (detachstate == PTHREAD_CREATE_JOINABLE)
+               pthread_join(ltid, NULL);
 fail:
        __STD(sem_destroy(&iargs.sync));
 
diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c
index 1265f3d..0661973 100644
--- a/lib/copperplate/internal.c
+++ b/lib/copperplate/internal.c
@@ -72,6 +72,7 @@ int copperplate_probe_node(unsigned int id)
 int copperplate_create_thread(int prio,
                              void *(*start)(void *arg), void *arg,
                              size_t stacksize,
+                             int detachstate,
                              pthread_t *tid)
 {
        struct sched_param_ex param_ex;
@@ -89,7 +90,7 @@ int copperplate_create_thread(int prio,
        pthread_attr_setschedparam_ex(&attr_ex, &param_ex);
        pthread_attr_setstacksize_ex(&attr_ex, stacksize);
        pthread_attr_setscope_ex(&attr_ex, thread_scope_attribute);
-       pthread_attr_setdetachstate_ex(&attr_ex, PTHREAD_CREATE_JOINABLE);
+       pthread_attr_setdetachstate_ex(&attr_ex, detachstate);
        ret = __bt(-pthread_create_ex(tid, &attr_ex, start, arg));
        pthread_attr_destroy_ex(&attr_ex);
 
@@ -117,6 +118,7 @@ int copperplate_probe_node(unsigned int id)
 int copperplate_create_thread(int prio,
                              void *(*start)(void *arg), void *arg,
                              size_t stacksize,
+                             int detachstate,
                              pthread_t *tid)
 {
        struct sched_param param;
@@ -134,7 +136,7 @@ int copperplate_create_thread(int prio,
        pthread_attr_setschedparam(&attr, &param);
        pthread_attr_setstacksize(&attr, stacksize);
        pthread_attr_setscope(&attr, thread_scope_attribute);
-       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+       pthread_attr_setdetachstate(&attr, detachstate);
        ret = __bt(-pthread_create(tid, &attr, start, arg));
        pthread_attr_destroy(&attr);
 
diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h
index 15a0321..e1fa41c 100644
--- a/lib/copperplate/internal.h
+++ b/lib/copperplate/internal.h
@@ -103,6 +103,7 @@ int copperplate_probe_node(unsigned int id);
 int copperplate_create_thread(int prio,
                              void *(*start)(void *arg), void *arg,
                              size_t stacksize,
+                             int detachstate,
                              pthread_t *tid);
 
 int copperplate_renice_thread(pthread_t tid, int prio);
diff --git a/lib/copperplate/timerobj.c b/lib/copperplate/timerobj.c
index 9277f50..91b483d 100644
--- a/lib/copperplate/timerobj.c
+++ b/lib/copperplate/timerobj.c
@@ -225,6 +225,7 @@ static int timerobj_spawn_server(void)
        ret = __bt(copperplate_create_thread(threadobj_irq_prio,
                                             timerobj_server, NULL,
                                             PTHREAD_STACK_MIN * 16,
+                                            PTHREAD_CREATE_DETACHED,
                                             &svthread));
 
        /* Wait for timer server to initialize. */
diff --git a/lib/psos/task.c b/lib/psos/task.c
index c5b79e2..a482b5d 100644
--- a/lib/psos/task.c
+++ b/lib/psos/task.c
@@ -312,7 +312,8 @@ u_long t_create(const char *name, u_long prio,
        threadobj_init(&task->thobj, &idata);
 
        ret = __bt(copperplate_create_thread(cprio, task_trampoline, task,
-                                            ustack, &task->thobj.tid));
+                                            ustack, PTHREAD_CREATE_DETACHED,
+                                            &task->thobj.tid));
        if (ret) {
                cluster_delobj(&psos_task_table, &task->cobj);
                threadobj_destroy(&task->thobj);
diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c
index b4c2e1f..c891dd5 100644
--- a/lib/vxworks/taskLib.c
+++ b/lib/vxworks/taskLib.c
@@ -369,7 +369,8 @@ static STATUS __taskInit(struct wind_task *task,
        registry_init_file(&task->fsobj, &registry_ops);
 
        ret = __bt(copperplate_create_thread(cprio, task_trampoline, task,
-                                            stacksize, &task->thobj.tid));
+                                            stacksize, PTHREAD_CREATE_DETACHED,
+                                            &task->thobj.tid));
        if (ret) {
                registry_destroy_file(&task->fsobj);
                cluster_delobj(&wind_task_table, &task->cobj);


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

Reply via email to