certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi libCERTI/ClockFactory.cc libCERTI/CMakeLi...


From: certi-cvs
Subject: [certi-cvs] certi libCERTI/ClockFactory.cc libCERTI/CMakeLi...
Date: Fri, 16 Oct 2009 21:34:35 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      09/10/16 21:34:25

Modified files:
        libCERTI       : ClockFactory.cc CMakeLists.txt 
        .              : config.h.cmake CMakeLists.txt 
        test/utility   : CertiUtilTests.cc 
Added files:
        libCERTI       : GettimeofdayClock.hh GettimeofdayClock.cc 

Log message:
        Merge in 
        patch #6946: Add an other clock, and reorder preference
        The default "best" clock on unix is now PosixClock and if
        unavailable GettimeofdayClock. 
        TSCClock won't be used unless forced with appropriate CMake option.
        Use TSCClock  ONLY IF you know what you are doing.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/ClockFactory.cc?cvsroot=certi&r1=4.1&r2=4.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CMakeLists.txt?cvsroot=certi&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/GettimeofdayClock.hh?cvsroot=certi&rev=4.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/GettimeofdayClock.cc?cvsroot=certi&rev=4.1
http://cvs.savannah.gnu.org/viewcvs/certi/config.h.cmake?cvsroot=certi&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/certi/CMakeLists.txt?cvsroot=certi&r1=1.71&r2=1.72
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/CertiUtilTests.cc?cvsroot=certi&r1=1.15&r2=1.16

Patches:
Index: libCERTI/ClockFactory.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/ClockFactory.cc,v
retrieving revision 4.1
retrieving revision 4.2
diff -u -b -r4.1 -r4.2
--- libCERTI/ClockFactory.cc    25 Nov 2008 15:13:58 -0000      4.1
+++ libCERTI/ClockFactory.cc    16 Oct 2009 21:34:24 -0000      4.2
@@ -26,6 +26,9 @@
 #ifdef HAVE_POSIX_CLOCK
 #include "PosixClock.hh"
 #endif
+#ifdef HAVE_GETTIMEOFDAY
+#include "GettimeofdayClock.hh"
+#endif
 
 #ifdef HAVE_WIN_CLOCK
 #include "WinClock.hh"
@@ -48,10 +51,15 @@
 
 #ifdef HAVE_POSIX_CLOCK
     return new PosixClock () ;
+
+#else
+#ifdef HAVE_GETTIMEOFDAY
+    return new GettimeofdayClock () ;
 #else
     return NULL ;
 #endif
 #endif
 #endif
+#endif
   } /* end of getBestClock */
 }

Index: libCERTI/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libCERTI/CMakeLists.txt,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- libCERTI/CMakeLists.txt     14 Sep 2009 20:51:52 -0000      1.26
+++ libCERTI/CMakeLists.txt     16 Oct 2009 21:34:24 -0000      1.27
@@ -91,6 +91,12 @@
            PosixClock.cc PosixClock.hh)              
 ENDIF(HAVE_POSIX_CLOCK)
 
+IF (HAVE_GETTIMEOFDAY)
+    SET(CERTI_SUPPORT_SRCS 
+           ${CERTI_SUPPORT_SRCS}
+           GettimeofdayClock.cc GettimeofdayClock.hh)              
+ENDIF(HAVE_GETTIMEOFDAY)
+
 IF (HAVE_TSC_CLOCK)
     SET(CERTI_SUPPORT_SRCS 
            ${CERTI_SUPPORT_SRCS}

Index: config.h.cmake
===================================================================
RCS file: /sources/certi/certi/config.h.cmake,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- config.h.cmake      9 Oct 2009 21:13:56 -0000       1.4
+++ config.h.cmake      16 Oct 2009 21:34:24 -0000      1.5
@@ -109,6 +109,9 @@
 /* Define to 1 if you have clock_xxxx API */
 #cmakedefine HAVE_POSIX_CLOCK 1
 
+/* Define to 1 if you have gettimeofday API */
+#cmakedefine HAVE_GETTIMEOFDAY 1
+
 /* Define to 1 if the processor have TSC support */
 #cmakedefine HAVE_TSC_CLOCK 1
 

Index: CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/CMakeLists.txt,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -b -r1.71 -r1.72
--- CMakeLists.txt      9 Oct 2009 21:13:56 -0000       1.71
+++ CMakeLists.txt      16 Oct 2009 21:34:24 -0000      1.72
@@ -56,6 +56,10 @@
 OPTION(FORCE_NO_X11 
               "Force not to use X11 (i.e. no Billard GUI)" OFF)   
         
+# On demand of Eric Noulard, the unsafe tsc clocksource
+OPTION(ENABLE_TSC_CLOCK
+             "Enable the usage of the timestamp counter as clock source (use 
with care)" OFF)
+
 # The communication channel to RTIA
 OPTION(RTIA_USE_TCP 
            "Force TCP socket usage between RTIA and FederateAmbassador 
(default is Unix Socket)" OFF)
@@ -183,12 +187,18 @@
     SET(HAVE_POSIX_CLOCK 1)
 ENDIF (HAVE_CLOCK_GETTIME AND HAVE_CLOCK_SETTIME AND HAVE_CLOCK_GETRES)
 
+################ Check for gettimeofday Support ###########
+CHECK_INCLUDE_FILE(sys/time.h HAVE_SYS_TIME_H)
+CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
+
 ################ Check for TSCClock Support ###########
-SET(TSC_ENABLED_PROCESSOR_REGEX ".*x86_64.*|.*i686.*")
-MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
-IF (CMAKE_SYSTEM_PROCESSOR MATCHES "${TSC_ENABLED_PROCESSOR_REGEX}")
+IF (ENABLE_TSC_CLOCK)
+    SET(TSC_ENABLED_PROCESSOR_REGEX ".*x86_64.*|.*i686.*")
+    MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
+    IF (CMAKE_SYSTEM_PROCESSOR MATCHES "${TSC_ENABLED_PROCESSOR_REGEX}")
     SET(HAVE_TSC_CLOCK 1)
-ENDIF (CMAKE_SYSTEM_PROCESSOR MATCHES "${TSC_ENABLED_PROCESSOR_REGEX}")
+    ENDIF (CMAKE_SYSTEM_PROCESSOR MATCHES "${TSC_ENABLED_PROCESSOR_REGEX}")
+ENDIF (ENABLE_TSC_CLOCK)
 
 ENDIF (NOT WIN32)
 

Index: test/utility/CertiUtilTests.cc
===================================================================
RCS file: /sources/certi/certi/test/utility/CertiUtilTests.cc,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- test/utility/CertiUtilTests.cc      25 Nov 2008 15:13:58 -0000      1.15
+++ test/utility/CertiUtilTests.cc      16 Oct 2009 21:34:24 -0000      1.16
@@ -50,6 +50,9 @@
 #ifdef HAVE_POSIX_CLOCK
 #include "PosixClock.hh"
 #endif
+#ifdef HAVE_GETTIMEOFDAY
+#include "GettimeofdayClock.hh"
+#endif
 
 #ifdef HAVE_WIN_CLOCK
 #include "WinClock.hh"
@@ -246,6 +249,9 @@
 #ifdef HAVE_POSIX_CLOCK
        certi::PosixClock posixClk;
 #endif
+#ifdef HAVE_GETTIMEOFDAY
+        certi::GettimeofdayClock gettimeofdayClock;
+#endif
 #ifdef HAVE_TSC_CLOCK
        certi::TSCClock   tscClk;
 #endif
@@ -274,6 +280,9 @@
 #ifdef HAVE_POSIX_CLOCK
        clockTests(posixClk);
 #endif
+#ifdef HAVE_GETTIMEOFDAY
+       clockTests(gettimeofdayClock);
+#endif
 #ifdef HAVE_WIN_CLOCK
        clockTests(WinClk);
        clockTests(WinPerfClk);

Index: libCERTI/GettimeofdayClock.hh
===================================================================
RCS file: libCERTI/GettimeofdayClock.hh
diff -N libCERTI/GettimeofdayClock.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libCERTI/GettimeofdayClock.hh       16 Oct 2009 21:34:24 -0000      4.1
@@ -0,0 +1,65 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005  ONERA
+// Copyright (C) 2009 Mathias Froehlich
+//
+// This file is part of CERTI-libCERTI
+//
+// CERTI-libCERTI 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.
+//
+// CERTI-libCERTI 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 program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// $Id: GettimeofdayClock.hh,v 4.1 2009/10/16 21:34:24 erk Exp $
+// ----------------------------------------------------------------------------
+
+#ifndef CERTI_GETTIMEOFDAYCLOCK_HH_
+#define CERTI_GETTIMEOFDAYCLOCK_HH_
+
+#include "Clock.hh"
+#include <time.h>
+
+namespace certi {
+
+/**
+ * A Clock implemented using gettimeofday.
+ */
+class CERTI_EXPORT GettimeofdayClock : public Clock
+{
+public:
+    /**
+     * Build a UNIX clock.
+     */
+    GettimeofdayClock();
+    /**
+     * Get the clock resolution in nano-seconds.
+     * @return the clock resolution in nano-seconds
+     */
+    virtual double getResolution();
+    /**
+     * Get the current ticks value.
+     * @return the current ticks value
+     */
+    virtual uint64_t getCurrentTicksValue();
+    /**
+     * Convert a number of ticks into a double value
+     * representing nanoseconds.
+     * @param[in] ticks the number of tick to convert
+     * @return the nano-seconds value
+     */
+    virtual double tick2NanoSecond(const uint64_t ticks);
+    virtual ~GettimeofdayClock();
+};
+
+}
+#endif /*POSIXCLOCK_HH_*/

Index: libCERTI/GettimeofdayClock.cc
===================================================================
RCS file: libCERTI/GettimeofdayClock.cc
diff -N libCERTI/GettimeofdayClock.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libCERTI/GettimeofdayClock.cc       16 Oct 2009 21:34:24 -0000      4.1
@@ -0,0 +1,60 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005  ONERA
+// Copyright (C) 2009 Mathias Froehlich
+//
+// This file is part of CERTI-libCERTI
+//
+// CERTI-libCERTI 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.
+//
+// CERTI-libCERTI 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 program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// $Id: GettimeofdayClock.cc,v 4.1 2009/10/16 21:34:24 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "GettimeofdayClock.hh"
+
+#include <sys/time.h>
+
+#include "Exception.hh"
+
+namespace certi {
+
+GettimeofdayClock::GettimeofdayClock() : Clock("GettimeofdayClock")
+{
+}   
+
+double 
+GettimeofdayClock::getResolution() {
+    return 1000;
+}
+
+uint64_t GettimeofdayClock::getCurrentTicksValue() {
+    struct timeval tv;
+    if (-1 == gettimeofday(&tv, 0))
+        throw RTIinternalError("Cannot get current timestamp!");
+    /* convert struct timespec to number of micro-seconds */ 
+    return tv.tv_sec*1000000 + tv.tv_usec;
+}
+
+double   
+GettimeofdayClock::tick2NanoSecond(const uint64_t ticks) {
+    return 1e3*ticks;
+}
+
+GettimeofdayClock::~GettimeofdayClock()
+{
+}
+
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]