hybrid_sleep(sleep_time :: Float64, threshold :: Float64 = 0.0175) = begin
const tics_per_sec = 1000000000.0
const min_actual_sleep = 0.001
const max_sleep = 86400000.0
const min_sleep = 0.000001000
nano1 = time_ns()
nano2 = nano1 + (sleep_time * tics_per_sec)
if sleep_time < min_sleep
@printf("parameter error: sleep_time => %10.8f is less than %10.8f secs!!\n", sleep_time, min_sleep)
println("sleep_ns aborted ==> specified sleep time is too low!")
sleep(2.0)
return -1.0
end
if sleep_time > max_sleep
@printf("parameter error: sleep_time => %12.1f is greater than %10.1f secs!!\n", sleep_time, max_sleep)
println("sleep_ns aborted ==> specified sleep time is too high!")
sleep(2.0)
return -2.0
end
if sleep_time > threshold
actual_sleep_time = max(min_actual_sleep, sleep_time - threshold)
Libc.systemsleep(actual_sleep_time)
end
nano3 :: UInt64 = time_ns()
while true
nano3 >= nano2 && break
nano3 = time_ns()
end
seconds_over = (nano3 - nano2) / tics_per_sec
return seconds_over
end
@time hybrid_sleep(0.000001)