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

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

Added: more documentation.

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