mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Update time.odin
Add caveats.
This commit is contained in:
+6
-1
@@ -214,12 +214,17 @@ time_add :: proc(t: Time, d: Duration) -> Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Accurate sleep borrowed from: https://blat-blatnik.github.io/computerBear/making-accurate-sleep-function/
|
// Accurate sleep borrowed from: https://blat-blatnik.github.io/computerBear/making-accurate-sleep-function/
|
||||||
|
//
|
||||||
|
// Accuracy seems to be pretty good out of the box on Linux, to within around 4µs worst case.
|
||||||
|
// On Windows it depends but is comparable with regular sleep in the worst case.
|
||||||
|
// To get the same kind of accuracy as on Linux, have your program call `win32.time_begin_period(1)` to
|
||||||
|
// tell Windows to use a more accurate timer for your process.
|
||||||
accurate_sleep :: proc(d: Duration) {
|
accurate_sleep :: proc(d: Duration) {
|
||||||
to_sleep, estimate, mean, m2, count: Duration
|
to_sleep, estimate, mean, m2, count: Duration
|
||||||
|
|
||||||
to_sleep = d
|
to_sleep = d
|
||||||
estimate = 5 * Millisecond
|
estimate = 5 * Millisecond
|
||||||
mean = 5 * Millisecond
|
mean = 5 * Millisecond
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
for to_sleep > estimate {
|
for to_sleep > estimate {
|
||||||
|
|||||||
Reference in New Issue
Block a user