SquidTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 21 Time Functions */
10 
11 #ifndef SQUID_TIME_H
12 #define SQUID_TIME_H
13 
14 #include "rfc1123.h"
15 
16 #include <ctime>
17 /* NP: sys/time.h is provided by libcompat */
18 
19 /* Use uint64_t to store milliseconds */
20 typedef uint64_t time_msec_t;
21 
22 /* globals for accessing time */
23 extern struct timeval current_time;
24 extern double current_dtime;
25 extern time_t squid_curtime;
26 
27 time_t getCurrentTime(void);
28 int tvSubMsec(struct timeval, struct timeval);
29 
32 void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
33 
36 void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
37 
40 void tvAssignAdd(struct timeval &t, struct timeval const &add);
41 
43 inline long int tvToMsec(struct timeval &t)
44 {
45  return t.tv_sec * 1000 + t.tv_usec / 1000;
46 }
47 
50 {
51 
52 public:
53  virtual ~TimeEngine();
54 
56  virtual void tick();
57 };
58 
59 // TODO: Remove direct timercmp() calls in legacy code.
60 
61 inline bool
62 operator <(const timeval &a, const timeval &b)
63 {
64  return timercmp(&a, &b, <);
65 }
66 
67 inline bool
68 operator >(const timeval &a, const timeval &b)
69 {
70  return timercmp(&a, &b, >);
71 }
72 
73 inline bool
74 operator !=(const timeval &a, const timeval &b)
75 {
76  return timercmp(&a, &b, !=);
77 }
78 
79 // Operators for timeval below avoid timercmp() because Linux timeradd(3) manual
80 // page says that their timercmp() versions "do not work" on some platforms.
81 
82 inline bool
83 operator <=(const timeval &a, const timeval &b)
84 {
85  return !(a > b);
86 }
87 
88 inline bool
89 operator >=(const timeval &a, const timeval &b)
90 {
91  return !(a < b);
92 }
93 
94 inline bool
95 operator ==(const timeval &a, const timeval &b)
96 {
97  return !(a != b);
98 }
99 
100 namespace Time
101 {
102 
109 const char *FormatStrf(time_t t);
110 
117 const char *FormatHttpd(time_t t);
118 
119 } // namespace Time
120 
121 #endif /* SQUID_TIME_H */
122 
void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2)
Definition: time.cc:52
bool operator<(const timeval &a, const timeval &b)
Definition: SquidTime.h:62
long int tvToMsec(struct timeval &t)
Convert timeval to milliseconds.
Definition: SquidTime.h:43
bool operator<=(const timeval &a, const timeval &b)
Definition: SquidTime.h:83
bool operator>(const timeval &a, const timeval &b)
Definition: SquidTime.h:68
#define timercmp(tvp, uvp, cmp)
Definition: snmp_api_util.h:76
virtual ~TimeEngine()
Definition: time.cc:72
bool operator>=(const timeval &a, const timeval &b)
Definition: SquidTime.h:89
bool operator==(const timeval &a, const timeval &b)
Definition: SquidTime.h:95
const char * FormatStrf(time_t t)
Definition: time.cc:82
int tvSubMsec(struct timeval, struct timeval)
Definition: time.cc:34
time_t getCurrentTime(void)
Get current time.
void tvAssignAdd(struct timeval &t, struct timeval const &add)
Definition: time.cc:62
struct timeval current_time
Definition: stub_time.cc:15
time_t squid_curtime
Definition: stub_time.cc:17
void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2)
Definition: time.cc:41
const char * FormatHttpd(time_t t)
Definition: time.cc:98
virtual void tick()
Definition: time.cc:76
uint64_t time_msec_t
Definition: SquidTime.h:20
double current_dtime
Definition: stub_time.cc:16
bool operator!=(const timeval &a, const timeval &b)
Definition: SquidTime.h:74

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors