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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Mar  7 15:29:32 2014 +0100

lib/cobalt: pass personality at thread creation

---

 include/cobalt/pthread.h |    7 +++++++
 lib/cobalt/attr.c        |   16 ++++++++++++++++
 lib/cobalt/init.c        |    7 ++++---
 lib/cobalt/internal.h    |    2 ++
 lib/cobalt/thread.c      |   14 +++++++++-----
 5 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index b290695..47fb432 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -27,6 +27,7 @@
 typedef struct pthread_attr_ex {
        pthread_attr_t std;
        struct {
+               int personality;
                int sched_policy;
                struct sched_param_ex sched_param;
        } nonstd;
@@ -212,6 +213,12 @@ int pthread_attr_getscope_ex(const pthread_attr_ex_t 
*attr_ex,
 int pthread_attr_setscope_ex(pthread_attr_ex_t *attr_ex,
                             int scope);
 
+int pthread_attr_getpersonality_ex(const pthread_attr_ex_t *attr_ex,
+                                  int *personality);
+
+int pthread_attr_setpersonality_ex(pthread_attr_ex_t *attr_ex,
+                                  int personality);
+
 #ifdef __UCLIBC__
 
 #include <errno.h>
diff --git a/lib/cobalt/attr.c b/lib/cobalt/attr.c
index 2d65ad6..b3ec570 100644
--- a/lib/cobalt/attr.c
+++ b/lib/cobalt/attr.c
@@ -124,3 +124,19 @@ int pthread_attr_setscope_ex(pthread_attr_ex_t *attr_ex,
 {
        return pthread_attr_setscope(&attr_ex->std, scope);
 }
+
+int pthread_attr_getpersonality_ex(const pthread_attr_ex_t *attr_ex,
+                                  int *personality)
+{
+       *personality = attr_ex->nonstd.personality;
+
+       return 0;
+}
+
+int pthread_attr_setpersonality_ex(pthread_attr_ex_t *attr_ex,
+                                  int personality)
+{
+       attr_ex->nonstd.personality = personality;
+
+       return 0;
+}
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index e68094b..7e35f19 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -170,26 +170,27 @@ void __libcobalt_init(void)
 
        if (sizeof(struct cobalt_mutex_shadow) > sizeof(pthread_mutex_t)) {
                report_error("sizeof(pthread_mutex_t): %d <"
-                            " sizeof(shadow_mutex): %d !",
+                            " sizeof(cobalt_mutex_shadow): %d!",
                             (int) sizeof(pthread_mutex_t),
                             (int) sizeof(struct cobalt_mutex_shadow));
                exit(EXIT_FAILURE);
        }
        if (sizeof(struct cobalt_cond_shadow) > sizeof(pthread_cond_t)) {
                report_error("sizeof(pthread_cond_t): %d <"
-                            " sizeof(shadow_cond): %d !",
+                            " sizeof(cobalt_cond_shadow): %d!",
                             (int) sizeof(pthread_cond_t),
                             (int) sizeof(struct cobalt_cond_shadow));
                exit(EXIT_FAILURE);
        }
        if (sizeof(struct cobalt_sem_shadow) > sizeof(sem_t)) {
                report_error("sizeof(sem_t): %d <"
-                            " sizeof(shadow_sem): %d !",
+                            " sizeof(cobalt_sem_shadow): %d!",
                             (int) sizeof(sem_t),
                             (int) sizeof(struct cobalt_sem_shadow));
                exit(EXIT_FAILURE);
        }
 
+       cobalt_thread_init();
        cobalt_print_init();
        boilerplate_init();
 }
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index 2589ef7..9121d7e 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -127,6 +127,8 @@ int cobalt_event_destroy(cobalt_event_t *event);
 int cobalt_sem_inquire(sem_t *sem, struct cobalt_sem_info *info,
                       pid_t *waitlist, size_t waitsz);
 
+void cobalt_thread_init(void);
+
 void cobalt_print_init(void);
 
 void cobalt_print_exit(void);
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 51c8a9c..785451c 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -30,7 +30,7 @@
 #include "internal.h"
 #include <boilerplate/ancillaries.h>
 
-static pthread_attr_ex_t default_attr_ex; /* We want it zeroed at init. */
+static pthread_attr_ex_t default_attr_ex;
 
 static int linuxthreads;
 
@@ -217,6 +217,7 @@ COBALT_IMPL(int, pthread_yield, (void))
 struct pthread_iargs {
        struct sched_param_ex param_ex;
        int policy;
+       int personality;
        void *(*start)(void *);
        void *arg;
        int parent_prio;
@@ -232,15 +233,16 @@ static void *cobalt_thread_trampoline(void *p)
         */
        volatile pthread_t tid = pthread_self();
        void *(*start)(void *), *arg, *retval;
+       int personality, parent_prio, policy;
        struct pthread_iargs *iargs = p;
        struct sched_param_ex param_ex;
-       int parent_prio, policy;
        unsigned long u_winoff;
        long ret;
 
        cobalt_sigshadow_install_once();
        prefault_stack();
 
+       personality = iargs->personality;
        param_ex = iargs->param_ex;
        policy = iargs->policy;
        parent_prio = iargs->parent_prio;
@@ -256,8 +258,8 @@ static void *cobalt_thread_trampoline(void *p)
         * Do _not_ inline the call to pthread_self() in the syscall
         * macro: this trashes the syscall regs on some archs.
         */
-       ret = -XENOMAI_SKINCALL4(__cobalt_muxid, sc_cobalt_thread_create, tid,
-                                policy, &param_ex, &u_winoff);
+       ret = -XENOMAI_SKINCALL5(__cobalt_muxid, sc_cobalt_thread_create, tid,
+                                policy, &param_ex, personality, &u_winoff);
        if (ret == 0) {
                cobalt_set_current();
                cobalt_set_current_window(u_winoff);
@@ -337,6 +339,7 @@ int pthread_create_ex(pthread_t *tid,
        pthread_attr_getdetachstate(&attr, &detachstate);
        pthread_attr_getstacksize(&attr, &stksz);
        pthread_attr_setstacksize(&attr, cobalt_get_stacksize(stksz));
+       pthread_attr_getpersonality_ex(attr_ex, &iargs.personality);
 
        /*
         * First start a native POSIX thread, then mate a Xenomai
@@ -388,6 +391,7 @@ COBALT_IMPL(int, pthread_create, (pthread_t *tid,
        attr_ex.nonstd.sched_policy = policy;
        pthread_attr_getschedparam(attr, &param);
        attr_ex.nonstd.sched_param.sched_priority = param.sched_priority;
+       attr_ex.nonstd.personality = 0; /* Default: use Cobalt. */
 
        return pthread_create_ex(tid, &attr_ex, start, arg);
 }
@@ -490,7 +494,7 @@ COBALT_IMPL(int, pthread_join, (pthread_t thread, void 
**retval))
        return ret == -EBUSY ? EINVAL : 0;
 }
 
-static __attribute__((constructor)) void cobalt_thread_init(void)
+void cobalt_thread_init(void)
 {
 #ifdef _CS_GNU_LIBPTHREAD_VERSION
        char vers[128];


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

Reply via email to