diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2023-05-19 17:21:51 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2023-05-19 17:21:51 -0400 |
commit | 84278d0d2c404a02c6292a6d99f38a88e77a6490 (patch) | |
tree | bd961ca166a22cc7c6a5e65da585ea0f705dda9d /indra/llcommon/lltimer.cpp | |
parent | 22a07b1121bb429e6bfe10b5a5e859bcea1262b6 (diff) | |
parent | a92f08b2bc0ee5a63f678c55f9a9d0ec0c4ff574 (diff) |
SL-18837: Merge branch 'xcode-14.1' of secondlife/viewer into xcode-14.3
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 aaa6df325c..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; - - S32 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); |