Skip to content

Commit f9fed0e

Browse files
committed
ATRONIX: Treat unhandled events as no activity in Awake_System
This code could cause high CPU usage: >> p1: open tcp://www.google.com:80 >> p2: open tcp://www.google.com:80 >> wait/only [p1 10] This happens because when Awake_System is called by WAIT in this cause, will always return 0 (because of the unhandled LOOKUP event in the port p1), thus Wait_Ports will set `wt' to 1 ms in very iteration. Returning -1 from Awake_System in this case will cause `wt' in Wait_Ports to be doubled in the next iteration, which gives CPU more time to sleep.
1 parent fbd300d commit f9fed0e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/core/c-port.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
v = Apply_Func(0, awake, port, &tmp, &ref_only, 0); // ds is return value
185185

186186
// Awake function returns 1 for end of WAIT:
187-
return (IS_LOGIC(v) && VAL_LOGIC(v)) ? 1 : 0;
187+
return IS_NONE(v) ? -1 : (IS_LOGIC(v) && VAL_LOGIC(v)) ? 1 : 0;
188188
}
189189

190190

src/mezz/sys-ports.r

+5-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ init-schemes: func [
214214
if find waked first ports [return true]
215215
]
216216

217-
false ; keep waiting
217+
either zero? n-event [
218+
none ;events are ignored
219+
][
220+
false ; keep waiting
221+
]
218222
]
219223
init: func [port] [
220224
;;print ["Init" title]

0 commit comments

Comments
 (0)