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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Jun  1 17:40:48 2012 +0200

cobalt: cleanup, fix build over uClinux

---

 include/asm-blackfin/syscall.h |   26 --------------------------
 include/cobalt/nucleus/types.h |    1 -
 include/cobalt/pthread.h       |   23 +++++++++++++++++++++++
 include/cobalt/sched.h         |    6 ++++++
 include/cobalt/stdio.h         |   12 ++++++++++++
 lib/cobalt/internal.c          |    1 +
 lib/cobalt/printf.c            |   16 ++++++++++++++++
 lib/cobalt/sigshadow.c         |   14 ++++++++++++--
 lib/cobalt/wrappers.c          |   26 ++++++++++++++++++++++++++
 lib/vxworks/taskInfo.c         |   35 +++++++++++++++++++++++------------
 testsuite/unit/cond-torture.c  |    7 +++++++
 11 files changed, 126 insertions(+), 41 deletions(-)

diff --git a/include/asm-blackfin/syscall.h b/include/asm-blackfin/syscall.h
index 005d9a3..795234b 100644
--- a/include/asm-blackfin/syscall.h
+++ b/include/asm-blackfin/syscall.h
@@ -152,32 +152,6 @@ static inline unsigned long long __xn_rdtsc (void)
     return u.t;
 }
 
-/* uClibc does not provide pthread_atfork() for this arch; provide it
-   here. Note: let the compiler decides whether it wants to actually
-   inline this routine, i.e. do not force always_inline. */
-inline __attribute__((weak)) int pthread_atfork(void (*prepare)(void),
-                                               void (*parent)(void),
-                                               void (*child)(void))
-{
-       return 0;
-}
-
-#include <errno.h>
-
-inline __attribute__((weak)) int shm_open(const char *name,
-                                         int oflag,
-                                         mode_t mode)
-{
-       errno = ENOSYS;
-       return -1;
-}
-
-inline __attribute__((weak)) int shm_unlink(const char *name)
-{
-       errno = ENOSYS;
-       return -1;
-}
-
 #endif /* __KERNEL__ */
 
 #endif /* !_XENO_ASM_BLACKFIN_SYSCALL_H */
diff --git a/include/cobalt/nucleus/types.h b/include/cobalt/nucleus/types.h
index dc894a4..1eecc01 100644
--- a/include/cobalt/nucleus/types.h
+++ b/include/cobalt/nucleus/types.h
@@ -23,7 +23,6 @@
 #ifdef __KERNEL__
 #include <linux/errno.h>
 #else /* !__KERNEL__ */
-#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 #include <errno.h>
diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index f0b1a04..99f28d5 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -120,6 +120,7 @@ typedef struct
 #else /* !__KERNEL__ */
 
 #include <sched.h>
+#include <errno.h>
 #include_next <pthread.h>
 #include <nucleus/thread.h>
 #include <cobalt/wrappers.h>
@@ -405,6 +406,28 @@ 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);
+
+#ifdef __UCLIBC__
+/*
+ * uClibc does not provide the following routines, so we define them
+ * here. Note: let the compiler decides whether it wants to actually
+ * inline these routines, i.e. do not force always_inline.
+ */
+inline __attribute__ ((weak))
+int pthread_atfork(void (*prepare)(void), void (*parent)(void),
+                  void (*child)(void))
+{
+       return 0;
+}
+
+inline __attribute__ ((weak))
+int pthread_getattr_np(pthread_t th, pthread_attr_t *attr)
+{
+       return ENOSYS;
+}
+
+#endif /* __UCLIBC__ */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h
index eeb114f..4931b99 100644
--- a/include/cobalt/sched.h
+++ b/include/cobalt/sched.h
@@ -39,6 +39,12 @@ COBALT_DECL(int, sched_get_priority_max(int policy));
 
 #endif /* !__KERNEL__ */
 
+#ifndef CPU_COUNT
+#define CPU_COUNT(__setp)    __PROVIDE_CPU_COUNT(__setp)
+#define __PROVIDE_CPU_COUNT(__setp)  __sched_cpucount(sizeof(cpu_set_t), 
__setp)
+int __sched_cpucount(size_t __setsize, const cpu_set_t *__setp);
+#endif /* !CPU_COUNT */
+
 #ifndef __sched_extensions_defined
 #define __sched_extensions_defined
 
diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h
index cadde58..60398c7 100644
--- a/include/cobalt/stdio.h
+++ b/include/cobalt/stdio.h
@@ -24,10 +24,22 @@ COBALT_DECL(int, puts(const char *s));
 
 COBALT_DECL(int, fputs(const char *s, FILE *stream));
 
+#if !defined(__UCLIBC__) || !defined(__STDIO_PUTC_MACRO)
+
 COBALT_DECL(int, fputc(int c, FILE *stream));
 
 COBALT_DECL(int, putchar(int c));
 
+#else
+
+int __wrap_fputc(int c, FILE *stream);
+#define __real_fputc __wrap_fputc
+
+int __wrap_putchar(int c);
+#define __real_putchar __wrap_putchar
+
+#endif
+
 COBALT_DECL(size_t, fwrite(const void *ptr, size_t sz, size_t nmemb, FILE 
*stream));
 
 #ifdef __cplusplus
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 12e31fb..573391b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <stddef.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <signal.h>
 #include <errno.h>
diff --git a/lib/cobalt/printf.c b/lib/cobalt/printf.c
index 6654a93..1bef2eb 100644
--- a/lib/cobalt/printf.c
+++ b/lib/cobalt/printf.c
@@ -835,6 +835,8 @@ int __wrap_puts(const char *s)
        }
 }
 
+#if !defined(__UCLIBC__) || !defined(__STDIO_PUTC_MACRO)
+
 int __wrap_fputc(int c, FILE *stream)
 {
        if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
@@ -857,6 +859,20 @@ int __wrap_putchar(int c)
        }
 }
 
+#else
+
+int __wrap_fputc(int c, FILE *stream)
+{
+       return fputc(c, stream);
+}
+
+int __wrap_putchar(int c)
+{
+       return putchar(c);
+}
+
+#endif /* !(__UCLIBC__ && __STDIO_PUTC_MACRO) */
+
 size_t __wrap_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
 {
        if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index a4c23ca..815e42b 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -1,9 +1,19 @@
 #include <pthread.h>
 #include <signal.h>
-#include <execinfo.h>
-
 #include <asm/xenomai/syscall.h>
 
+#ifdef __UCLIBC__
+static inline int backtrace(void **buffer, int size)
+{
+       /*
+        * We have no backtrace support in uClibc.
+        */
+       return 0;
+}
+#else /* !__UCLIBC__ */
+#include <execinfo.h>
+#endif /* !__UCLIBC__ */
+
 static struct sigaction xeno_saved_sigshadow_action;
 
 /*
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 90e0029..2f33885 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -36,6 +36,7 @@
 #include <semaphore.h>
 #include <limits.h>
 #include <fcntl.h>
+#include <sched.h>
 #include <unistd.h>
 #include <malloc.h>
 
@@ -318,6 +319,8 @@ int __real_fputs(const char *s, FILE *stream)
        return fputs(s, stream);
 }
 
+#if !defined(__UCLIBC__) || !defined(__STDIO_PUTC_MACRO)
+
 __attribute__ ((weak))
 int __real_fputc(int c, FILE *stream)
 {
@@ -330,6 +333,8 @@ int __real_putchar(int c)
        return putchar(c);
 }
 
+#endif /* !(__UCLIBC__ && __STDIO_PUTC_MACRO) */
+
 __attribute__ ((weak))
 size_t __real_fwrite(const void *ptr, size_t sz, size_t nmemb, FILE *stream)
 {
@@ -375,3 +380,24 @@ int __real_clock_gettime(clockid_t clk_id, struct timespec 
*tp)
 {
        return clock_gettime(clk_id, tp);
 }
+
+#ifdef __PROVIDE_CPU_COUNT
+
+int __sched_cpucount(size_t setsize, const cpu_set_t *setp)
+{
+       int count, shift;
+       const char *p;
+
+       for (count = 0, p = setp; p < setp + setsize; p++) {
+               shift = *p;
+               while (shift) {
+                       if (shift & 1)
+                               count++;
+                       shift >>= 1;
+               }
+       }
+
+       return count;
+}
+
+#endif /* __PROVIDE_CPU_COUNT */
diff --git a/lib/vxworks/taskInfo.c b/lib/vxworks/taskInfo.c
index c3dcc26..b0b53a7 100644
--- a/lib/vxworks/taskInfo.c
+++ b/lib/vxworks/taskInfo.c
@@ -102,10 +102,10 @@ BOOL taskIsSuspended(TASK_ID task_id)
 
 STATUS taskGetInfo(TASK_ID task_id, TASK_DESC *desc)
 {
+       int vfirst, vlast, ret;
        struct wind_task *task;
        struct WIND_TCB *tcb;
        pthread_attr_t attr;
-       int vfirst, vlast;
        size_t stacksize;
        void *stackbase;
 
@@ -123,19 +123,30 @@ STATUS taskGetInfo(TASK_ID task_id, TASK_DESC *desc)
        strncpy(desc->td_name, task->name, sizeof(desc->td_name));
        desc->td_entry = tcb->entry;
        desc->td_errorStatus = *task->thobj.errno_pointer;
-       pthread_getattr_np(task->thobj.tid, &attr);
+       ret = pthread_getattr_np(task->thobj.tid, &attr);
        put_wind_task(task);
 
-       pthread_attr_getstack(&attr, &stackbase, &stacksize);
-       desc->td_stacksize = stacksize;
-       desc->td_pStackBase = stackbase;
-
-       if (&vfirst < &vlast)
-               /* Stack grows upward. */
-               desc->td_pStackEnd = (caddr_t)stackbase + stacksize;
-       else
-               /* Stack grows downward. */
-               desc->td_pStackEnd = (caddr_t)stackbase - stacksize;
+       /*
+        * If the target does not support pthread_getattr_np(), we are
+        * out of luck for determining the stack information. We just
+        * zero it.
+        */
+       if (ret) {
+               /* No idea, buddy. */
+               desc->td_stacksize = 0;
+               desc->td_pStackBase = NULL;
+       } else {
+               pthread_attr_getstack(&attr, &stackbase, &stacksize);
+               desc->td_stacksize = stacksize;
+               desc->td_pStackBase = stackbase;
+
+               if (&vfirst < &vlast)
+                       /* Stack grows upward. */
+                       desc->td_pStackEnd = (caddr_t)stackbase + stacksize;
+               else
+                       /* Stack grows downward. */
+                       desc->td_pStackEnd = (caddr_t)stackbase - stacksize;
+       }
 
        return OK;
 }
diff --git a/testsuite/unit/cond-torture.c b/testsuite/unit/cond-torture.c
index c1abc3a..a9aa6dd 100644
--- a/testsuite/unit/cond-torture.c
+++ b/testsuite/unit/cond-torture.c
@@ -64,8 +64,15 @@ int cond_init(pthread_cond_t *cond, int absolute)
        int err;
 
        pthread_condattr_init(&cattr);
+#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
        pthread_condattr_setclock(&cattr,
                                  absolute ? CLOCK_REALTIME : CLOCK_MONOTONIC);
+#else
+       if (!absolute) {
+               pthread_condattr_destroy(&cattr);
+               return ENOSYS;
+       }
+#endif
        err = pthread_cond_init(cond, &cattr);
        pthread_condattr_destroy(&cattr);
 


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

Reply via email to