diff options
| author | Dave Parks <davep@lindenlab.com> | 2022-10-13 19:51:40 -0500 | 
|---|---|---|
| committer | Dave Parks <davep@lindenlab.com> | 2022-10-13 19:51:40 -0500 | 
| commit | ec5009d70eb0fd729126b2321b9d7d6118741573 (patch) | |
| tree | 2cffe21857f9c74c775b988107147630f837392a | |
| parent | 15c3c3f94d6d1b3007f3135602bf3f65dc791f57 (diff) | |
SL-18190 Potential fix for sapping CPU when "sleeping"
| -rw-r--r-- | indra/llcommon/lltimer.cpp | 28 | ||||
| -rw-r--r-- | indra/llwindow/llwindowwin32.cpp | 9 | 
2 files changed, 37 insertions, 0 deletions
| diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 39dfee3755..8739eeef00 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -65,6 +65,9 @@ LLTimer* LLTimer::sTimer = NULL;  //---------------------------------------------------------------------------  #if LL_WINDOWS + + +#if 0  void ms_sleep(U32 ms)  {      LL_PROFILE_ZONE_SCOPED; @@ -83,6 +86,31 @@ U32 micro_sleep(U64 us, U32 max_yields)  	ms_sleep((U32)(us / 1000));      return 0;  } + +#else + +U32 micro_sleep(U64 us, U32 max_yields) +{ +    LL_PROFILE_ZONE_SCOPED +    LARGE_INTEGER ft; +    ft.QuadPart = -static_cast<S64>(us * 10);  // '-' using relative time + +    HANDLE timer = CreateWaitableTimer(NULL, TRUE, NULL); +    SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); +    WaitForSingleObject(timer, INFINITE); +    CloseHandle(timer); + +    return 0; +} + +void ms_sleep(U32 ms) +{ +    LL_PROFILE_ZONE_SCOPED +    micro_sleep(ms * 1000, 0); +} + +#endif +  #elif LL_LINUX || LL_DARWIN  static void _sleep_loop(struct timespec& thiswait)  { diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index aadf895271..6beb874e8c 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -66,6 +66,7 @@  #include <d3d9.h>  #include <dxgi1_4.h> +#include <timeapi.h>  // Require DirectInput version 8  #define DIRECTINPUT_VERSION 0x0800 @@ -4827,6 +4828,14 @@ void LLWindowWin32::LLWindowWin32Thread::run()      initDX(); +    //as good a place as any to up the MM timer resolution (see ms_sleep) +    //attempt to set timer resolution to 1ms +    TIMECAPS tc; +    if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) == TIMERR_NOERROR) +    { +        timeBeginPeriod(llclamp((U32) 1, tc.wPeriodMin, tc.wPeriodMax)); +    } +      while (! getQueue().done())      {          LL_PROFILE_ZONE_SCOPED_CATEGORY_WIN32; | 
