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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Nov 26 19:05:54 2011 +0100

copperplate: enforce strict aliasing

---

 configure                         |   56 +------------------------------------
 configure.in                      |   27 +-----------------
 include/copperplate/clockobj.h    |   54 ++++++++++++++++++++++++++---------
 lib/copperplate/clockobj.c        |   31 ++++++++++++--------
 lib/copperplate/threadobj.c       |   18 +++++------
 lib/copperplate/timerobj-cobalt.c |   24 ++--------------
 6 files changed, 71 insertions(+), 139 deletions(-)

diff --git a/configure b/configure
index 98f0209..84424c9 100755
--- a/configure
+++ b/configure
@@ -12705,54 +12705,6 @@ $as_echo "no" >&6; }
 fi
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for specific GCC switches" 
>&5
-$as_echo_n "checking for specific GCC switches... " >&6; }
-if test "${ac_cv_gcc_wnoalias+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext 
$LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-save_CFLAGS="$CFLAGS"
-CFLAGS="-Wno-strict-aliasing -Werror"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-return 0;
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ac_cv_gcc_wnoalias=yes
-else
-  ac_cv_gcc_wnoalias=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-CFLAGS="$save_CFLAGS"
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext 
$LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-fi
-
-if [ $ac_cv_gcc_wnoalias = no ]; then
-  gcc_w_noalias=
-else
-  gcc_w_noalias="-Wno-strict-aliasing"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5
-$as_echo "done" >&6; }
-
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler 
provides atomic builtins" >&5
 $as_echo_n "checking whether the compiler provides atomic builtins... " >&6; }
@@ -12787,7 +12739,7 @@ if test "$ac_cv_atomic_builtins" != "yes"; then
    as_fn_error $? "compiler does not support atomic builtins." "$LINENO" 5
 fi
 
-XENO_USER_CFLAGS="-D_GNU_SOURCE -D_REENTRANT -Wall -pipe -Wstrict-prototypes 
-Wmissing-prototypes -Wno-long-long -Wno-unused-parameter -Werror"
+XENO_USER_CFLAGS="-D_GNU_SOURCE -D_REENTRANT -fstrict-aliasing -Wall -pipe 
-Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wno-unused-parameter 
-Werror"
 XENO_USER_LDFLAGS=
 
 if test x$use_registry = xy; then
@@ -12798,12 +12750,6 @@ fi
 XENO_USER_APP_CFLAGS=$XENO_USER_CFLAGS
 XENO_USER_APP_LDFLAGS=$XENO_USER_LDFLAGS
 
-case $XENO_TARGET_ARCH in
- x86)
-       XENO_USER_CFLAGS="$XENO_USER_CFLAGS -fstrict-aliasing $gcc_w_noalias"
-       ;;
-esac
-
 if test x$debug_mode = xpartial; then
    XENO_USER_CFLAGS="-g -O2 -D__XENO_DEBUG__ $XENO_USER_CFLAGS"
 elif test x$debug_mode = xfull; then
diff --git a/configure.in b/configure.in
index d67c14c..006b9b2 100644
--- a/configure.in
+++ b/configure.in
@@ -491,25 +491,6 @@ AC_CACHE_VAL(ac_cv_sched_setaffinity,
  fi
  CFLAGS="$save_CFLAGS")
 
-AC_MSG_CHECKING([for specific GCC switches])
-AC_CACHE_VAL(ac_cv_gcc_wnoalias,
-AC_LANG_SAVE
-AC_LANG_C
-save_CFLAGS="$CFLAGS"
-CFLAGS="-Wno-strict-aliasing -Werror"
-[AC_TRY_COMPILE([],
-[return 0;],
-[ac_cv_gcc_wnoalias=yes],
-[ac_cv_gcc_wnoalias=no])]
-CFLAGS="$save_CFLAGS"
-AC_LANG_RESTORE)
-if [[ $ac_cv_gcc_wnoalias = no ]]; then
-  gcc_w_noalias=
-else
-  gcc_w_noalias="-Wno-strict-aliasing"
-fi
-AC_MSG_RESULT([done])
-
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
 
@@ -524,7 +505,7 @@ if test "$ac_cv_atomic_builtins" != "yes"; then
 fi
 
 dnl Common CFLAGS and LDFLAGS
-XENO_USER_CFLAGS="-D_GNU_SOURCE -D_REENTRANT -Wall -pipe -Wstrict-prototypes 
-Wmissing-prototypes -Wno-long-long -Wno-unused-parameter -Werror"
+XENO_USER_CFLAGS="-D_GNU_SOURCE -D_REENTRANT -fstrict-aliasing -Wall -pipe 
-Wstrict-prototypes -Wmissing-prototypes -Wno-long-long -Wno-unused-parameter 
-Werror"
 XENO_USER_LDFLAGS=
 
 if test x$use_registry = xy; then
@@ -536,12 +517,6 @@ dnl Exported CFLAGS and LDFLAGS, may be enhanced per-arch 
below
 XENO_USER_APP_CFLAGS=$XENO_USER_CFLAGS
 XENO_USER_APP_LDFLAGS=$XENO_USER_LDFLAGS
 
-case $XENO_TARGET_ARCH in
- x86)
-       XENO_USER_CFLAGS="$XENO_USER_CFLAGS -fstrict-aliasing $gcc_w_noalias"
-       ;;
-esac
-
 if test x$debug_mode = xpartial; then
    XENO_USER_CFLAGS="-g -O2 -D__XENO_DEBUG__ $XENO_USER_CFLAGS"
 elif test x$debug_mode = xfull; then
diff --git a/include/copperplate/clockobj.h b/include/copperplate/clockobj.h
index 39cb79d..f006986 100644
--- a/include/copperplate/clockobj.h
+++ b/include/copperplate/clockobj.h
@@ -54,25 +54,30 @@ struct clockobj {
        const char *name;       /* __ref FIXME */
 };
 
-void timespec_sub(struct timespec *r,
-                 const struct timespec *t1, const struct timespec *t2);
+void timespec_sub(struct timespec *__restrict r,
+                 const struct timespec *__restrict t1,
+                 const struct timespec *__restrict t2);
 
-void timespec_subs(struct timespec *r,
-                  const struct timespec *t1, sticks_t t2);
+void timespec_subs(struct timespec *__restrict r,
+                  const struct timespec *__restrict t1,
+                  sticks_t t2);
 
-void timespec_add(struct timespec *r,
-                 const struct timespec *t1, const struct timespec *t2);
+void timespec_add(struct timespec *__restrict r,
+                 const struct timespec *__restrict t1,
+                 const struct timespec *__restrict t2);
 
-void timespec_adds(struct timespec *r,
-                  const struct timespec *t1, sticks_t t2);
+void timespec_adds(struct timespec *__restrict r,
+                  const struct timespec *__restrict t1,
+                  sticks_t t2);
 
-static inline sticks_t timespec_scalar(const struct timespec *t)
+static inline sticks_t timespec_scalar(const struct timespec *__restrict t)
 {
        return t->tv_sec * 1000000000LL + t->tv_nsec;
 }
 
-static inline int
-timespec_before(const struct timespec *t1, const struct timespec *t2)
+static inline int __attribute__ ((always_inline))
+timespec_before(const struct timespec *__restrict t1,
+               const struct timespec *__restrict t2)
 {
        if (t1->tv_sec < t2->tv_sec)
                return 1;
@@ -84,10 +89,31 @@ timespec_before(const struct timespec *t1, const struct 
timespec *t2)
        return 0;
 }
 
-static inline int
-timespec_after(const struct timespec *t1, const struct timespec *t2)
+static inline int __attribute__ ((always_inline))
+timespec_before_or_same(const struct timespec *__restrict t1,
+                       const struct timespec *__restrict t2)
+{
+       if (t1->tv_sec < t2->tv_sec)
+               return 1;
+
+       if (t1->tv_sec == t2->tv_sec &&
+           t1->tv_nsec <= t2->tv_nsec)
+               return 1;
+
+       return 0;
+}
+
+static inline int __attribute__ ((always_inline))
+timespec_after(const struct timespec *__restrict t1,
+              const struct timespec *__restrict t2)
+{
+       return !timespec_before_or_same(t1, t2);
+}
+
+static inline int __attribute__ ((always_inline))
+timespec_after_or_same(const struct timespec *__restrict t1,
+                      const struct timespec *__restrict t2)
 {
-       /* Checks after or equal. */
        return !timespec_before(t1, t2);
 }
 
diff --git a/lib/copperplate/clockobj.c b/lib/copperplate/clockobj.c
index 48f6eab..03d851a 100644
--- a/lib/copperplate/clockobj.c
+++ b/lib/copperplate/clockobj.c
@@ -29,8 +29,9 @@
 #include "copperplate/debug.h"
 #include "internal.h"
 
-void timespec_sub(struct timespec *r,
-                 const struct timespec *t1, const struct timespec *t2)
+void timespec_sub(struct timespec *__restrict r,
+                 const struct timespec *__restrict t1,
+                 const struct timespec *__restrict t2)
 {
        r->tv_sec = t1->tv_sec - t2->tv_sec;
        r->tv_nsec = t1->tv_nsec - t2->tv_nsec;
@@ -40,8 +41,9 @@ void timespec_sub(struct timespec *r,
        }
 }
 
-void timespec_subs(struct timespec *r,
-                  const struct timespec *t1, sticks_t t2)
+void timespec_subs(struct timespec *__restrict r,
+                  const struct timespec *__restrict t1,
+                  sticks_t t2)
 {
        sticks_t s, rem;
 
@@ -55,8 +57,9 @@ void timespec_subs(struct timespec *r,
        }
 }
 
-void timespec_add(struct timespec *r,
-                 const struct timespec *t1, const struct timespec *t2)
+void timespec_add(struct timespec *__restrict r,
+                 const struct timespec *__restrict t1,
+                 const struct timespec *__restrict t2)
 {
        r->tv_sec = t1->tv_sec + t2->tv_sec;
        r->tv_nsec = t1->tv_nsec + t2->tv_nsec;
@@ -66,8 +69,9 @@ void timespec_add(struct timespec *r,
        }
 }
 
-void timespec_adds(struct timespec *r,
-                  const struct timespec *t1, sticks_t t2)
+void timespec_adds(struct timespec *__restrict r,
+                  const struct timespec *__restrict t1,
+                  sticks_t t2)
 {
        sticks_t s, rem;
 
@@ -116,11 +120,11 @@ void __clockobj_ticks_to_timeout(struct clockobj *clkobj,
                                 clockid_t clk_id,
                                 ticks_t ticks, struct timespec *ts)
 {
-       struct timespec delta;
+       struct timespec now, delta;
 
-       __RT(clock_gettime(clk_id, ts));
+       __RT(clock_gettime(clk_id, &now));
        __clockobj_ticks_to_timespec(clkobj, ticks, &delta);
-       timespec_add(ts, ts, &delta);
+       timespec_add(ts, &now, &delta);
 }
 
 static inline
@@ -228,11 +232,12 @@ void clockobj_ticks_to_caltime(struct clockobj *clkobj,
 void clockobj_caltime_to_timeout(struct clockobj *clkobj, const struct tm *tm,
                                 unsigned long rticks, struct timespec *ts)
 {
+       struct timespec date;
        ticks_t ticks;
 
        clockobj_caltime_to_ticks(clkobj, tm, rticks, &ticks);
-       __clockobj_ticks_to_timespec(clkobj, ticks, ts);
-       timespec_sub(ts, ts, &clkobj->offset);
+       __clockobj_ticks_to_timespec(clkobj, ticks, &date);
+       timespec_sub(ts, &date, &clkobj->offset);
 }
 
 void clockobj_set_date(struct clockobj *clkobj, ticks_t ticks)
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index ce257b4..53e4508 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -727,20 +727,18 @@ void threadobj_stop_rr(void)
 int threadobj_set_periodic(struct threadobj *thobj,
                           struct timespec *idate, struct timespec *period)
 {
-       struct timespec now;
+       struct timespec now, wakeup;
 
        __RT(clock_gettime(CLOCK_COPPERPLATE, &now));
 
        if (idate->tv_sec || idate->tv_nsec) {
                if (timespec_before(idate, &now))
                        return -ETIMEDOUT;
-               thobj->core.wakeup = *idate;
+               wakeup = *idate;
        } else
-               thobj->core.wakeup = now;
-
-       timespec_add(&thobj->core.wakeup,
-                    &thobj->core.wakeup, period);
+               wakeup = now;
 
+       timespec_add(&thobj->core.wakeup, &wakeup, period);
        thobj->core.period = timespec_scalar(period);
 
        return 0;
@@ -770,10 +768,10 @@ int threadobj_wait_period(struct threadobj *thobj,
        d = timespec_scalar(&delta);
        if (d >= period) {
                overruns = d / period;
-               timespec_adds(&wakeup, &wakeup, overruns * period);
-       }
-
-       timespec_adds(&thobj->core.wakeup, &wakeup, period);
+               timespec_adds(&thobj->core.wakeup, &wakeup,
+                             overruns * (period + 1));
+       } else
+               timespec_adds(&thobj->core.wakeup, &wakeup, period);
 
        if (overruns)
                ret = -ETIMEDOUT;
diff --git a/lib/copperplate/timerobj-cobalt.c 
b/lib/copperplate/timerobj-cobalt.c
index 248d8f5..44401a5 100644
--- a/lib/copperplate/timerobj-cobalt.c
+++ b/lib/copperplate/timerobj-cobalt.c
@@ -41,24 +41,6 @@ static pthread_t svthread;
 
 static DEFINE_PRIVATE_LIST(svtimers);
 
-void timespec_add(struct timespec *r,
-                 const struct timespec *t1, const struct timespec *t2);
-
-static inline int __attribute__ ((always_inline))
-timeobj_compare(const struct timespec *t1, const struct timespec *t2)
-{
-       if (t1->tv_sec < t2->tv_sec)
-               return -1;
-       if (t1->tv_sec > t2->tv_sec)
-               return 1;
-       if (t1->tv_nsec < t2->tv_nsec)
-               return -1;
-       if (t1->tv_nsec > t2->tv_nsec)
-               return 1;
-
-       return 0;
-}
-
 /*
  * XXX: at some point, we may consider using a timer wheel instead of
  * a simple linked list to index timers. The latter method is
@@ -77,8 +59,8 @@ static void timerobj_enqueue(struct timerobj *tmobj)
        }
 
        pvlist_for_each_entry_reverse(__tmobj, &svtimers, core.link) {
-               if (timeobj_compare(&__tmobj->core.spec.it_value,
-                                   &tmobj->core.spec.it_value) <= 0)
+               if (timespec_before_or_same(&__tmobj->core.spec.it_value,
+                                           &tmobj->core.spec.it_value))
                        break;
        }
 
@@ -110,7 +92,7 @@ static void *timerobj_server(void *arg)
 
                pvlist_for_each_entry_safe(tmobj, tmp, &svtimers, core.link) {
                        value = tmobj->core.spec.it_value;
-                       if (timeobj_compare(&value, &now) > 0)
+                       if (timespec_after(&value, &now))
                                break;
                        pvlist_remove_init(&tmobj->core.link);
                        interval = tmobj->core.spec.it_interval;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to