source: pacpusframework/branches/0.0.x/include/Pacpus/kernel/road_time.h

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

Added: PacpusException - base class for all exceptions. DbiteExceptions inherits from it.
Added: PacpusLibConfig.h - dllimport/dllexport clauses separated from pacpus.h.
Update: comments.

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1// %pacpus:license{
2// This file is part of the PACPUS framework distributed under the
3// CECILL-C License, Version 1.0.
4// %pacpus:license}
5/// @file
6/// @version $Id: road_time.h 116 2013-06-25 11:44:25Z kurdejma $
7/// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
8/// @brief Brief description.
9///
10/// Detailed description.
11
12
13#ifndef DEF_PACPUS_ROAD_TIME_H
14#define DEF_PACPUS_ROAD_TIME_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif // __cplusplus
19
20#include <stddef.h> // defines: NULL
21
22#include <Pacpus/kernel/cstdint.h>
23
24/// Export macro for ROAD_TIME DLL for Windows only
25#ifdef WIN32
26# ifdef ROAD_TIME_EXPORTS
27# define ROAD_TIME_API __declspec(dllexport)
28# else
29# define ROAD_TIME_API __declspec(dllimport)
30# endif
31#else
32# define ROAD_TIME_API /* nothing */
33#endif
34
35/// Timestamp type
36typedef uint64_t road_time_t;
37/// Timerange type
38typedef int32_t road_timerange_t;
39
40/// Timestamp difference type
41typedef int64_t road_time_diff_t;
42/// Timerange difference type
43typedef 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
51struct ROAD_TIME_API 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
75road_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
79road_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)
83struct Initialisation_Time ROAD_TIME_API road_time_init(void);
84
85#else // WIN32
86
87// UNIX
88
89#include <sys/time.h>
90
91static 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
Note: See TracBrowser for help on using the repository browser.