mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
77b6febc19
improved sleep_us_impl() in several ways: 1. dynamic sleep intervals: now sleeps for actual remaining time instead of fixed 1ms polling, reducing unnecessary wakeups and improving efficiency for longer sleeps 2. error handling: added checks for clock_gettime() failures with fallback to usleep(), and input validation to handle negative values 3. overflow prevention: use named constant USEC_PER_MSEC instead of literal 1000 for microsecond-to-nanosecond conversion, and validate input before conversion 4. wraparound handling: fixed tick comparison at line 580 to use signed arithmetic like other tick comparisons in the codebase 5. code clarity: added time conversion constants (NSEC_PER_MSEC, NSEC_PER_SEC, USEC_PER_MSEC) to replace magic numbers all tests pass. Co-authored-by: Claude <noreply@anthropic.com>