source: pacpusframework/trunk/include/Pacpus/kernel/road_time.h@ 18

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