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

Last change on this file since 64 was 64, checked in by Marek Kurdej, 11 years ago

Modified property: added svn:keywords=Id.

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