blob: 1e37813a0728416179c8bcdf828a8557f3538184 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
/**
* Interface to OS time functions.
*/
class FastOS_TimeInterface
{
protected:
/**
* Destructor. No cleanup needed for base class.
*/
virtual ~FastOS_TimeInterface() { }
public:
/**
* Set the time to 0.
*/
virtual void SetZero() = 0;
/**
* Set the time, specified by number of seconds.
* @param seconds Number of seconds.
*/
FastOS_TimeInterface& operator=(const double seconds)
{
SetSecs(seconds);
return *this;
}
/**
* Return the microsecond difference between the current time
* and the time stored in the instance.
* Note: Only millisecond accuracy is guaranteed.
* @return Time difference in microseconds.
*/
double MicroSecsToNow() const;
/**
* Return the millisecond difference between the current time
* and the time stored in the instance.
* @return Time difference in milliseconds.
*/
double MilliSecsToNow() const;
/**
* Add a specified number of microseconds to the time.
* Note: Only millisecond accuracy is guaranteed.
* @param microsecs Number of microseconds to add.
*/
void AddMicroSecs(double microsecs) { SetMicroSecs(MicroSecs() + microsecs); }
/**
* Add a specified number of milliseconds to the time.
* @param millisecs Number of milliseconds to add.
*/
void AddMilliSecs(double millisecs) { SetMilliSecs(MilliSecs() + millisecs); }
/**
* Subtract a specified number of microseconds from the time.
* Note: Only millisecond accuracy is guaranteed.
* @param microsecs Number of microseconds to subtract.
*/
void SubtractMicroSecs(double microsecs) { SetMicroSecs(MicroSecs() - microsecs); }
/**
* Subtract a specified number of milliseconds from the time.
* @param millisecs Number of milliseconds to subtract.
*/
void SubtractMilliSecs(double millisecs) { SetMilliSecs(MilliSecs() - millisecs); }
/**
* Return the time in microseconds.
* Note: Only millisecond accuracy is guaranteed.
* @return Time in microseconds.
*/
virtual double MicroSecs() const = 0;
/**
* Return the time in milliseconds.
* @return Time in milliseconds.
*/
virtual double MilliSecs() const = 0;
/**
* Return the time in seconds.
* @return Time in seconds.
*/
virtual double Secs() const = 0;
/**
* Set the time, specified in microseconds.
* Note: Only millisecond accuracy is guaranteed.
* @param microsecs Time in microseconds.
*/
virtual void SetMicroSecs(double microsecs) = 0;
/**
* Set the time, specified in milliseconds.
* @param millisecs Time in milliseconds.
*/
virtual void SetMilliSecs(double millisecs) = 0;
/**
* Set the time, specified in seconds.
* @param secs Time in seconds.
*/
virtual void SetSecs(double secs) = 0;
/**
* Set the time value to the current system time.
*/
virtual void SetNow() = 0;
/**
* Get the seconds-part of the time value. If the time value
* is 56.1234, this method will return 56.
* @return Number of seconds.
*/
virtual long int GetSeconds() const = 0;
/**
* Get the microsecond-part of the time value. If the time
* value is 56.123456, this method will return 123456.
* Note: Only millisecond accuracy is guaranteed.
* @return Number of microseconds.
*/
virtual long int GetMicroSeconds() const = 0;
};
#include <vespa/fastos/unix_time.h>
using FastOS_Time = FastOS_UNIX_Time;
|