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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Aug 17 11:55:31 2014 +0200

cobalt, mercury: enable uClibc, NPTL/linuxthreads builds

We allow building the Xenomai libraries and programs against uClibc
and glibc-based toolchains for both Cobalt and Mercury
configurations. We cope with NPTL and legacy linuxthreads for both as
well.

To this end, this patch moves all libc quirks to a separate header.

---

 configure                                    |   23 +++-
 configure.ac                                 |   28 ++++-
 include/boilerplate/Makefile.am              |    1 +
 include/boilerplate/Makefile.in              |    1 +
 include/boilerplate/compiler.h               |    4 +
 include/boilerplate/libc.h                   |  175 ++++++++++++++++++++++++++
 include/cobalt/pthread.h                     |   56 ++-------
 include/copperplate/clockobj.h               |   44 ++++++-
 include/mercury/Makefile.am                  |    2 +
 include/mercury/Makefile.in                  |    8 +-
 include/mercury/pthread.h                    |   21 ++++
 include/xeno_config.h.in                     |   30 +++++
 lib/alchemy/mutex.c                          |    3 +-
 lib/copperplate/clockobj.c                   |    7 ++
 lib/copperplate/syncobj.c                    |    6 +-
 lib/copperplate/threadobj.c                  |    5 +-
 lib/vxworks/semLib.c                         |    3 +-
 testsuite/regression/posix/leaks.c           |    7 +-
 testsuite/smokey/cond-torture/cond-torture.c |   15 +--
 19 files changed, 368 insertions(+), 71 deletions(-)

diff --git a/configure b/configure
index 6a2d951..00e96e0 100755
--- a/configure
+++ b/configure
@@ -13745,7 +13745,18 @@ done
 
 save_LIBS="$LIBS"
 LIBS="$LIBS -lrt -lpthread"
-for ac_func in pthread_mutexattr_setprotocol pthread_condattr_setclock 
pthread_spin_lock fork
+for ac_func in pthread_mutexattr_setprotocol   \
+               pthread_mutexattr_getprotocol   \
+               pthread_mutexattr_setrobust_np  \
+               pthread_condattr_getclock       \
+               pthread_condattr_setclock       \
+               pthread_spin_lock fork          \
+               pthread_attr_setaffinity_np     \
+               pthread_getattr_np              \
+               pthread_atfork                  \
+               pthread_setname_np              \
+               sched_getcpu                    \
+               clock_nanosleep
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -13759,6 +13770,16 @@ done
 
 LIBS="$save_LIBS"
 
+ac_fn_c_check_func "$LINENO" "pthread_condattr_setclock" 
"ac_cv_func_pthread_condattr_setclock"
+if test "x$ac_cv_func_pthread_condattr_setclock" = xyes; then :
+
+else
+
+$as_echo "#define CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED 1" >>confdefs.h
+
+fi
+
+
 
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 5f7d714..febcdfd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -498,9 +498,35 @@ AC_CHECK_HEADERS(mqueue.h)
 dnl Check for presence of some routines we need
 save_LIBS="$LIBS"
 LIBS="$LIBS -lrt -lpthread"
-AC_CHECK_FUNCS([pthread_mutexattr_setprotocol pthread_condattr_setclock 
pthread_spin_lock fork])
+AC_CHECK_FUNCS([pthread_mutexattr_setprotocol  \
+               pthread_mutexattr_getprotocol   \
+               pthread_mutexattr_setrobust_np  \
+               pthread_condattr_getclock       \
+               pthread_condattr_setclock       \
+               pthread_spin_lock fork          \
+               pthread_attr_setaffinity_np     \
+               pthread_getattr_np              \
+               pthread_atfork                  \
+               pthread_setname_np              \
+               sched_getcpu                    \
+               clock_nanosleep])
 LIBS="$save_LIBS"
 
+dnl If we can't set the clock for condvar timeouts, then
+dnl we have to restrict the Copperplate clock to CLOCK_REALTIME.
+dnl In effect this means that updating the host system date may affect
+dnl wait times of blocking services. This is a provision for running
+dnl over legacy threading libraries such as linuxthreads.
+dnl
+dnl CAUTION: the CLOCK_COPPERPLATE value is part of the ABI between
+dnl the Xenomai core libraries and the applications. Therefore it shall
+dnl remain stable even if applications depend on a different libc
+dnl than Xenomai libraries were built against originally. Hence the
+dnl built-in CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED flag, which
+dnl won't vary for a given Xenomai installation.
+AC_CHECK_FUNC(pthread_condattr_setclock,,
+    [AC_DEFINE(CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED, 1,[config])])
+
 dnl
 dnl Produce the info needed to build xeno_config.h
 dnl
diff --git a/include/boilerplate/Makefile.am b/include/boilerplate/Makefile.am
index a9cc384..0cde61c 100644
--- a/include/boilerplate/Makefile.am
+++ b/include/boilerplate/Makefile.am
@@ -5,6 +5,7 @@ includesub_HEADERS =    \
        compiler.h      \
        debug.h         \
        hash.h          \
+       libc.h          \
        list.h          \
        lock.h          \
        obstack.h       \
diff --git a/include/boilerplate/Makefile.in b/include/boilerplate/Makefile.in
index 9108411..afd8b81 100644
--- a/include/boilerplate/Makefile.in
+++ b/include/boilerplate/Makefile.in
@@ -335,6 +335,7 @@ includesub_HEADERS = \
        compiler.h      \
        debug.h         \
        hash.h          \
+       libc.h          \
        list.h          \
        lock.h          \
        obstack.h       \
diff --git a/include/boilerplate/compiler.h b/include/boilerplate/compiler.h
index a784089..b52a585 100644
--- a/include/boilerplate/compiler.h
+++ b/include/boilerplate/compiler.h
@@ -46,4 +46,8 @@
 #define __weak         __attribute__((__weak__))
 #endif
 
+#ifndef __maybe_unused
+#define __maybe_unused __attribute__((__unused__))
+#endif
+
 #endif /* _BOILERPLATE_COMPILER_H */
diff --git a/include/boilerplate/libc.h b/include/boilerplate/libc.h
new file mode 100644
index 0000000..9379124
--- /dev/null
+++ b/include/boilerplate/libc.h
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2014 Philippe Gerum <r...@xenomai.org>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#ifndef _BOILERPLATE_LIBC_H
+#define _BOILERPLATE_LIBC_H
+
+#ifdef __IN_XENO__
+/*
+ * Quirks for dealing with outdated libc* issues.  This header will be
+ * parsed by the Xenomai implementation only, applications based on it
+ * have to provide their own set of wrappers as they should decide by
+ * themselves what to do when a feature is missing.
+ */
+#include <xeno_config.h>
+#include <errno.h>
+#include <boilerplate/compiler.h>
+
+#if defined(__UCLIBC__) && !defined(UCLIBC_HAS_THREADS_NATIVE)
+enum {
+       PTHREAD_PRIO_NONE,
+       PTHREAD_PRIO_INHERIT,
+       PTHREAD_PRIO_PROTECT
+};
+#endif /* __UCLIBC__  && !UCLIBC_HAS_THREADS_NATIVE */
+
+#ifndef HAVE_PTHREAD_ATFORK
+#ifndef HAVE_FORK
+static inline
+int pthread_atfork(void (*prepare)(void), void (*parent)(void),
+                  void (*child)(void))
+{
+       return 0;
+}
+#else
+#error "fork() without pthread_atfork()"
+#endif
+#endif /* !HAVE_PTHREAD_ATFORK */
+
+#ifndef HAVE_PTHREAD_GETATTR_NP
+static inline
+int pthread_getattr_np(pthread_t th, pthread_attr_t *attr)
+{
+       return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_GETATTR_NP */
+
+#ifndef HAVE_PTHREAD_CONDATTR_SETCLOCK
+static inline
+int pthread_condattr_setclock(pthread_condattr_t *__restrict__ attr,
+                             clockid_t clock_id)
+{
+       return clock_id == CLOCK_REALTIME ? 0 : ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_CONDATTR_SETCLOCK */
+
+#ifndef HAVE_PTHREAD_CONDATTR_GETCLOCK
+static inline
+int pthread_condattr_getclock(const pthread_condattr_t *__restrict__ attr,
+                             clockid_t *__restrict__ clock_id)
+{
+       *clock_id = CLOCK_REALTIME;
+
+       return 0;
+}
+#endif /* !HAVE_PTHREAD_CONDATTR_GETCLOCK */
+
+#ifndef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
+static inline
+int pthread_mutexattr_setprotocol(pthread_mutexattr_t *__restrict__ attr,
+                                 int protocol)
+{
+       return protocol == PTHREAD_PRIO_NONE ? 0 : ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL */
+
+#ifndef HAVE_PTHREAD_MUTEXATTR_GETPROTOCOL
+static inline
+int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *
+                                 __restrict__ attr, int *__restrict__ protocol)
+{
+       *protocol = PTHREAD_PRIO_NONE;
+
+       return 0;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_GETPROTOCOL */
+
+#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
+static inline
+int pthread_attr_setaffinity_np(pthread_attr_t *attr,
+                               size_t cpusetsize, const cpu_set_t *cpuset)
+{
+       return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_ATTR_SETAFFINITY_NP */
+
+#if !defined(HAVE_CLOCK_NANOSLEEP) && defined(CONFIG_XENO_MERCURY)
+/*
+ * Best effort for a Mercury setup based on an outdated libc lacking
+ * "advanced" real-time support.  Too bad if the system clock is set
+ * during sleep time. This is a non-issue for Cobalt, as the libcobalt
+ * implementation will always be picked instead.
+ */
+__weak inline int clock_nanosleep(clockid_t clock_id, int flags,
+                                 const struct timespec *request,
+                                 struct timespec *remain)
+{
+       struct timespec now, tmp;
+
+       tmp = *request;
+       if (flags) {
+               clock_gettime(CLOCK_REALTIME, &now);
+               tmp.tv_sec -= now.tv_sec;
+               tmp.tv_nsec -= now.tv_nsec;
+               if (tmp.tv_nsec < 0) {
+                       tmp.tv_sec--;
+                       tmp.tv_nsec += 1000000000;
+               }
+       }
+
+       return nanosleep(&tmp, remain);
+}
+#else  /* HAVE_CLOCK_NANOSLEEP || COBALT */
+/*
+ * Either libcobalt or the libc implements this, we only want the
+ * possibly missing declaration from the libc headers.
+ */
+int clock_nanosleep(clockid_t clock_id, int flags,
+                   const struct timespec *request,
+                   struct timespec *remain);
+#endif /* HAVE_CLOCK_NANOSLEEP || COBALT */
+
+#ifndef HAVE_SCHED_GETCPU
+/*
+ * Might be declared in uClibc headers but not actually implemented,
+ * so we make the placeholder a weak symbol.
+ */
+__weak inline int sched_getcpu(void)
+{
+       return 0;   /* outdated uClibc: assume uniprocessor. */
+}
+#endif /* !HAVE_SCHED_GETCPU */
+
+#ifndef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
+#define pthread_mutexattr_setrobust_np(__attr, __robust)       \
+       ({ ENOSYS; })
+#endif /* !HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP */
+
+#if !defined(HAVE_PTHREAD_SETNAME_NP) && defined(CONFIG_XENO_MERCURY)
+static inline
+int pthread_setname_np(pthread_t thread, const char *name)
+{
+       return ENOSYS;
+}
+#else /* HAVE_PTHREAD_SETNAME_NP || COBALT */
+/* Same as clock_nanosleep() */
+int pthread_setname_np(pthread_t thread, const char *name);
+#endif /* HAVE_PTHREAD_SETNAME_NP || COBALT */
+
+#endif /* __IN_XENO__ */
+
+#endif /* _BOILERPLATE_LIBC_H */
diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 58e279e..f4f9e36 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -21,6 +21,7 @@
 #ifndef _COBALT_PTHREAD_H
 #define _COBALT_PTHREAD_H
 
+#include <boilerplate/libc.h>
 #include <cobalt/wrappers.h>
 #include <cobalt/uapi/thread.h>
 
@@ -58,10 +59,6 @@ COBALT_DECL(int, pthread_setschedparam(pthread_t thread,
                                       int policy,
                                       const struct sched_param *param));
 
-#ifndef pthread_yield  /* likely uClibc wrapping otherwise. */
-COBALT_DECL(int, pthread_yield(void));
-#endif
-
 COBALT_DECL(int, pthread_mutex_init(pthread_mutex_t *mutex,
                                    const pthread_mutexattr_t *attr));
 
@@ -96,12 +93,20 @@ COBALT_DECL(int, pthread_kill(pthread_t ptid, int sig));
 
 COBALT_DECL(int, pthread_join(pthread_t ptid, void **retval));
 
+#ifndef pthread_yield
+/*
+ * linuxthreads wraps pthread_yield() to sched_yield() via a
+ * preprocessor macro, which confuses the compiler with
+ * COBALT_DECL(). Since Cobalt also routes pthread_yield() to its own
+ * sched_yield() implementation internally, we can live with this
+ * wrapping.
+ */
+COBALT_DECL(int, pthread_yield(void));
+#endif
+
 int pthread_setmode_np(int clrmask, int setmask,
                       int *mask_r);
 
-/* May be absent from outdated glibc releases. */
-int pthread_setname_np(pthread_t thread, const char *name);
-
 COBALT_DECL(int, pthread_setname_np(pthread_t thread, const char *name));
 
 int pthread_create_ex(pthread_t *ptid_r,
@@ -165,43 +170,6 @@ int pthread_attr_getpersonality_ex(const pthread_attr_ex_t 
*attr_ex,
 
 int pthread_attr_setpersonality_ex(pthread_attr_ex_t *attr_ex,
                                   int personality);
-
-#ifdef __UCLIBC__
-
-#include <errno.h>
-
-/*
- * Mutex PI and priority ceiling settings may not be available with
- * uClibc. Define the protocol values in the same terms as the
- * standard enum found in glibc to allow application code to enable
- * them.
- */
-enum {
-       PTHREAD_PRIO_NONE,
-       PTHREAD_PRIO_INHERIT,
-       PTHREAD_PRIO_PROTECT
-};
-
-/*
- * 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/copperplate/clockobj.h b/include/copperplate/clockobj.h
index 28709ae..1543589 100644
--- a/include/copperplate/clockobj.h
+++ b/include/copperplate/clockobj.h
@@ -28,17 +28,27 @@
 #include <copperplate/debug.h>
 
 /*
- * We define the Copperplate clock as a monotonic, non-adjustable
- * one. This means that delays and timeouts won't be affected when the
- * kernel host date is changed. The implementation provides support
- * for absolute dates internally, with a per-clock epoch value, so
- * that different emulators can have different system dates.
+ * We normally define the Copperplate clock as a monotonic,
+ * non-adjustable one, unless the threading library has restrictions
+ * to support this.
+ *
+ * In the normal case, this means that ongoing delays and timeouts
+ * won't be affected when the host system date is changed. In the
+ * restricted case by contrast, ongoing delays and timeouts may be
+ * impacted by changes to the host system date.
+ *
+ * The implementation maintains a per-clock epoch value, so that
+ * different emulators can have different (virtual) system dates.
  */
+#ifndef CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED
 #ifdef CONFIG_XENO_RAW_CLOCK_ENABLED
 #define CLOCK_COPPERPLATE  CLOCK_MONOTONIC_RAW
 #else
 #define CLOCK_COPPERPLATE  CLOCK_MONOTONIC
 #endif
+#else /* CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED */
+#define CLOCK_COPPERPLATE  CLOCK_REALTIME
+#endif /* CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED */
 
 struct clockobj {
        pthread_mutex_t lock;
@@ -102,6 +112,28 @@ int clockobj_destroy(struct clockobj *clkobj);
 
 #include <cobalt/ticks.h>
 
+/*
+ * The Cobalt core exclusively deals with aperiodic timings, so a
+ * Cobalt _tick_ is actually a _TSC_ unit. In contrast, Copperplate
+ * deals with _TSC_ units and periodic _ticks_ which duration depend
+ * on the clock resolution. Therefore, Cobalt ticks are strictly
+ * equivalent to Copperplate TSC units, and Copperplate ticks are
+ * periods of the reference clockobj which Cobalt does not know about.
+ */
+#ifdef CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED
+
+static inline sticks_t clockobj_ns_to_tsc(sticks_t ns)
+{
+       return ns;
+}
+
+static inline sticks_t clockobj_tsc_to_ns(sticks_t tsc)
+{
+       return tsc;
+}
+
+#else /* !CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED */
+
 static inline sticks_t clockobj_ns_to_tsc(sticks_t ns)
 {
        return cobalt_ns_to_ticks(ns);
@@ -112,6 +144,8 @@ static inline sticks_t clockobj_tsc_to_ns(sticks_t tsc)
        return cobalt_ticks_to_ns(tsc);
 }
 
+#endif /* !CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED */
+
 static inline
 void clockobj_ns_to_timespec(ticks_t ns, struct timespec *ts)
 {
diff --git a/include/mercury/Makefile.am b/include/mercury/Makefile.am
index 901e8a2..f1af838 100644
--- a/include/mercury/Makefile.am
+++ b/include/mercury/Makefile.am
@@ -1,2 +1,4 @@
 
 SUBDIRS = boilerplate
+
+noinst_HEADERS = pthread.h
diff --git a/include/mercury/Makefile.in b/include/mercury/Makefile.in
index bccfe4b..e88e419 100644
--- a/include/mercury/Makefile.in
+++ b/include/mercury/Makefile.in
@@ -13,6 +13,7 @@
 # PARTICULAR PURPOSE.
 
 @SET_MAKE@
+
 VPATH = @srcdir@
 am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
 am__make_running_with_option = \
@@ -79,7 +80,8 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 subdir = include/mercury
-DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+       $(noinst_HEADERS)
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/config/ac_prog_cc_for_build.m4 \
        $(top_srcdir)/config/libtool.m4 \
@@ -121,6 +123,7 @@ am__can_run_installinfo = \
     n|no|NO) false;; \
     *) (install-info --version) >/dev/null 2>&1;; \
   esac
+HEADERS = $(noinst_HEADERS)
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 am__recursive_targets = \
@@ -341,6 +344,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 SUBDIRS = boilerplate
+noinst_HEADERS = pthread.h
 all: all-recursive
 
 .SUFFIXES:
@@ -537,7 +541,7 @@ distdir: $(DISTFILES)
        done
 check-am: all-am
 check: check-recursive
-all-am: Makefile
+all-am: Makefile $(HEADERS)
 installdirs: installdirs-recursive
 installdirs-am:
 install: install-recursive
diff --git a/include/mercury/pthread.h b/include/mercury/pthread.h
new file mode 100644
index 0000000..dd94305
--- /dev/null
+++ b/include/mercury/pthread.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2014 Philippe Gerum <r...@xenomai.org>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#pragma GCC system_header
+#include_next <pthread.h>
+
+#include <boilerplate/libc.h>
diff --git a/include/xeno_config.h.in b/include/xeno_config.h.in
index 80446b5..015edba 100644
--- a/include/xeno_config.h.in
+++ b/include/xeno_config.h.in
@@ -25,6 +25,9 @@
 #undef CONFIG_XENO_COMPILER
 
 /* config */
+#undef CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED
+
+/* config */
 #undef CONFIG_XENO_CPU_XSC3
 
 /* config */
@@ -92,6 +95,9 @@
 
 #ifdef __IN_XENO__
 
+/* Define to 1 if you have the `clock_nanosleep' function. */
+#undef HAVE_CLOCK_NANOSLEEP
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
@@ -110,18 +116,42 @@
 /* config */
 #undef HAVE_OLD_SETAFFINITY
 
+/* Define to 1 if you have the `pthread_atfork' function. */
+#undef HAVE_PTHREAD_ATFORK
+
+/* Define to 1 if you have the `pthread_attr_setaffinity_np' function. */
+#undef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
+
+/* Define to 1 if you have the `pthread_condattr_getclock' function. */
+#undef HAVE_PTHREAD_CONDATTR_GETCLOCK
+
 /* Define to 1 if you have the `pthread_condattr_setclock' function. */
 #undef HAVE_PTHREAD_CONDATTR_SETCLOCK
 
+/* Define to 1 if you have the `pthread_getattr_np' function. */
+#undef HAVE_PTHREAD_GETATTR_NP
+
+/* Define to 1 if you have the `pthread_mutexattr_getprotocol' function. */
+#undef HAVE_PTHREAD_MUTEXATTR_GETPROTOCOL
+
 /* Define to 1 if you have the `pthread_mutexattr_setprotocol' function. */
 #undef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
 
+/* Define to 1 if you have the `pthread_mutexattr_setrobust_np' function. */
+#undef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
+
+/* Define to 1 if you have the `pthread_setname_np' function. */
+#undef HAVE_PTHREAD_SETNAME_NP
+
 /* Define to 1 if you have the `pthread_spin_lock' function. */
 #undef HAVE_PTHREAD_SPIN_LOCK
 
 /* config */
 #undef HAVE_RECENT_SETAFFINITY
 
+/* Define to 1 if you have the `sched_getcpu' function. */
+#undef HAVE_SCHED_GETCPU
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c
index 560b3a5..ad7b034 100644
--- a/lib/alchemy/mutex.c
+++ b/lib/alchemy/mutex.c
@@ -131,9 +131,8 @@ int rt_mutex_create(RT_MUTEX *mutex, const char *name)
        pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
        pthread_mutexattr_setpshared(&mattr, mutex_scope_attribute);
        pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
-#ifdef CONFIG_XENO_MERCURY
+       /* pthread_mutexattr_setrobust_np() might not be implemented. */
        pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
-#endif
        __RT(pthread_mutex_init(&mcb->lock, &mattr));
        pthread_mutexattr_destroy(&mattr);
 
diff --git a/lib/copperplate/clockobj.c b/lib/copperplate/clockobj.c
index 3ad568d..18c45ca 100644
--- a/lib/copperplate/clockobj.c
+++ b/lib/copperplate/clockobj.c
@@ -233,8 +233,15 @@ int clockobj_set_resolution(struct clockobj *clkobj, 
unsigned int resolution_ns)
 
 ticks_t clockobj_get_tsc(void)
 {
+#ifdef CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED
+       /* Rare case with legacy uClibc+linuxthreads combo. */
+       struct timespec now;
+       __RT(clock_gettime(CLOCK_REALTIME, &now));
+       return xnarch_ullmul(now.tv_sec, 1000000000) + now.tv_nsec;
+#else
        /* Guaranteed to be the source of CLOCK_COPPERPLATE. */
        return cobalt_read_tsc();
+#endif
 }
 
 #ifndef CONFIG_XENO_LORES_CLOCK_DISABLED
diff --git a/lib/copperplate/syncobj.c b/lib/copperplate/syncobj.c
index 40b0997..9968a40 100644
--- a/lib/copperplate/syncobj.c
+++ b/lib/copperplate/syncobj.c
@@ -203,10 +203,14 @@ static inline int syncobj_init_corespec(struct syncobj 
*sobj,
 
        pthread_condattr_init(&cattr);
        pthread_condattr_setpshared(&cattr, mutex_scope_attribute);
-       pthread_condattr_setclock(&cattr, clk_id);
+       ret = __bt(pthread_condattr_setclock(&cattr, clk_id));
+       if (ret)
+               goto fail;
+
        ret = __bt(-pthread_cond_init(&sobj->core.drain_sync, &cattr));
        pthread_condattr_destroy(&cattr);
        if (ret) {
+       fail:
                pthread_mutex_destroy(&sobj->core.lock);
                return ret;
        }
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 462eb1e..923bf83 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -556,8 +556,9 @@ static inline int threadobj_init_corespec(struct threadobj 
*thobj)
         */
        pthread_condattr_init(&cattr);
        pthread_condattr_setpshared(&cattr, mutex_scope_attribute);
-       pthread_condattr_setclock(&cattr, CLOCK_COPPERPLATE);
-       ret = __bt(-pthread_cond_init(&thobj->core.grant_sync, &cattr));
+       ret = __bt(pthread_condattr_setclock(&cattr, CLOCK_COPPERPLATE));
+       if (ret == 0)
+               ret = __bt(-pthread_cond_init(&thobj->core.grant_sync, &cattr));
        pthread_condattr_destroy(&cattr);
 
        return ret;
diff --git a/lib/vxworks/semLib.c b/lib/vxworks/semLib.c
index 0dfb819..d033289 100644
--- a/lib/vxworks/semLib.c
+++ b/lib/vxworks/semLib.c
@@ -411,9 +411,8 @@ SEM_ID semMCreate(int options)
         */
        pthread_mutexattr_init(&mattr);
        pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
-#ifdef CONFIG_XENO_MERCURY
+       /* pthread_mutexattr_setrobust_np() might not be implemented. */
        pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
-#endif
        if (options & SEM_INVERSION_SAFE)
                pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
        pthread_mutexattr_setpshared(&mattr, mutex_scope_attribute);
diff --git a/testsuite/regression/posix/leaks.c 
b/testsuite/regression/posix/leaks.c
index 4e8a769..8673ba6 100644
--- a/testsuite/regression/posix/leaks.c
+++ b/testsuite/regression/posix/leaks.c
@@ -12,6 +12,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <linux/unistd.h>
+#include <boilerplate/compiler.h>
 #include <cobalt/uapi/kernel/heap.h>
 #include <asm/xenomai/syscall.h>
 
@@ -53,7 +54,7 @@ static void *empty(void *cookie)
        return cookie;
 }
 
-static void subprocess_leak(void)
+static inline void subprocess_leak(void)
 {
        struct sigevent sevt;
        pthread_mutex_t mutex;
@@ -85,7 +86,7 @@ int main(void)
        pthread_t thread;
        sem_t sem, *psem;
        timer_t tm;
-       pid_t child;
+       __maybe_unused pid_t child;
 
        mlockall(MCL_CURRENT|MCL_FUTURE);
 
@@ -132,6 +133,7 @@ int main(void)
        check_unix(mq_unlink(MQ_NAME));
        check_used("mq", before, failed);
 
+#ifdef HAVE_FORK
        before = get_used();
        check_unix(child = fork());
        if (!child) {
@@ -144,6 +146,7 @@ int main(void)
        check_unix(sem_unlink(SEM_NAME));
        check_unix(mq_unlink(MQ_NAME));
        check_used("fork", before, failed);
+#endif
 
        return failed ? EXIT_FAILURE : EXIT_SUCCESS;
 }
diff --git a/testsuite/smokey/cond-torture/cond-torture.c 
b/testsuite/smokey/cond-torture/cond-torture.c
index 1652915..54fcea5 100644
--- a/testsuite/smokey/cond-torture/cond-torture.c
+++ b/testsuite/smokey/cond-torture/cond-torture.c
@@ -74,22 +74,19 @@ static int mutex_init(pthread_mutex_t *mutex, int type, int 
pi)
 static int cond_init(pthread_cond_t *cond, int absolute)
 {
        pthread_condattr_t cattr;
-       int err;
+       int ret;
 
        pthread_condattr_init(&cattr);
-#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
-       pthread_condattr_setclock(&cattr,
-                                 absolute ? CLOCK_REALTIME : CLOCK_MONOTONIC);
-#else
-       if (!absolute) {
+       ret = pthread_condattr_setclock(&cattr,
+                                       absolute ? CLOCK_REALTIME : 
CLOCK_MONOTONIC);
+       if (ret) {
                pthread_condattr_destroy(&cattr);
                return ENOSYS;
        }
-#endif
-       err = pthread_cond_init(cond, &cattr);
+       ret = pthread_cond_init(cond, &cattr);
        pthread_condattr_destroy(&cattr);
 
-       return -err;
+       return -ret;
 }
 #define cond_signal(cond) (-pthread_cond_signal(cond))
 


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

Reply via email to