reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Time.hxx
Go to the documentation of this file.
1#if !defined(RESIP_TIME_HXX)
2#define RESIP_TIME_HXX
3
4#include "rutil/Mutex.hxx"
5#include <limits.h>
6#include "rutil/ResipAssert.h"
7
8namespace resip
9{
10
11void sleepMs(unsigned int ms);
12void sleepSeconds(unsigned int seconds);
13
54{
55 public:
56 ResipClock(void);
57 ~ResipClock(void);
58
62 {
63 return getSystemTime();
64 }
65
66
70 {
71 return getSystemTime()/1000LL;
72 }
73
77 {
78 return getSystemTime()/1000000LL;
79 }
80
84 static uint64_t getRandomFutureTimeMs( uint64_t futureMs );
87 static uint64_t getForever();
88
92 static unsigned getMaxSystemTimeWaitMs(void)
93 {
94 return mMaxSystemTimeWaitMs;
95 }
96
102 static void queryTimerInfo(unsigned &minRes, unsigned &maxRes, unsigned &actualRes, bool &isMonotonic);
103
104 private:
108 static uint64_t getSystemTime();
109
110 static unsigned mMaxSystemTimeWaitMs;
111
112#ifdef WIN32
113 private:
118 class WinMonoClock
119 {
120 public:
121 WinMonoClock();
122
126 static uint64_t GetClock64(void)
127 {
128 return mGTC64();
129 }
130
131 private:
132
133 static void Initialize(void);
136 typedef uint64_t (*PGTC64)(void);
137
142 class GTCInterlocked
143 {
144 public:
145
146 static uint64_t GTC64(void);
147
151 static uint32_t GetMaxWaitMs(void)
152 {
153 //Since the base time isn't updated on every call, need to ensure that it's updated once every 49.7 days.
154 //The base time will lag behind the current tick count, which means the lag time must be used
155 //to determine the max wait.
156 //Also need to add a cushion to this calculaton because ::timeGetTime may not be accurate to 1ms.
158 if (maxWait <= 0)
159 {
160 resip_assert(0);
161 const_cast<uint32_t &>(mBaseTimeUpdateInterval) = 60000;
162 const_cast<uint32_t &>(mBaseTimeCushion) = 120000;
164 }
165 return static_cast<uint32_t>(maxWait);
166 }
167
168 private:
178 };
179
186 {
187 public:
188
189 static uint64_t GTC64(void);
190
191 static uint32_t GetMaxWaitMs(void)
192 {
193 return 120000;
194 }
195
196 private:
201 static uint32_t mWrapCounter;
202
205 static DWORD mPrevTick;
206
210
211 };
212
216 class GTCLock
217 {
218 public:
219 static uint64_t GTC64(void);
220
221 private:
223
226 static Mutex mMutex;
227 };
228
229 static PGTC64 mGTC64;
230 };
231#endif
232};
233
234
235}//namespace resip
236
237#endif
238/* ====================================================================
239 * The Vovida Software License, Version 1.0
240 *
241 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
242 *
243 * Redistribution and use in source and binary forms, with or without
244 * modification, are permitted provided that the following conditions
245 * are met:
246 *
247 * 1. Redistributions of source code must retain the above copyright
248 * notice, this list of conditions and the following disclaimer.
249 *
250 * 2. Redistributions in binary form must reproduce the above copyright
251 * notice, this list of conditions and the following disclaimer in
252 * the documentation and/or other materials provided with the
253 * distribution.
254 *
255 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
256 * and "Vovida Open Communication Application Library (VOCAL)" must
257 * not be used to endorse or promote products derived from this
258 * software without prior written permission. For written
259 * permission, please contact vocal@vovida.org.
260 *
261 * 4. Products derived from this software may not be called "VOCAL", nor
262 * may "VOCAL" appear in their name, without prior written
263 * permission of Vovida Networks, Inc.
264 *
265 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
266 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
267 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
268 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
269 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
270 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
271 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
272 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
273 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
274 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
276 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
277 * DAMAGE.
278 *
279 * ====================================================================
280 *
281 * This software consists of voluntary contributions made by Vovida
282 * Networks, Inc. and many individuals on behalf of Vovida Networks,
283 * Inc. For more information on Vovida Networks, Inc., please see
284 * <http://www.vovida.org/>.
285 *
286 * vi: set shiftwidth=3 expandtab:
287 */
#define resip_assert(x)
This file needs to work for both C and C++ code.
#define sleepMs(t)
Definition Server.hxx:16
Clock used for timing in the Timer class and possibly other areas.
Definition Time.hxx:54
static unsigned getMaxSystemTimeWaitMs(void)
Some monotonic clock implementations may internally only return 32-bit values that will wrap.
Definition Time.hxx:92
ResipClock(void)
Definition Time.cxx:37
static uint64_t getTimeMs()
Returns the current clock time in milliseconds.
Definition Time.hxx:69
static uint64_t getTimeSecs()
Returns the current clock time in seconds.
Definition Time.hxx:76
static uint64_t getForever()
Infinit time in future.
Definition Time.cxx:245
static uint64_t getRandomFutureTimeMs(uint64_t futureMs)
Returns an absolute time in ms that is between 50% and 90% of passed in ms from now.
Definition Time.cxx:256
static uint64_t getTimeMicroSec()
Returns the current clock time in microseconds.
Definition Time.hxx:61
~ResipClock(void)
Definition Time.cxx:41
static void queryTimerInfo(unsigned &minRes, unsigned &maxRes, unsigned &actualRes, bool &isMonotonic)
Gets the current clock's minimum, maximum and current/actual timer resolution and returns if the cloc...
Definition Time.cxx:275
dcm! – add UnusedChecking(_enum) below;
std::mutex Mutex
A semaphore that can be locked by only one thread at a time.
Definition Mutex.hxx:37
void sleepSeconds(unsigned int seconds)
Definition Time.cxx:28
unsigned long long uint64_t
Definition Stun.hxx:39
unsigned int uint32_t
Definition stdint.h:85
unsigned __int64 uint64_t
Definition stdint.h:95
void list()
Definition userAdmin.cxx:66