Skip to content

Commit fbd300d

Browse files
committed
ATRONIX: Dynamically change resolution passed to OS_WAIT
res was hard coded to 16 ms, which could waste too many iterations when CPU is fast enough. Suppose WAIT starts with timeout = 30, and Awake_System always returns negatives: 1. first iteration will call OS_WAIT with 30, and actually waits 14 ms (timeout - res). 2. second iteration will call OS_WAIT with 16, and OS_WAIT will not wait at all, because (timeout - res == 0). 3. third iteration will call OS_WAIT with probably 16 (or < 16, depending on how fast the second iteration finished), and a busy loop will start until 16 ms elapses.
1 parent c27cbca commit fbd300d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/core/c-port.c

+8
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
REBINT result;
207207
REBCNT wt = 1;
208208
REBCNT res = (timeout >= 1000) ? 0 : 16; // OS dependent?
209+
REBCNT old_time = -1;
209210

210211
while (wt) {
211212
if (GET_SIGNAL(SIG_ESCAPE)) {
@@ -229,6 +230,13 @@
229230
if (time >= timeout) break; // done (was dt = 0 before)
230231
else if (wt > timeout - time) // use smaller residual time
231232
wt = timeout - time;
233+
234+
if (old_time >= 0
235+
&& time - old_time < res) {
236+
res = time - old_time;
237+
}
238+
239+
old_time = time;
232240
}
233241

234242
//printf("%d %d %d\n", dt, time, timeout);

0 commit comments

Comments
 (0)