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