[62] | 1 | // This file is part of the PACPUS framework distributed under the
|
---|
| 2 | // CECILL-C License, Version 1.0.
|
---|
| 3 | //
|
---|
[66] | 4 | /// @file
|
---|
[63] | 5 | /// @author Gerald Dherbomez <firstname.surname@utc.fr>
|
---|
| 6 | /// @date January, 2006
|
---|
[62] | 7 | /// @version $Id: road_time.h 66 2013-01-09 16:54:11Z kurdejma $
|
---|
| 8 | /// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
|
---|
| 9 | /// @brief Brief description.
|
---|
| 10 | ///
|
---|
| 11 | /// Detailed description.
|
---|
[31] | 12 |
|
---|
[62] | 13 | // FIXME: update this note.
|
---|
| 14 | // NOTE:
|
---|
| 15 | // This DLL was compiled as a Standard C Language Dynamic Link Libtrary.
|
---|
| 16 | // So in order to be compatible with C++ program, we must add the command extern "C"
|
---|
| 17 | // for the whole include file.
|
---|
[3] | 18 |
|
---|
[31] | 19 | #ifndef DEF_PACPUS_ROAD_TIME_H
|
---|
| 20 | #define DEF_PACPUS_ROAD_TIME_H
|
---|
[3] | 21 |
|
---|
| 22 | #ifdef __cplusplus
|
---|
| 23 | extern "C" {
|
---|
| 24 | #endif // __cplusplus
|
---|
| 25 |
|
---|
| 26 | #include <stddef.h> // defines: NULL
|
---|
| 27 |
|
---|
[31] | 28 | #include <Pacpus/kernel/cstdint.h>
|
---|
[3] | 29 |
|
---|
| 30 | // Export macro for ROAD_TIME DLL for Windows only
|
---|
| 31 | #ifdef WIN32
|
---|
| 32 | # ifdef ROAD_TIME_EXPORTS
|
---|
| 33 | # define ROAD_TIME_API __declspec(dllexport)
|
---|
| 34 | # else
|
---|
| 35 | # define ROAD_TIME_API __declspec(dllimport)
|
---|
| 36 | # endif
|
---|
| 37 | #else
|
---|
| 38 | # define ROAD_TIME_API /* nothing */
|
---|
| 39 | #endif
|
---|
| 40 |
|
---|
| 41 | typedef uint64_t road_time_t;
|
---|
| 42 | typedef int32_t road_timerange_t;
|
---|
| 43 |
|
---|
| 44 | typedef int64_t road_time_diff_t;
|
---|
| 45 | typedef int32_t road_timerange_diff_t;
|
---|
| 46 |
|
---|
| 47 | #ifdef WIN32
|
---|
| 48 |
|
---|
| 49 | /// Structure exchanged to give the Initialization parameters. All these fields are filled when the
|
---|
| 50 | /// first process attached to the DLL. It gives the Real Time and the value of the Performance Counter
|
---|
| 51 | /// at the same time.
|
---|
| 52 | /// Description of each field is provided inside the structure
|
---|
| 53 | struct Initialisation_Time
|
---|
| 54 | {
|
---|
| 55 | /// Time (extended to micro seconds precision)
|
---|
| 56 | /// that was given by the Real Time Clock of
|
---|
| 57 | /// windows (using ftime()) at the first time the DLL was called.
|
---|
| 58 | road_time_t Real_Time;
|
---|
| 59 |
|
---|
| 60 | /// Correpsonding number of cycles of the CPU Performance Counter,
|
---|
| 61 | /// if it is available. Normally it is the Multimedia Counter.
|
---|
| 62 | /// If the Performance Counter is not availaible, normally it
|
---|
| 63 | /// should return the Real Time Counter Value (accuracy of 10 ms)..
|
---|
| 64 | uint64_t Multimedia_Counter;
|
---|
| 65 |
|
---|
| 66 | /// Frequency of the Performance Counter, if it is available
|
---|
| 67 | /// This Frequency is given in Hertz.
|
---|
| 68 | uint64_t Multimedia_Counter_Frequency;
|
---|
| 69 |
|
---|
| 70 | /// Delta_t is used to have less work when asking time.
|
---|
| 71 | /// Delta_t is equal to Real_Time - (Multimedia_Counter/Multimedia_Counter_Frequancy)/1000000
|
---|
| 72 | road_time_t delta_t;
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | /// This method just return the actual time using a method based on delta_t (1 less operation).
|
---|
| 76 | /// Return a road_time_t: ellapsed time in microseconds since the 1/01/1970
|
---|
| 77 | road_time_t ROAD_TIME_API road_time(void);
|
---|
| 78 |
|
---|
| 79 | /// This method just return the actual time using all the fields of the Initiaiztion_Time Structure.
|
---|
| 80 | /// Return a road_time_t: ellapsed time in microseconds since the 1/01/1970
|
---|
| 81 | road_time_t ROAD_TIME_API road_time2(void);
|
---|
| 82 |
|
---|
| 83 | /// This method just return the Initialization Parameter
|
---|
| 84 | /// Return an Initialization_Time structure (see below)
|
---|
| 85 | struct Initialisation_Time ROAD_TIME_API road_time_init(void);
|
---|
| 86 |
|
---|
| 87 | #else // WIN32
|
---|
| 88 |
|
---|
| 89 | // UNIX
|
---|
| 90 |
|
---|
| 91 | #include <sys/time.h>
|
---|
| 92 |
|
---|
| 93 | static road_time_t road_time(void)
|
---|
| 94 | {
|
---|
| 95 | struct timeval t;
|
---|
| 96 | gettimeofday(&t, NULL);
|
---|
| 97 | return(road_time_t)((road_time_t)(t.tv_sec)*1000000 + (road_time_t)(t.tv_usec));
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | #endif // WIN32
|
---|
| 101 |
|
---|
| 102 | #ifdef __cplusplus
|
---|
| 103 | }
|
---|
| 104 | #endif // __cplusplus
|
---|
| 105 |
|
---|
[31] | 106 | #endif // DEF_PACPUS_ROAD_TIME_H
|
---|