aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/lltimer.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/lltimer.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llcommon/lltimer.h')
-rw-r--r--linden/indra/llcommon/lltimer.h161
1 files changed, 161 insertions, 0 deletions
diff --git a/linden/indra/llcommon/lltimer.h b/linden/indra/llcommon/lltimer.h
new file mode 100644
index 0000000..caac16f
--- /dev/null
+++ b/linden/indra/llcommon/lltimer.h
@@ -0,0 +1,161 @@
1/**
2 * @file lltimer.h
3 * @brief Cross-platform objects for doing timing
4 *
5 * Copyright (c) 2000-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_TIMER_H
29#define LL_TIMER_H
30
31#if LL_LINUX || LL_DARWIN
32# include <time.h>
33# include <sys/time.h>
34#endif
35
36#include <list>
37
38// units conversions
39#ifndef USEC_PER_SEC
40 const U32 USEC_PER_SEC = 1000000;
41#endif
42const U32 SEC_PER_MIN = 60;
43const U32 MIN_PER_HOUR = 60;
44const U32 USEC_PER_MIN = USEC_PER_SEC * SEC_PER_MIN;
45const U32 USEC_PER_HOUR = USEC_PER_MIN * MIN_PER_HOUR;
46const U32 SEC_PER_HOUR = SEC_PER_MIN * MIN_PER_HOUR;
47const F64 SEC_PER_USEC = 1.0 / (F64) USEC_PER_SEC;
48
49class LLTimer
50{
51public:
52 static LLTimer *sTimer; // global timer
53
54protected:
55 U64 mLastClockCount;
56 U64 mExpirationTicks;
57 BOOL mStarted;
58
59public:
60 LLTimer();
61 ~LLTimer();
62
63 static void initClass() { if (!sTimer) sTimer = new LLTimer; }
64 static void cleanupClass() { delete sTimer; sTimer = NULL; }
65
66 // Return a high precision number of seconds since the start of
67 // this application instance.
68 static F64 getElapsedSeconds()
69 {
70 return sTimer->getElapsedTimeF64();
71 }
72
73 // Return a high precision usec since epoch
74 static U64 getTotalTime();
75
76 // Return a high precision seconds since epoch
77 static F64 getTotalSeconds();
78
79
80 // MANIPULATORS
81 void start() { reset(); mStarted = TRUE; }
82 void stop() { mStarted = FALSE; }
83 void reset(); // Resets the timer
84 void setLastClockCount(U64 current_count); // Sets the timer so that the next elapsed call will be relative to this time
85 void setTimerExpirySec(F32 expiration);
86 BOOL checkExpirationAndReset(F32 expiration);
87 BOOL hasExpired();
88 F32 getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset
89 F64 getElapsedTimeAndResetF64();
90
91 F32 getRemainingTimeF32();
92
93 static BOOL knownBadTimer();
94
95 // ACCESSORS
96 F32 getElapsedTimeF32() const; // Returns elapsed time in seconds
97 F64 getElapsedTimeF64() const; // Returns elapsed time in seconds
98
99 BOOL getStarted() const { return mStarted; }
100
101
102 static U64 getCurrentClockCount(); // Returns the raw clockticks
103};
104
105//
106// Various functions for initializing/accessing clock and timing stuff. Don't use these without REALLY knowing how they work.
107//
108U64 get_clock_count();
109F64 calc_clock_frequency(U32 msecs);
110void update_clock_frequencies();
111
112
113// Sleep for milliseconds
114void ms_sleep(long ms);
115
116// Yield
117//void llyield(); // Yield your timeslice - not implemented yet for Mac, so commented out.
118
119// Returns the correct UTC time in seconds, like time(NULL).
120// Useful on the viewer, which may have its local clock set wrong.
121U32 time_corrected();
122
123// Correction factor used by time_corrected() above.
124extern S32 gUTCOffset;
125
126// Is the current computer (in its current time zone)
127// observing daylight savings time?
128BOOL is_daylight_savings();
129
130// Converts internal "struct tm" time buffer to Pacific Standard/Daylight Time
131// Usage:
132// S32 utc_time;
133// utc_time = time_corrected();
134// struct tm* internal_time = utc_to_pacific_time(utc_time, gDaylight);
135struct tm* utc_to_pacific_time(S32 utc_time, BOOL pacific_daylight_time);
136
137void microsecondsToTimecodeString(U64 current_time, char *tcstring);
138void secondsToTimecodeString(F32 current_time, char *tcstring);
139
140// class for scheduling a function to be called at a given frequency (approximate, inprecise)
141class LLEventTimer
142{
143public:
144 LLEventTimer(F32 period); // period is the amount of time between each call to tick()
145 virtual ~LLEventTimer();
146
147 //function to be called at the supplied frequency
148 virtual void tick() = 0;
149
150 static void updateClass();
151
152protected:
153 LLTimer mTimer;
154 F32 mPeriod;
155
156private:
157 //list of active timers
158 static std::list<LLEventTimer*> sActiveList;
159};
160
161#endif