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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Aug  1 12:33:27 2014 +0200

trank: more compatibility calls

---

 aclocal.m4                     |   15 +++
 config/config.guess            |  151 +++++++++++++----------------
 config/config.sub              |   30 +++---
 include/alchemy/Makefile.am    |    1 +
 include/alchemy/Makefile.in    |    1 +
 include/alchemy/alarm.h        |   11 ++-
 include/alchemy/compat.h       |   23 +++++
 include/alchemy/task.h         |   23 ++---
 include/boilerplate/compiler.h |    3 +
 include/cobalt/wrappers.h      |    4 +-
 include/trank/Makefile.am      |    2 +-
 include/trank/Makefile.in      |    2 +-
 include/trank/native/alarm.h   |   12 +--
 include/trank/native/misc.h    |    5 +-
 include/trank/native/task.h    |   23 +++--
 include/trank/native/timer.h   |    3 +-
 include/trank/trank.h          |   47 +++++++++
 include/version.h              |    3 +-
 lib/alchemy/alarm.h            |    4 +-
 lib/alchemy/task.c             |   15 +--
 lib/trank/Makefile.am          |    7 +-
 lib/trank/Makefile.in          |    5 +-
 lib/trank/native.c             |  204 ++++++++++++++++++++++++++++++++++++++++
 scripts/xeno-config-cobalt.in  |    2 +-
 24 files changed, 442 insertions(+), 154 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index d7bb46a..f473e28 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -220,6 +220,21 @@ m4_popdef([pkg_default])
 m4_popdef([pkg_description])
 ]) dnl PKG_NOARCH_INSTALLDIR
 
+
+# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
+# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+# -------------------------------------------
+# Retrieves the value of the pkg-config variable for the given module.
+AC_DEFUN([PKG_CHECK_VAR],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
+
+_PKG_CONFIG([$1], [variable="][$3]["], [$2])
+AS_VAR_COPY([$1], [pkg_cv_][$1])
+
+AS_VAR_IF([$1], [""], [$5], [$4])dnl
+])# PKG_CHECK_VAR
+
 # Copyright (C) 2002-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
diff --git a/config/config.guess b/config/config.guess
index b79252d..1804e9f 100755
--- a/config/config.guess
+++ b/config/config.guess
@@ -1,8 +1,10 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright 1992-2013 Free Software Foundation, Inc.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+#   2011, 2012, 2013 Free Software Foundation, Inc.
 
-timestamp='2013-06-10'
+timestamp='2012-12-29'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -24,7 +26,7 @@ timestamp='2013-06-10'
 # program.  This Exception is an additional permission under section 7
 # of the GNU General Public License, version 3 ("GPLv3").
 #
-# Originally written by Per Bothner.
+# Originally written by Per Bothner. 
 #
 # You can get the latest version of this script from:
 # 
http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
@@ -50,7 +52,9 @@ version="\
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright 1992-2013 Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012, 2013 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -132,27 +136,6 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || 
UNAME_RELEASE=unknown
 UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
 UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
 
-case "${UNAME_SYSTEM}" in
-Linux|GNU|GNU/*)
-       # If the system lacks a compiler, then just pick glibc.
-       # We could probably try harder.
-       LIBC=gnu
-
-       eval $set_cc_for_build
-       cat <<-EOF > $dummy.c
-       #include <features.h>
-       #if defined(__UCLIBC__)
-       LIBC=uclibc
-       #elif defined(__dietlibc__)
-       LIBC=dietlibc
-       #else
-       LIBC=gnu
-       #endif
-       EOF
-       eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
-       ;;
-esac
-
 # Note: order is significant - the case branches are not exclusive.
 
 case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
@@ -874,21 +857,21 @@ EOF
        exit ;;
     *:GNU:*:*)
        # the GNU system
-       echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo 
${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+       echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo 
${UNAME_RELEASE}|sed -e 's,/.*$,,'`
        exit ;;
     *:GNU/*:*:*)
        # other systems with GNU libc and userland
-       echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' 
| tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' 
| tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
        exit ;;
     i*86:Minix:*:*)
        echo ${UNAME_MACHINE}-pc-minix
        exit ;;
     aarch64:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     aarch64_be:Linux:*:*)
        UNAME_MACHINE=aarch64_be
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     alpha:Linux:*:*)
        case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
@@ -901,54 +884,59 @@ EOF
          EV68*) UNAME_MACHINE=alphaev68 ;;
        esac
        objdump --private-headers /bin/sh | grep -q ld.so.1
-       if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
-       exit ;;
-    arc:Linux:*:* | arceb:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
+       echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
        exit ;;
     arm*:Linux:*:*)
        eval $set_cc_for_build
        if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
            | grep -q __ARM_EABI__
        then
-           echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+           echo ${UNAME_MACHINE}-unknown-linux-gnu
        else
            if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
                | grep -q __ARM_PCS_VFP
            then
-               echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
+               echo ${UNAME_MACHINE}-unknown-linux-gnueabi
            else
-               echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
+               echo ${UNAME_MACHINE}-unknown-linux-gnueabihf
            fi
        fi
        exit ;;
     avr32*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     cris:Linux:*:*)
-       echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+       echo ${UNAME_MACHINE}-axis-linux-gnu
        exit ;;
     crisv32:Linux:*:*)
-       echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+       echo ${UNAME_MACHINE}-axis-linux-gnu
        exit ;;
     frv:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     hexagon:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     i*86:Linux:*:*)
-       echo ${UNAME_MACHINE}-pc-linux-${LIBC}
+       LIBC=gnu
+       eval $set_cc_for_build
+       sed 's/^        //' << EOF >$dummy.c
+       #ifdef __dietlibc__
+       LIBC=dietlibc
+       #endif
+EOF
+       eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
+       echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
        exit ;;
     ia64:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     m32r*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     m68*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     mips:Linux:*:* | mips64:Linux:*:*)
        eval $set_cc_for_build
@@ -967,63 +955,54 @@ EOF
        #endif
 EOF
        eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
-       test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
+       test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
        ;;
-    or1k:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
-       exit ;;
     or32:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     padre:Linux:*:*)
-       echo sparc-unknown-linux-${LIBC}
+       echo sparc-unknown-linux-gnu
        exit ;;
     parisc64:Linux:*:* | hppa64:Linux:*:*)
-       echo hppa64-unknown-linux-${LIBC}
+       echo hppa64-unknown-linux-gnu
        exit ;;
     parisc:Linux:*:* | hppa:Linux:*:*)
        # Look for CPU level
        case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
-         PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
-         PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
-         *)    echo hppa-unknown-linux-${LIBC} ;;
+         PA7*) echo hppa1.1-unknown-linux-gnu ;;
+         PA8*) echo hppa2.0-unknown-linux-gnu ;;
+         *)    echo hppa-unknown-linux-gnu ;;
        esac
        exit ;;
     ppc64:Linux:*:*)
-       echo powerpc64-unknown-linux-${LIBC}
+       echo powerpc64-unknown-linux-gnu
        exit ;;
     ppc:Linux:*:*)
-       echo powerpc-unknown-linux-${LIBC}
-       exit ;;
-    ppc64le:Linux:*:*)
-       echo powerpc64le-unknown-linux-${LIBC}
-       exit ;;
-    ppcle:Linux:*:*)
-       echo powerpcle-unknown-linux-${LIBC}
+       echo powerpc-unknown-linux-gnu
        exit ;;
     s390:Linux:*:* | s390x:Linux:*:*)
-       echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
+       echo ${UNAME_MACHINE}-ibm-linux
        exit ;;
     sh64*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     sh*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     sparc:Linux:*:* | sparc64:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     tile*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     vax:Linux:*:*)
-       echo ${UNAME_MACHINE}-dec-linux-${LIBC}
+       echo ${UNAME_MACHINE}-dec-linux-gnu
        exit ;;
     x86_64:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     xtensa*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
        exit ;;
     i*86:DYNIX/ptx:4*:*)
        # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
@@ -1256,21 +1235,19 @@ EOF
        exit ;;
     *:Darwin:*:*)
        UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
-       eval $set_cc_for_build
-       if test "$UNAME_PROCESSOR" = unknown ; then
-           UNAME_PROCESSOR=powerpc
-       fi
-       if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
-           if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
-               (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
-               grep IS_64BIT_ARCH >/dev/null
-           then
-               case $UNAME_PROCESSOR in
-                   i386) UNAME_PROCESSOR=x86_64 ;;
-                   powerpc) UNAME_PROCESSOR=powerpc64 ;;
-               esac
-           fi
-       fi
+       case $UNAME_PROCESSOR in
+           i386)
+               eval $set_cc_for_build
+               if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+                 if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo 
'#endif') | \
+                     (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+                     grep IS_64BIT_ARCH >/dev/null
+                 then
+                     UNAME_PROCESSOR="x86_64"
+                 fi
+               fi ;;
+           unknown) UNAME_PROCESSOR=powerpc ;;
+       esac
        echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
        exit ;;
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
diff --git a/config/config.sub b/config/config.sub
index c765b34..52f04bc 100755
--- a/config/config.sub
+++ b/config/config.sub
@@ -1,8 +1,10 @@
 #! /bin/sh
 # Configuration validation subroutine script.
-#   Copyright 1992-2013 Free Software Foundation, Inc.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+#   2011, 2012, 2013 Free Software Foundation, Inc.
 
-timestamp='2013-04-24'
+timestamp='2012-12-29'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -68,7 +70,9 @@ Report bugs and patches to <config-patc...@gnu.org>."
 version="\
 GNU config.sub ($timestamp)
 
-Copyright 1992-2013 Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012, 2013 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -252,7 +256,7 @@ case $basic_machine in
        | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
        | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | 
alpha64pca5[67] \
        | am33_2.0 \
-       | arc | arceb \
+       | arc \
        | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
        | avr | avr32 \
        | be32 | be64 \
@@ -286,17 +290,16 @@ case $basic_machine in
        | mipsisa64r2 | mipsisa64r2el \
        | mipsisa64sb1 | mipsisa64sb1el \
        | mipsisa64sr71k | mipsisa64sr71kel \
-       | mipsr5900 | mipsr5900el \
        | mipstx39 | mipstx39el \
        | mn10200 | mn10300 \
        | moxie \
        | mt \
        | msp430 \
        | nds32 | nds32le | nds32be \
-       | nios | nios2 | nios2eb | nios2el \
+       | nios | nios2 \
        | ns16k | ns32k \
        | open8 \
-       | or1k | or32 \
+       | or32 \
        | pdp10 | pdp11 | pj | pjl \
        | powerpc | powerpc64 | powerpc64le | powerpcle \
        | pyramid \
@@ -366,7 +369,7 @@ case $basic_machine in
        | aarch64-* | aarch64_be-* \
        | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
        | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
-       | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
+       | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
        | arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
        | avr-* | avr32-* \
        | be32-* | be64-* \
@@ -404,13 +407,12 @@ case $basic_machine in
        | mipsisa64r2-* | mipsisa64r2el-* \
        | mipsisa64sb1-* | mipsisa64sb1el-* \
        | mipsisa64sr71k-* | mipsisa64sr71kel-* \
-       | mipsr5900-* | mipsr5900el-* \
        | mipstx39-* | mipstx39el-* \
        | mmix-* \
        | mt-* \
        | msp430-* \
        | nds32-* | nds32le-* | nds32be-* \
-       | nios-* | nios2-* | nios2eb-* | nios2el-* \
+       | nios-* | nios2-* \
        | none-* | np1-* | ns16k-* | ns32k-* \
        | open8-* \
        | orion-* \
@@ -1352,7 +1354,7 @@ case $os in
        -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
              | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | 
-sunos[34]*\
              | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | 
-solaris* \
-             | -sym* | -kopensolaris* | -plan9* \
+             | -sym* | -kopensolaris* \
              | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
              | -aos* | -aros* \
              | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
@@ -1498,6 +1500,9 @@ case $os in
        -aros*)
                os=-aros
                ;;
+       -kaos*)
+               os=-kaos
+               ;;
        -zvmoe)
                os=-zvmoe
                ;;
@@ -1589,9 +1594,6 @@ case $basic_machine in
        mips*-*)
                os=-elf
                ;;
-       or1k-*)
-               os=-elf
-               ;;
        or32-*)
                os=-coff
                ;;
diff --git a/include/alchemy/Makefile.am b/include/alchemy/Makefile.am
index d590620..8cbc3b8 100644
--- a/include/alchemy/Makefile.am
+++ b/include/alchemy/Makefile.am
@@ -3,6 +3,7 @@ includesubdir = $(includedir)/alchemy
 includesub_HEADERS =   \
        alarm.h         \
        buffer.h        \
+       compat.h        \
        cond.h          \
        event.h         \
        heap.h          \
diff --git a/include/alchemy/Makefile.in b/include/alchemy/Makefile.in
index beb1bb9..8ce41a7 100644
--- a/include/alchemy/Makefile.in
+++ b/include/alchemy/Makefile.in
@@ -333,6 +333,7 @@ includesubdir = $(includedir)/alchemy
 includesub_HEADERS = \
        alarm.h         \
        buffer.h        \
+       compat.h        \
        cond.h          \
        event.h         \
        heap.h          \
diff --git a/include/alchemy/alarm.h b/include/alchemy/alarm.h
index c6f4b8a..b57197a 100644
--- a/include/alchemy/alarm.h
+++ b/include/alchemy/alarm.h
@@ -20,6 +20,7 @@
 
 #include <stdint.h>
 #include <alchemy/timer.h>
+#include <alchemy/compat.h>
 
 /**
  * @addtogroup alchemy_alarm
@@ -60,12 +61,12 @@ typedef struct RT_ALARM_INFO RT_ALARM_INFO;
 extern "C" {
 #endif
 
-int rt_alarm_create(RT_ALARM *alarm,
-                   const char *name,
-                   void (*handler)(void *arg),
-                   void *arg);
+CURRENT_DECL(int, rt_alarm_create(RT_ALARM *alarm,
+                                 const char *name,
+                                 void (*handler)(void *arg),
+                                 void *arg));
 
-int rt_alarm_delete(RT_ALARM *alarm);
+CURRENT_DECL(int, rt_alarm_delete(RT_ALARM *alarm));
 
 int rt_alarm_start(RT_ALARM *alarm,
                   RTIME value,
diff --git a/include/alchemy/compat.h b/include/alchemy/compat.h
new file mode 100644
index 0000000..0113879
--- /dev/null
+++ b/include/alchemy/compat.h
@@ -0,0 +1,23 @@
+/*
+ * 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 _XENOMAI_ALCHEMY_COMPAT_H
+#define _XENOMAI_ALCHEMY_COMPAT_H
+
+#include <trank/trank.h>
+
+#endif /* _XENOMAI_ALCHEMY_COMPAT_H */
diff --git a/include/alchemy/task.h b/include/alchemy/task.h
index fc5700c..cc3e3c0 100644
--- a/include/alchemy/task.h
+++ b/include/alchemy/task.h
@@ -24,6 +24,7 @@
 #include <boilerplate/list.h>
 #include <copperplate/threadobj.h>
 #include <alchemy/timer.h>
+#include <alchemy/compat.h>
 
 /**
  * @addtogroup alchemy_task
@@ -91,11 +92,11 @@ typedef struct RT_TASK_INFO RT_TASK_INFO;
 extern "C" {
 #endif
 
-int rt_task_create(RT_TASK *task,
-                  const char *name,
-                  int stksize,
-                  int prio,
-                  int mode);
+CURRENT_DECL(int, rt_task_create(RT_TASK *task,
+                                const char *name,
+                                int stksize,
+                                int prio,
+                                int mode));
 
 int rt_task_delete(RT_TASK *task);
 
@@ -106,10 +107,10 @@ int rt_task_start(RT_TASK *task,
                  void (*entry)(void *arg),
                  void *arg);
 
-int rt_task_spawn(RT_TASK *task, const char *name,
-                 int stksize, int prio, int mode,
-                 void (*entry)(void *arg),
-                 void *arg);
+CURRENT_DECL(int, rt_task_spawn(RT_TASK *task, const char *name,
+                               int stksize, int prio, int mode,
+                               void (*entry)(void *arg),
+                               void *arg));
 
 int rt_task_shadow(RT_TASK *task,
                   const char *name,
@@ -118,8 +119,8 @@ int rt_task_shadow(RT_TASK *task,
 
 int rt_task_join(RT_TASK *task);
 
-int rt_task_set_periodic(RT_TASK *task,
-                        RTIME idate, RTIME period);
+CURRENT_DECL(int, rt_task_set_periodic(RT_TASK *task,
+                                      RTIME idate, RTIME period));
 
 int rt_task_wait_period(unsigned long *overruns_r);
 
diff --git a/include/boilerplate/compiler.h b/include/boilerplate/compiler.h
index 2ee52b1..a784089 100644
--- a/include/boilerplate/compiler.h
+++ b/include/boilerplate/compiler.h
@@ -26,6 +26,9 @@
                (type *)((char *)__mptr - offsetof(type, member));      \
        })
 
+#define __stringify_1(x...)    #x
+#define __stringify(x...)      __stringify_1(x)
+
 #ifndef likely
 #define likely(x)      __builtin_expect(!!(x), 1)
 #define unlikely(x)    __builtin_expect(!!(x), 0)
diff --git a/include/cobalt/wrappers.h b/include/cobalt/wrappers.h
index aab50e6..975f7a3 100644
--- a/include/cobalt/wrappers.h
+++ b/include/cobalt/wrappers.h
@@ -47,7 +47,7 @@
  * referenced as __COBALT(foo).
  */
 #define COBALT_IMPL(T, I, A)                                                   
        \
-typeof(T) __wrap_ ## I A __attribute__((alias("__cobalt_" __stringify(I)), 
weak));     \
-typeof(T) __cobalt_ ## I A
+__typeof__(T) __wrap_ ## I A __attribute__((alias("__cobalt_" __stringify(I)), 
weak)); \
+__typeof__(T) __cobalt_ ## I A
 
 #endif /* !_COBALT_WRAPPERS_H */
diff --git a/include/trank/Makefile.am b/include/trank/Makefile.am
index d67df25..4a20401 100644
--- a/include/trank/Makefile.am
+++ b/include/trank/Makefile.am
@@ -1,5 +1,5 @@
 includesubdir = $(includedir)/trank
 
-includesub_HEADERS = rtdk.h
+includesub_HEADERS = rtdk.h trank.h
 
 SUBDIRS = posix native rtdm
diff --git a/include/trank/Makefile.in b/include/trank/Makefile.in
index a52bd9b..5db5756 100644
--- a/include/trank/Makefile.in
+++ b/include/trank/Makefile.in
@@ -372,7 +372,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 includesubdir = $(includedir)/trank
-includesub_HEADERS = rtdk.h
+includesub_HEADERS = rtdk.h trank.h
 SUBDIRS = posix native rtdm
 all: all-recursive
 
diff --git a/include/trank/native/alarm.h b/include/trank/native/alarm.h
index 490c279..8096133 100644
--- a/include/trank/native/alarm.h
+++ b/include/trank/native/alarm.h
@@ -18,13 +18,13 @@
 #ifndef _XENOMAI_TRANK_NATIVE_ALARM_H
 #define _XENOMAI_TRANK_NATIVE_ALARM_H
 
+#include <trank/trank.h>
 #include <alchemy/alarm.h>
 
-__attribute__((__deprecated__))
-static inline int rt_alarm_wait(RT_ALARM *alarm);
-{
-       warning("rt_alarm_create() should be passed a handler");
-       return -ENOSYS;
-}
+COMPAT_DECL(int, rt_alarm_create(RT_ALARM *alarm, const char *name));
+
+COMPAT_DECL(int, rt_alarm_wait(RT_ALARM *alarm));
+
+COMPAT_DECL(int, rt_alarm_delete(RT_ALARM *alarm));
 
 #endif /* _XENOMAI_TRANK_NATIVE_ALARM_H */
diff --git a/include/trank/native/misc.h b/include/trank/native/misc.h
index c8575ff..b5255fa 100644
--- a/include/trank/native/misc.h
+++ b/include/trank/native/misc.h
@@ -20,6 +20,7 @@
 
 #include <stdint.h>
 #include <errno.h>
+#include <trank/trank.h>
 
 #define IORN_IOPORT  0
 #define IORN_IOMEM   0
@@ -34,14 +35,14 @@ static inline int rt_io_get_region(RT_IOREGION *iorn,
                                   uint64_t len,
                                   int flags)
 {
-       warning("service should be provided by a RTDM driver");
+       trank_warning("service should be provided by a RTDM driver");
        return -ENOSYS;
 }
 
 __attribute__((__deprecated__))
 int rt_io_put_region(RT_IOREGION *iorn)
 {
-       warning("service should be provided by a RTDM driver");
+       trank_warning("service should be provided by a RTDM driver");
        return -ENOSYS;
 }
 
diff --git a/include/trank/native/task.h b/include/trank/native/task.h
index 66479bf..f2fb1dd 100644
--- a/include/trank/native/task.h
+++ b/include/trank/native/task.h
@@ -20,23 +20,32 @@
 
 #include <errno.h>
 #include <alchemy/task.h>
+#include <trank/trank.h>
 #include <trank/native/types.h>
 
 #define T_FPU    0
 #define T_NOSIG  0
+#define T_SUSP  __THREAD_M_SPARE7
+
+/* bit #24 onward are otherwise unused. */
+#define T_CPU(cpu) (1 << (24 + (cpu & 7)))
+#define T_CPUMASK  0xff000000
 
 __attribute__((__deprecated__))
 static inline int rt_task_notify(RT_TASK *task, rt_sigset_t sigs)
 {
-       warning("in-kernel native API is gone, rebase over RTDM");
+       trank_warning("in-kernel native API is gone, rebase over RTDM");
        return -ENOSYS;
 }
 
-__attribute__((__deprecated__))
-static inline int T_CPU(int cpu)
-{
-       warning("use rt_task_set_affinity() instead");
-       return 0;
-}
+COMPAT_DECL(int, rt_task_create(RT_TASK *task, const char *name,
+                               int stksize, int prio, int mode));
+
+COMPAT_DECL(int, rt_task_spawn(RT_TASK *task, const char *name,
+                              int stksize, int prio, int mode,
+                              void (*entry)(void *arg), void *arg));
+
+COMPAT_DECL(int, rt_task_set_periodic(RT_TASK *task,
+                                     RTIME idate, RTIME period));
 
 #endif /* _XENOMAI_TRANK_NATIVE_TASK_H */
diff --git a/include/trank/native/timer.h b/include/trank/native/timer.h
index 022cd9e..396b5ec 100644
--- a/include/trank/native/timer.h
+++ b/include/trank/native/timer.h
@@ -18,6 +18,7 @@
 #ifndef _XENOMAI_TRANK_NATIVE_TIMER_H
 #define _XENOMAI_TRANK_NATIVE_TIMER_H
 
+#include <trank/trank.h>
 #include <alchemy/timer.h>
 
 #define TM_ONESHOT  0
@@ -27,7 +28,7 @@ static inline int rt_timer_set_mode(RTIME nstick)
 {
 #ifdef CONFIG_XENO_LORES_CLOCK_DISABLED
        if (nstick != TM_ONESHOT) {
-               warning("start program with --alchemy-clock-resolution option 
instead");
+               trank_warning("start program with --alchemy-clock-resolution 
option instead");
                return -ENODEV;
        }
 #endif
diff --git a/include/trank/trank.h b/include/trank/trank.h
new file mode 100644
index 0000000..60f5f3e
--- /dev/null
+++ b/include/trank/trank.h
@@ -0,0 +1,47 @@
+/*
+ * 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 _XENOMAI_TRANK_TRANK_H
+#define _XENOMAI_TRANK_TRANK_H
+
+#ifdef __XENO_COMPAT__
+
+#define trank_warning(__fmt, __args...)        \
+       warning("%s: " __fmt, __func__, ##__args)
+
+#define __CURRENT(call)                __trank_ ## call
+
+#define COMPAT_DECL(T, P)      __typeof__(T) P
+#define CURRENT_DECL(T, P)     __typeof__(T) __CURRENT(P)
+
+#else /* !__XENO_COMPAT__ */
+
+#include <boilerplate/compiler.h>
+
+#define __CURRENT(call)                call
+
+#define COMPAT_DECL(T, P)
+#define CURRENT_DECL(T, P)     __typeof__(T) P;        \
+                               __typeof__(T) __trank_ ## P
+
+#define CURRENT_IMPL(T, I, A)          \
+__typeof__(T) I A __attribute__((alias("__trank_" __stringify(I)), weak)); \
+__typeof__(T) __trank_ ## I A
+
+#endif /* !__XENO_COMPAT__ */
+
+#endif /* _XENOMAI_TRANK_TRANK_H */
diff --git a/include/version.h b/include/version.h
index 4e6c32f..2abc481 100644
--- a/include/version.h
+++ b/include/version.h
@@ -20,8 +20,7 @@
 
 #ifndef __KERNEL__
 #include <xeno_config.h>
-#define __stringify_1(x...)    #x
-#define __stringify(x...)      __stringify_1(x)
+#include <boilerplate/compiler.h>
 #endif
 
 #define XENO_VERSION(maj, min, rev)  (((maj)<<16)|((min)<<8)|(rev))
diff --git a/lib/alchemy/alarm.h b/lib/alchemy/alarm.h
index 24ba455..3fa4296 100644
--- a/lib/alchemy/alarm.h
+++ b/lib/alchemy/alarm.h
@@ -24,6 +24,8 @@
 #include <copperplate/cluster.h>
 #include <alchemy/alarm.h>
 
+#define alarm_magic    0x8888ebeb
+
 struct alchemy_alarm {
        unsigned int magic;     /* Must be first. */
        char name[XNOBJECT_NAME_LEN];
@@ -36,8 +38,6 @@ struct alchemy_alarm {
        struct fsobj fsobj;
 };
 
-#define alarm_magic    0x8888ebeb
-
 extern struct pvcluster alchemy_alarm_table;
 
 #endif /* _ALCHEMY_ALARM_H */
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index 2238934..18ceb35 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -404,8 +404,8 @@ fail_syncinit:
  * @note Tasks can be referred to from multiple processes which all
  * belong to the same Xenomai session.
  */
-int rt_task_create(RT_TASK *task, const char *name,
-                  int stksize, int prio, int mode)
+CURRENT_IMPL(int, rt_task_create, (RT_TASK *task, const char *name,
+                                  int stksize, int prio, int mode))
 {
        struct corethread_attributes cta;
        struct alchemy_task *tcb;
@@ -808,7 +808,8 @@ undo:
  * multiple of the Alchemy clock resolution (see
  * --alchemy-clock-resolution option, defaults to 1 nanosecond).
  */
-int rt_task_set_periodic(RT_TASK *task, RTIME idate, RTIME period)
+CURRENT_IMPL(int, rt_task_set_periodic,
+            (RT_TASK *task, RTIME idate, RTIME period))
 {
        struct timespec its, pts, now;
        struct alchemy_task *tcb;
@@ -1025,10 +1026,10 @@ int rt_task_sleep(RTIME delay)
  *
  * @sideeffect see rt_task_create().
  */
-int rt_task_spawn(RT_TASK *task, const char *name,
-                 int stksize, int prio, int mode,
-                 void (*entry)(void *arg),
-                 void *arg)
+CURRENT_IMPL(int, rt_task_spawn, (RT_TASK *task, const char *name,
+                                 int stksize, int prio, int mode,
+                                 void (*entry)(void *arg),
+                                 void *arg))
 {
        int ret;
 
diff --git a/lib/trank/Makefile.am b/lib/trank/Makefile.am
index 9546b8b..89b2f13 100644
--- a/lib/trank/Makefile.am
+++ b/lib/trank/Makefile.am
@@ -11,7 +11,8 @@ libtrank_la_SOURCES = \
        posix.c         \
        native.c
 
-libtrank_la_CPPFLAGS =                 \
-       @XENO_USER_CFLAGS@              \
-       -I$(top_srcdir)/include         \
+libtrank_la_CPPFLAGS =         \
+       @XENO_USER_CFLAGS@      \
+       -D__XENO_COMPAT__       \
+       -I$(top_srcdir)/include \
        -I$(top_srcdir)/lib
diff --git a/lib/trank/Makefile.in b/lib/trank/Makefile.in
index 11c6b54..4945b70 100644
--- a/lib/trank/Makefile.in
+++ b/lib/trank/Makefile.in
@@ -373,8 +373,9 @@ libtrank_la_SOURCES = \
        native.c
 
 libtrank_la_CPPFLAGS = \
-       @XENO_USER_CFLAGS@              \
-       -I$(top_srcdir)/include         \
+       @XENO_USER_CFLAGS@      \
+       -D__XENO_COMPAT__       \
+       -I$(top_srcdir)/include \
        -I$(top_srcdir)/lib
 
 all: all-am
diff --git a/lib/trank/native.c b/lib/trank/native.c
index 5dc6407..1f44368 100644
--- a/lib/trank/native.c
+++ b/lib/trank/native.c
@@ -15,4 +15,208 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+#include <copperplate/threadobj.h>
+#include <copperplate/heapobj.h>
 #include <trank/native/task.h>
+#include <trank/native/alarm.h>
+#include "../alchemy/alarm.h"
+
+int rt_task_create(RT_TASK *task, const char *name,
+                  int stksize, int prio, int mode)
+{
+       int ret, susp, cpus, cpu;
+       cpu_set_t cpuset;
+
+       susp = mode & T_SUSP;
+       cpus = mode & T_CPUMASK;
+       ret = __CURRENT(rt_task_create(task, name, stksize, prio,
+                                      mode & ~(T_SUSP|T_CPUMASK)));
+       if (ret)
+               return ret;
+
+       if (cpus) {
+               CPU_ZERO(&cpuset);
+               for (cpu = 0, cpus >>= 24;
+                    cpus && cpu < 8; cpu++, cpus >>= 1) {
+                       if (cpus & 1)
+                               CPU_SET(cpu, &cpuset);
+               }
+               ret = rt_task_set_affinity(task, &cpuset);
+               if (ret) {
+                       rt_task_delete(task);
+                       return ret;
+               }
+       }
+
+       return susp ? rt_task_suspend(task) : 0;
+}
+
+int rt_task_spawn(RT_TASK *task, const char *name,
+                 int stksize, int prio, int mode,
+                 void (*entry)(void *arg), void *arg)
+{
+       int ret;
+
+       ret = rt_task_create(task, name, stksize, prio, mode);
+       if (ret)
+               return ret;
+
+       return rt_task_start(task, entry, arg);
+}
+
+int rt_task_set_periodic(RT_TASK *task, RTIME idate, RTIME period)
+{
+       int ret;
+
+       ret = __CURRENT(rt_task_set_periodic(task, idate, period));
+       if (ret)
+               return ret;
+
+       if (idate != TM_NOW) {
+               if (task == NULL || task == rt_task_self())
+                       ret = rt_task_wait_period(NULL);
+               else
+                       trank_warning("task won't wait for start time");
+       }
+
+       return ret;
+}
+
+struct trank_alarm_wait {
+       pthread_mutex_t lock;
+       pthread_cond_t event;
+       int alarm_pulses;
+};
+
+static void trank_alarm_handler(void *arg)
+{
+       struct trank_alarm_wait *aw = arg;
+
+       __RT(pthread_mutex_lock(&aw->lock));
+       aw->alarm_pulses++;
+       __RT(pthread_cond_broadcast(&aw->event));
+       __RT(pthread_mutex_unlock(&aw->lock));
+}
+
+int rt_alarm_create(RT_ALARM *alarm, const char *name)
+{
+       struct trank_alarm_wait *aw;
+       pthread_mutexattr_t mattr;
+       pthread_condattr_t cattr;
+       int ret;
+
+       aw = xnmalloc(sizeof(*aw));
+       if (aw == NULL)
+               return -ENOMEM;
+
+       aw->alarm_pulses = 0;
+
+       pthread_mutexattr_init(&mattr);
+       pthread_mutexattr_settype(&mattr, mutex_type_attribute);
+       pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
+       pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE);
+       ret = __bt(-__RT(pthread_mutex_init(&aw->lock, &mattr)));
+       pthread_mutexattr_destroy(&mattr);
+       if (ret)
+               goto fail_lock;
+
+       pthread_condattr_init(&cattr);
+       pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_PRIVATE);
+       pthread_condattr_setclock(&cattr, CLOCK_COPPERPLATE);
+       ret = __bt(-pthread_cond_init(&aw->event, &cattr));
+       pthread_condattr_destroy(&cattr);
+       if (ret)
+               goto fail_cond;
+
+       ret = __CURRENT(rt_alarm_create(alarm, name, trank_alarm_handler, aw));
+       if (ret)
+               goto fail_alarm;
+
+       return 0;
+fail_alarm:
+       __RT(pthread_cond_destroy(&aw->event));
+fail_cond:
+       __RT(pthread_mutex_destroy(&aw->lock));
+fail_lock:
+       xnfree(aw);
+
+       return ret;
+}
+
+static struct alchemy_alarm *find_alarm(RT_ALARM *alarm)
+{
+       struct alchemy_alarm *acb;
+
+       if (bad_pointer(alarm))
+               return NULL;
+
+       acb = (struct alchemy_alarm *)alarm->handle;
+       if (bad_pointer(acb) || acb->magic != alarm_magic)
+               return NULL;
+
+       return acb;
+}
+
+int rt_alarm_wait(RT_ALARM *alarm)
+{
+       struct threadobj *current = threadobj_current();
+       struct sched_param_ex param_ex;
+       struct trank_alarm_wait *aw;
+       struct alchemy_alarm *acb;
+       int ret, prio, pulses;
+
+       acb = find_alarm(alarm);
+       if (acb == NULL)
+               return -EINVAL;
+
+       threadobj_lock(current);
+       prio = threadobj_get_priority(current);
+       if (prio != threadobj_irq_prio) {
+               param_ex.sched_priority = threadobj_irq_prio;
+               threadobj_set_schedparam(current, SCHED_FIFO, &param_ex);
+       }
+       threadobj_unlock(current);
+
+       aw = acb->arg;
+
+       /*
+        * Emulate the original behavior: wait for the next pulse (no
+        * event buffering, broadcast to all waiters), while
+        * preventing spurious wakeups.
+        */
+       __RT(pthread_mutex_lock(&aw->lock));
+
+       pulses = aw->alarm_pulses;
+
+       for (;;) {
+               ret = -__RT(pthread_cond_wait(&aw->event, &aw->lock));
+               if (ret || aw->alarm_pulses != pulses)
+                       break;
+       }
+
+       __RT(pthread_mutex_unlock(&aw->lock));
+
+       return __bt(ret);
+}
+
+int rt_alarm_delete(RT_ALARM *alarm)
+{
+       struct trank_alarm_wait *aw;
+       struct alchemy_alarm *acb;
+       int ret;
+
+       acb = find_alarm(alarm);
+       if (acb == NULL)
+               return -EINVAL;
+
+       aw = acb->arg;
+       ret = __CURRENT(rt_alarm_delete(alarm));
+       if (ret)
+               return ret;
+
+       __RT(pthread_cond_destroy(&aw->event));
+       __RT(pthread_mutex_destroy(&aw->lock));
+       xnfree(aw);
+
+       return 0;
+}
diff --git a/scripts/xeno-config-cobalt.in b/scripts/xeno-config-cobalt.in
index c2b37bd..cafd697 100644
--- a/scripts/xeno-config-cobalt.in
+++ b/scripts/xeno-config-cobalt.in
@@ -157,7 +157,7 @@ while test $# -gt 0; do
                exit 1
            fi
            cflags="$XENO_BASE_CFLAGS"
-           test x$compat = xy && cflags="-I$XENO_INCLUDE_DIR/trank $cflags"
+           test x$compat = xy && cflags="-I$XENO_INCLUDE_DIR/trank 
-D__XENO_COMPAT__ $cflags"
            for skin in $skin_list; do
                case "$skin" in
                    posix|cobalt|rtdm)


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

Reply via email to