aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/lltimer.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:50 -0500
committerJacek Antonelli2008-08-15 23:45:50 -0500
commit2a4dea528f670b9bb1f77ef27a8a1dd16603d114 (patch)
tree95c68e362703c9099d571ecbdc6142b1cda1e005 /linden/indra/llcommon/lltimer.cpp
parentSecond Life viewer sources 1.20.6 (diff)
downloadmeta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.zip
meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.gz
meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.bz2
meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.xz
Second Life viewer sources 1.20.7
Diffstat (limited to 'linden/indra/llcommon/lltimer.cpp')
-rw-r--r--linden/indra/llcommon/lltimer.cpp84
1 files changed, 48 insertions, 36 deletions
diff --git a/linden/indra/llcommon/lltimer.cpp b/linden/indra/llcommon/lltimer.cpp
index a421dce..25d9897 100644
--- a/linden/indra/llcommon/lltimer.cpp
+++ b/linden/indra/llcommon/lltimer.cpp
@@ -39,10 +39,8 @@
39# define WIN32_LEAN_AND_MEAN 39# define WIN32_LEAN_AND_MEAN
40# include <winsock2.h> 40# include <winsock2.h>
41# include <windows.h> 41# include <windows.h>
42#elif LL_LINUX || LL_SOLARIS 42#elif LL_LINUX || LL_SOLARIS || LL_DARWIN
43# include <sys/time.h> 43# include <errno.h>
44# include <sched.h>
45#elif LL_DARWIN
46# include <sys/time.h> 44# include <sys/time.h>
47#else 45#else
48# error "architecture not supported" 46# error "architecture not supported"
@@ -81,42 +79,55 @@ U64 gLastTotalTimeClockCount = 0;
81//--------------------------------------------------------------------------- 79//---------------------------------------------------------------------------
82 80
83#if LL_WINDOWS 81#if LL_WINDOWS
84void ms_sleep(long ms) 82void ms_sleep(U32 ms)
85{ 83{
86 Sleep((U32)ms); 84 Sleep(ms);
87} 85}
88 86#elif LL_LINUX || LL_SOLARIS || LL_DARWIN
89void llyield() 87void ms_sleep(U32 ms)
90{ 88{
91 SleepEx(0, TRUE); // Relinquishes time slice to any thread of equal priority, can be woken up by extended IO functions 89 long mslong = ms; // tv_nsec is a long
92} 90 struct timespec thiswait, nextwait;
93#elif LL_LINUX || LL_SOLARIS 91 bool sleep_more = false;
94void ms_sleep(long ms)
95{
96 struct timespec t;
97 t.tv_sec = ms / 1000;
98 t.tv_nsec = (ms % 1000) * 1000000l;
99 nanosleep(&t, NULL);
100}
101 92
102void llyield() 93 thiswait.tv_sec = ms / 1000;
103{ 94 thiswait.tv_nsec = (mslong % 1000) * 1000000l;
104 sched_yield(); 95 do {
105} 96 int result = nanosleep(&thiswait, &nextwait);
106#elif LL_DARWIN
107void ms_sleep(long ms)
108{
109 struct timespec t;
110 t.tv_sec = ms / 1000;
111 t.tv_nsec = (ms % 1000) * 1000000l;
112 nanosleep(&t, NULL);
113}
114 97
115void llyield() 98 // check if sleep was interrupted by a signal; unslept
116{ 99 // remainder was written back into 't' and we just nanosleep
117// sched_yield(); 100 // again.
101 sleep_more = (result == -1 && EINTR == errno);
102
103 if (sleep_more)
104 {
105 if ( nextwait.tv_sec > thiswait.tv_sec ||
106 (nextwait.tv_sec == thiswait.tv_sec &&
107 nextwait.tv_nsec >= thiswait.tv_nsec) )
108 {
109 // if the remaining time isn't actually going
110 // down then we're being shafted by low clock
111 // resolution - manually massage the sleep time
112 // downward.
113 if (nextwait.tv_nsec > 1000000) {
114 // lose 1ms
115 nextwait.tv_nsec -= 1000000;
116 } else {
117 if (nextwait.tv_sec == 0) {
118 // already so close to finished
119 sleep_more = false;
120 } else {
121 // lose up to 1ms
122 nextwait.tv_nsec = 0;
123 }
124 }
125 }
126 thiswait = nextwait;
127 }
128 } while (sleep_more);
118} 129}
119#else 130#else
120# error "architecture not supported" 131# error "architecture not supported"
121#endif 132#endif
122 133
@@ -323,7 +334,7 @@ void LLTimer::setTimerExpirySec(F32 expiration)
323 + (U64)((F32)(expiration * gClockFrequency)); 334 + (U64)((F32)(expiration * gClockFrequency));
324} 335}
325 336
326F32 LLTimer::getRemainingTimeF32() 337F32 LLTimer::getRemainingTimeF32() const
327{ 338{
328 U64 cur_ticks = get_clock_count(); 339 U64 cur_ticks = get_clock_count();
329 if (cur_ticks > mExpirationTicks) 340 if (cur_ticks > mExpirationTicks)
@@ -348,7 +359,7 @@ BOOL LLTimer::checkExpirationAndReset(F32 expiration)
348} 359}
349 360
350 361
351BOOL LLTimer::hasExpired() 362BOOL LLTimer::hasExpired() const
352{ 363{
353 return (get_clock_count() >= mExpirationTicks) 364 return (get_clock_count() >= mExpirationTicks)
354 ? TRUE : FALSE; 365 ? TRUE : FALSE;
@@ -550,3 +561,4 @@ void LLEventTimer::updateClass()
550 } 561 }
551} 562}
552 563
564