GlsRSOLoader API
gls_rso_loader_timer.h
Go to the documentation of this file.
1 /*! \file gls_rso_loader_timer.h
2 \brief Cross platform portable timing routines.
3 
4 \par Copyright Information
5 
6  Copyright (c) 2013 The DiSTI Corporation.<br>
7  11301 Corporate Blvd.; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13 This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 */
39 
40 #ifndef INCLUDED_GLS_RSO_LOADER_TIMER_H
41 #define INCLUDED_GLS_RSO_LOADER_TIMER_H
42 
43 #define DISTI_EXPORT
44 
45 #ifdef _WIN32
46 #include <windows.h>
47 #include <windef.h>
48 #include <winnt.h>
49 #include <mmsystem.h>
50 #endif
51 
52 #ifndef INT_64
53 #ifndef _WIN32
54 typedef long long INT_64;
55 #else
56 typedef __int64 INT_64;
57 #endif
58 #endif
59 
60 namespace GlsRSOLoader
61 {
62  /** The Timer class
63  */
64  class Timer
65  {
66  private:
67 
68  /**
69  The epoch time when the timer was started. The time of
70  day that the time was started, or last "Reset". Used to calculate
71  elapsed time.
72  */
73  INT_64 _start_time;
74 
75  void AccurateSleep(unsigned long milli);
76 
77  bool _winTimerResolutionSet;
78 
79 #ifdef _WIN32
80  TIMECAPS _timeCaps;
81 #endif
82 
83  protected:
84 
85 #ifdef _WIN32
86  /** Speed of the hardware timer on windows in cycles per second
87  * This will have a value of zero if High performance timers
88  * are not available. */
89  LARGE_INTEGER performanceFreq;
90 #endif
91 
92  public:
93 
94  /** Timer constructor. */
95  DISTI_EXPORT Timer(void);
96 
97  /**
98  Reset the timer so current time is the time base, reset "epoch time" to
99  the current time
100  */
101  DISTI_EXPORT void Reset(void);
102 
103  /**
104  Get the number of milliseconds elapsed since the "epoch time" began
105  \return Return the elapsed milliseconds since the beginning of the epoch
106  */
107  virtual DISTI_EXPORT unsigned long ElapsedMilliseconds(void);
108 
109  /**
110  Get the number of microseconds elapsed since the "epoch time" began
111  \return Return the elapsed Microseconds since the beginning of the epoch
112  */
113  virtual DISTI_EXPORT unsigned long ElapsedMicroseconds(void);
114 
115  /**
116  Get the number of seconds elapsed since the "epoch time" began
117  \return Return the number of seconds since the beginning of the epoch
118  */
119  virtual DISTI_EXPORT unsigned long ElapsedSeconds(void);
120 
121  /**
122  Get the number of seconds elapsed since the "epoch time" began
123  \return The number of seconds elapsed since the beginning of the epoch
124  */
125  virtual DISTI_EXPORT double ElapsedSecondsDouble(void);
126 
127  /**
128  Get the number of seconds elapsed since 01/01/1970, "wall clock"
129  \return Return the number of seconds
130  */
131  virtual DISTI_EXPORT unsigned long GetCurrentTimeInSeconds(void);
132 
133  /**
134  Get the number of seconds elapsed since 01/01/1970,
135  and the number of microseconds elapsed in the current second
136  \param sec Return the number of seconds elapsed since 01/01/1970
137  \param usec Return the factional second in microseconds
138  */
139  virtual DISTI_EXPORT void GetTimeOfDay(unsigned long *sec,unsigned long *usec);
140 
141  /**
142  Get number of microseconds elapsed since 01/01/1970
143  \param usec Return number of microseconds elapsed
144  */
145  virtual DISTI_EXPORT void GetTimeOfDay(INT_64 *usec);
146 
147  /**
148  Cause the process (or thread) to sleep for the specified number of
149  milliseconds. Clock time continues, this pauses the thread, not
150  the clock.
151  \param milli How long to sleep in milliseconds.
152  */
153  virtual DISTI_EXPORT void WaitMilliseconds(unsigned long milli);
154 
155  /**
156  Cause the process (or thread) to sleep for the specified number of
157  microseconds. Clock time continues, this pauses the thread, not
158  the clock.
159  \param micro How long to sleep im micoseconds
160  */
161  virtual DISTI_EXPORT void WaitMicroseconds(unsigned long micro);
162 
163  /**
164  Get the difference between a time value and when the "epoch time" began
165  \param sec Time in seconds to compare to "epoch time"
166  \param usec Time in microseconds to compare to "epoch time"
167  \return Return the difference between the time parameters, and the "epoch time", in Microseconds
168  */
169  virtual DISTI_EXPORT unsigned long DifferenceInMicroseconds(unsigned long sec,unsigned long usec);
170 
171  /**
172  Get the difference between a time value and when the "epoch time" began
173  \param sec Time in seconds to compare to "epoch time"
174  \param usec Time in microseconds to compare to "epoch time"
175  \return Return the difference between the time parameters, and the "epoch time", in Seconds
176  */
177  virtual DISTI_EXPORT double DifferenceInSeconds(unsigned long sec,unsigned long usec);
178 
179  /**
180  Create a DIS timestamp based on the current time of day
181  \return Return a DIS timestamp
182  */
183  virtual DISTI_EXPORT unsigned long DIS_Timestamp(void);
184 
185  virtual DISTI_EXPORT ~Timer();
186  };
187 } // namespace disti
188 
189 #endif
virtual unsigned long ElapsedMicroseconds(void)
virtual void WaitMilliseconds(unsigned long milli)
virtual unsigned long DifferenceInMicroseconds(unsigned long sec, unsigned long usec)
virtual unsigned long ElapsedSeconds(void)
virtual unsigned long ElapsedMilliseconds(void)
Definition: gls_rso_loader_timer.h:64
virtual void GetTimeOfDay(unsigned long *sec, unsigned long *usec)
Definition: gls_rso_loader.h:48
virtual unsigned long DIS_Timestamp(void)
virtual double DifferenceInSeconds(unsigned long sec, unsigned long usec)
virtual void WaitMicroseconds(unsigned long micro)
virtual unsigned long GetCurrentTimeInSeconds(void)
virtual double ElapsedSecondsDouble(void)