Skip to content

Commit

Permalink
ATRONIX: Dynamically change resolution passed to OS_WAIT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Oldes committed May 29, 2018
1 parent c27cbca commit fbd300d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/c-port.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
REBINT result;
REBCNT wt = 1;
REBCNT res = (timeout >= 1000) ? 0 : 16; // OS dependent?
REBCNT old_time = -1;

while (wt) {
if (GET_SIGNAL(SIG_ESCAPE)) {
Expand All @@ -229,6 +230,13 @@
if (time >= timeout) break; // done (was dt = 0 before)
else if (wt > timeout - time) // use smaller residual time
wt = timeout - time;

if (old_time >= 0
&& time - old_time < res) {
res = time - old_time;
}

old_time = time;
}

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

0 comments on commit fbd300d

Please sign in to comment.