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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun May 26 18:49:50 2013 +0200

copperplate/internal: group thread creation attributes

---

 lib/alchemy/task.c         |   13 ++++++++-----
 lib/copperplate/internal.c |   30 ++++++++++++++----------------
 lib/copperplate/internal.h |   13 +++++++++----
 lib/copperplate/timerobj.c |   12 +++++++-----
 lib/psos/task.c            |   11 ++++++++---
 lib/vxworks/taskLib.c      |   11 ++++++++---
 6 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index da09d51..c31b6c9 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -333,9 +333,10 @@ static int create_tcb(struct alchemy_task **tcbp, RT_TASK 
*task,
 int rt_task_create(RT_TASK *task, const char *name,
                   int stksize, int prio, int mode)
 {
+       struct corethread_attributes cta;
        struct alchemy_task *tcb;
-       int detachstate, ret;
        struct service svc;
+       int ret;
 
        if (mode & ~(T_LOCK | T_WARNSW | T_JOINABLE))
                return -EINVAL;
@@ -349,12 +350,14 @@ 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 ?
+       cta.detachstate = mode & T_JOINABLE ?
                PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED;
+       cta.prio = prio;
+       cta.start = task_trampoline;
+       cta.arg = tcb;
+       cta.stacksize = stksize;
 
-       ret = __bt(copperplate_create_thread(prio, task_trampoline, tcb,
-                                            stksize, detachstate,
-                                            &tcb->thobj.tid));
+       ret = __bt(copperplate_create_thread(&cta, &tcb->thobj.tid));
        if (ret)
                delete_tcb(tcb);
        else
diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c
index 1443c4d..865ba85 100644
--- a/lib/copperplate/internal.c
+++ b/lib/copperplate/internal.c
@@ -69,28 +69,27 @@ int copperplate_probe_node(unsigned int id)
        return pthread_probe_np((pid_t)id) == 0;
 }
 
-int copperplate_create_thread(int prio,
-                             void *(*start)(void *arg), void *arg,
-                             size_t stacksize,
-                             int detachstate,
+int copperplate_create_thread(const struct corethread_attributes *cta,
                              pthread_t *tid)
 {
        struct sched_param_ex param_ex;
        pthread_attr_ex_t attr_ex;
+       size_t stacksize;
        int policy, ret;
 
+       stacksize = cta->stacksize;
        if (stacksize < PTHREAD_STACK_MIN * 4)
                stacksize = PTHREAD_STACK_MIN * 4;
 
-       param_ex.sched_priority = prio;
-       policy = prio ? SCHED_RT : SCHED_OTHER;
+       param_ex.sched_priority = cta->prio;
+       policy = cta->prio ? SCHED_RT : SCHED_OTHER;
        pthread_attr_init_ex(&attr_ex);
        pthread_attr_setinheritsched_ex(&attr_ex, PTHREAD_EXPLICIT_SCHED);
        pthread_attr_setschedpolicy_ex(&attr_ex, policy);
        pthread_attr_setschedparam_ex(&attr_ex, &param_ex);
        pthread_attr_setstacksize_ex(&attr_ex, stacksize);
-       pthread_attr_setdetachstate_ex(&attr_ex, detachstate);
-       ret = __bt(-pthread_create_ex(tid, &attr_ex, start, arg));
+       pthread_attr_setdetachstate_ex(&attr_ex, cta->detachstate);
+       ret = __bt(-pthread_create_ex(tid, &attr_ex, cta->start, cta->arg));
        pthread_attr_destroy_ex(&attr_ex);
 
        return ret;
@@ -114,28 +113,27 @@ int copperplate_probe_node(unsigned int id)
        return kill((pid_t)id, 0) == 0;
 }
 
-int copperplate_create_thread(int prio,
-                             void *(*start)(void *arg), void *arg,
-                             size_t stacksize,
-                             int detachstate,
+int copperplate_create_thread(const struct corethread_attributes *cta,
                              pthread_t *tid)
 {
        struct sched_param param;
        pthread_attr_t attr;
+       size_t stacksize;
        int policy, ret;
 
+       stacksize = cta->stacksize;
        if (stacksize < PTHREAD_STACK_MIN * 4)
                stacksize = PTHREAD_STACK_MIN * 4;
 
-       param.sched_priority = prio;
-       policy = prio ? SCHED_RT : SCHED_OTHER;
+       param.sched_priority = cta->prio;
+       policy = cta->prio ? SCHED_RT : SCHED_OTHER;
        pthread_attr_init(&attr);
        pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
        pthread_attr_setschedpolicy(&attr, policy);
        pthread_attr_setschedparam(&attr, &param);
        pthread_attr_setstacksize(&attr, stacksize);
-       pthread_attr_setdetachstate(&attr, detachstate);
-       ret = __bt(-pthread_create(tid, &attr, start, arg));
+       pthread_attr_setdetachstate(&attr, cta->detachstate);
+       ret = __bt(-pthread_create(tid, &attr, cta->start, cta->arg));
        pthread_attr_destroy(&attr);
 
        return ret;
diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h
index e1fa41c..77b5d05 100644
--- a/lib/copperplate/internal.h
+++ b/lib/copperplate/internal.h
@@ -67,6 +67,14 @@ struct shared_heap {
        } buckets[HOBJ_NBUCKETS];
 };
 
+struct corethread_attributes {
+       int prio;
+       void *(*start)(void *arg);
+       void *arg;
+       size_t stacksize;
+       int detachstate;
+};
+
 extern pid_t __node_id;
 
 extern struct coppernode __node_info;
@@ -100,10 +108,7 @@ pid_t copperplate_get_tid(void);
 
 int copperplate_probe_node(unsigned int id);
 
-int copperplate_create_thread(int prio,
-                             void *(*start)(void *arg), void *arg,
-                             size_t stacksize,
-                             int detachstate,
+int copperplate_create_thread(const struct corethread_attributes *cta,
                              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 efa0236..a367cb1 100644
--- a/lib/copperplate/timerobj.c
+++ b/lib/copperplate/timerobj.c
@@ -215,6 +215,7 @@ static void *timerobj_server(void *arg)
 
 static int timerobj_spawn_server(void)
 {
+       struct corethread_attributes cta;
        int ret = 0;
 
        push_cleanup_lock(&svlock);
@@ -223,11 +224,12 @@ static int timerobj_spawn_server(void)
        if (svthread)
                goto out;
 
-       ret = __bt(copperplate_create_thread(threadobj_irq_prio,
-                                            timerobj_server, NULL,
-                                            PTHREAD_STACK_MIN * 16,
-                                            PTHREAD_CREATE_DETACHED,
-                                            &svthread));
+       cta.prio = threadobj_irq_prio;
+       cta.start = timerobj_server;
+       cta.arg = NULL;
+       cta.stacksize = PTHREAD_STACK_MIN * 16;
+       cta.detachstate = PTHREAD_CREATE_DETACHED;
+       ret = __bt(copperplate_create_thread(&cta, &svthread));
        if (ret)
                return ret;
 
diff --git a/lib/psos/task.c b/lib/psos/task.c
index 0a0ef40..3218cba 100644
--- a/lib/psos/task.c
+++ b/lib/psos/task.c
@@ -247,6 +247,7 @@ static int check_task_priority(u_long psos_prio, int 
*core_prio)
 u_long t_create(const char *name, u_long prio,
                u_long sstack, u_long ustack, u_long flags, u_long *tid_r)
 {
+       struct corethread_attributes cta;
        struct threadobj_init_data idata;
        struct psos_task *task;
        struct syncstate syns;
@@ -308,9 +309,13 @@ u_long t_create(const char *name, u_long prio,
        idata.priority = cprio;
        threadobj_init(&task->thobj, &idata);
 
-       ret = __bt(copperplate_create_thread(cprio, task_trampoline, task,
-                                            ustack, PTHREAD_CREATE_DETACHED,
-                                            &task->thobj.tid));
+       cta.prio = cprio;
+       cta.start = task_trampoline;
+       cta.arg = task;
+       cta.stacksize = ustack;
+       cta.detachstate = PTHREAD_CREATE_DETACHED;
+
+       ret = __bt(copperplate_create_thread(&cta, &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 6096694..a74c20c 100644
--- a/lib/vxworks/taskLib.c
+++ b/lib/vxworks/taskLib.c
@@ -318,6 +318,7 @@ static STATUS __taskInit(struct wind_task *task,
                         struct WIND_TCB *tcb, const char *name,
                         int prio, int flags, FUNCPTR entry, int stacksize)
 {
+       struct corethread_attributes cta;
        struct threadobj_init_data idata;
        pthread_mutexattr_t mattr;
        int ret, cprio;
@@ -365,9 +366,13 @@ static STATUS __taskInit(struct wind_task *task,
 
        registry_init_file(&task->fsobj, &registry_ops);
 
-       ret = __bt(copperplate_create_thread(cprio, task_trampoline, task,
-                                            stacksize, PTHREAD_CREATE_DETACHED,
-                                            &task->thobj.tid));
+       cta.prio = cprio;
+       cta.start = task_trampoline;
+       cta.arg = tcb;
+       cta.stacksize = stacksize;
+       cta.detachstate = PTHREAD_CREATE_DETACHED;
+       ret = __bt(copperplate_create_thread(&cta, &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