Skip to content

Commit 5e975ad

Browse files
committed
FIX: enable better wait precision for timeouts bellow 16ms
Fixes: zsx#42
1 parent be815c1 commit 5e975ad

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/core/c-port.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,18 @@
232232
if (time >= timeout) break; // done (was dt = 0 before)
233233
else if (wt > timeout - time) // use smaller residual time
234234
wt = timeout - time;
235-
236-
if (old_time >= 0
237-
&& time - old_time < res) {
238-
res = time - old_time;
239-
// printf("=== res: %u old_time: %i time: %u \n", res, old_time, time);
235+
if (timeout > 16) {
236+
// dynamicaly change the resolution to save iterations
237+
// https://github.com/zsx/r3/commit/f397faef4d35ee761b56b80ec85061fbc2497d18
238+
// now used only when timeout is hight enough, so precise wait is still possible
239+
// https://github.com/zsx/r3/issues/42
240+
if (old_time >= 0
241+
&& time - old_time < res) {
242+
res = time - old_time;
243+
// printf("=== res: %u old_time: %i time: %u \n", res, old_time, time);
244+
}
245+
old_time = time;
240246
}
241-
242-
old_time = time;
243247
}
244248

245249
// printf("base: %ull res: %u wt: %u old_time: %i time: %u timeout: %u\n", base, res, wt, old_time, time, timeout);

0 commit comments

Comments
 (0)