diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2023-01-16 20:07:02 +0200 |
---|---|---|
committer | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2023-01-16 20:07:02 +0200 |
commit | 484e3b62131c487b8faaa445cabccb7c82931ffe (patch) | |
tree | 3b029f1d4e52001b11ff9e7fdce2703f47954e4e /indra/llcommon/lltimer.cpp | |
parent | 77a42cb8d61ce31a43f475cab48081b270de130f (diff) | |
parent | f3cd329b585ef55a66f2a824f010d1a54d67d8d2 (diff) |
Merge branch 'xcode-14.1' into DRTVWR-577-maint-S
D577 should have picked part of the changes from contribute branch, picking up the rest for the sake of branch specific crash fixes
Diffstat (limited to 'indra/llcommon/lltimer.cpp')
-rw-r--r-- | indra/llcommon/lltimer.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 74ec62d347..58bedacf43 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -121,9 +121,14 @@ U32 micro_sleep(U64 us, U32 max_yields) U64 start = get_clock_count(); // This is kernel dependent. Currently, our kernel generates software clock // interrupts at 250 Hz (every 4,000 microseconds). - const U64 KERNEL_SLEEP_INTERVAL_US = 4000; - - auto num_sleep_intervals = (us - (KERNEL_SLEEP_INTERVAL_US >> 1)) / KERNEL_SLEEP_INTERVAL_US; + const S64 KERNEL_SLEEP_INTERVAL_US = 4000; + + // Use signed arithmetic to discover whether a sleep is even necessary. If + // either 'us' or KERNEL_SLEEP_INTERVAL_US is unsigned, the compiler + // promotes the difference to unsigned. If 'us' is less than half + // KERNEL_SLEEP_INTERVAL_US, the unsigned difference will be hugely + // positive, resulting in a crazy long wait. + auto num_sleep_intervals = (S64(us) - (KERNEL_SLEEP_INTERVAL_US >> 1)) / KERNEL_SLEEP_INTERVAL_US; if (num_sleep_intervals > 0) { U64 sleep_time = (num_sleep_intervals * KERNEL_SLEEP_INTERVAL_US) - (KERNEL_SLEEP_INTERVAL_US >> 1); |