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

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Apr 21 16:14:47 2015 +0200

lib/cobalt: Set default stack size via wrapping pthread_attr_init

Offload the task of setting a reasonable default stack size from the
user by wrapping pthread_attr_init and presetting our value.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/cobalt/pthread.h   |    2 ++
 lib/cobalt/attr.c          |    8 +++++++-
 lib/cobalt/cobalt.wrappers |    1 +
 lib/cobalt/printf.c        |    3 +--
 lib/cobalt/wrappers.c      |    7 +++++++
 5 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 6685276..7843c84 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -38,6 +38,8 @@ typedef struct pthread_attr_ex {
 extern "C" {
 #endif
 
+COBALT_DECL(int, pthread_attr_init(pthread_attr_t *attr));
+
 COBALT_DECL(int, pthread_create(pthread_t *ptid_r,
                                const pthread_attr_t *attr,
                                void *(*start) (void *),
diff --git a/lib/cobalt/attr.c b/lib/cobalt/attr.c
index b3ec570..fcb94ff 100644
--- a/lib/cobalt/attr.c
+++ b/lib/cobalt/attr.c
@@ -23,6 +23,12 @@
 #include <cobalt/uapi/thread.h>
 #include "internal.h"
 
+COBALT_IMPL(int, pthread_attr_init, (pthread_attr_t *attr))
+{
+       __STD(pthread_attr_init)(attr);
+       return pthread_attr_setstacksize(attr, COBALT_STACKSIZE_DEFAULT);
+}
+
 int pthread_attr_init_ex(pthread_attr_ex_t *attr_ex)
 {
        struct sched_param param;
@@ -31,7 +37,7 @@ int pthread_attr_init_ex(pthread_attr_ex_t *attr_ex)
        /* Start with defaulting all fields to null. */
        memset(attr_ex, 0, sizeof(*attr_ex));
        /* Merge in the default standard attribute set. */
-       pthread_attr_init(&attr_ex->std);
+       __COBALT(pthread_attr_init)(&attr_ex->std);
        pthread_attr_getschedpolicy(&attr_ex->std, &policy);
        attr_ex->nonstd.sched_policy = policy;
        pthread_attr_getschedparam(&attr_ex->std, &param);
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index ee13bcf..e66b9c1 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -1,3 +1,4 @@
+--wrap pthread_attr_init
 --wrap pthread_create
 --wrap pthread_setschedparam
 --wrap pthread_getschedparam
diff --git a/lib/cobalt/printf.c b/lib/cobalt/printf.c
index 4e1dff3..d9f3f8b 100644
--- a/lib/cobalt/printf.c
+++ b/lib/cobalt/printf.c
@@ -665,8 +665,7 @@ static void spawn_printer_thread(void)
 {
        pthread_attr_t thattr;
 
-       pthread_attr_init(&thattr);
-       pthread_attr_setstacksize(&thattr, COBALT_STACKSIZE_DEFAULT);
+       __COBALT(pthread_attr_init)(&thattr);
        pthread_create(&printer_thread, &thattr, printer_loop, NULL);
 }
 
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 106b466..313c3a7 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -98,6 +98,13 @@ int __real_pthread_join(pthread_t ptid, void **retval)
        return pthread_join(ptid, retval);
 }
 
+/* attr */
+__weak
+int __real_pthread_attr_init(pthread_attr_t *attr)
+{
+       return pthread_attr_init(attr);
+}
+
 /* semaphores */
 __weak
 int __real_sem_init(sem_t * sem, int pshared, unsigned value)


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

Reply via email to