44 lines
1.8 KiB
Plaintext
44 lines
1.8 KiB
Plaintext
;;;; The job ring between the listener thread and the game thread, and what it
|
|
;;;; does when it is full.
|
|
;;;;
|
|
;;;; The window this needs is "the listener has queued modules the game thread
|
|
;;;; has not looked at yet", and that window has to be held open by something
|
|
;;;; other than a timer — how long sixty-five connections take on a loaded
|
|
;;;; machine is exactly the kind of race a test must not be. So the program
|
|
;;;; blocks on stdin: the test fills the ring, checks what the agent said, and
|
|
;;;; only then writes the byte that lets the program poll.
|
|
(import agent "vendor:agent")
|
|
|
|
;;; libc's, declared straight: no aggregate crosses the boundary, so there is
|
|
;;; nothing for a shim to do.
|
|
(declare stdin-byte [] i32 "getchar")
|
|
|
|
(defonce ticks i64)
|
|
|
|
(defn tick [] i64
|
|
(set ticks (+ ticks 1))
|
|
ticks)
|
|
|
|
(defn main [args [str]] i32
|
|
(if (< (length args) 2)
|
|
(do (println "usage: agent-queue <socket>") 2)
|
|
(do
|
|
(if (< (agent/start (at args 1)) 0)
|
|
(do (println "cannot listen") 1)
|
|
(do
|
|
(println "ready")
|
|
(stdin-byte)
|
|
;; How many the ring actually held. Every module queued is installed
|
|
;; here, so this number is the count of slots that survived — which
|
|
;; is the whole claim: a ring that overwrote the slot it was reading
|
|
;; would answer with something else.
|
|
(print (agent/poll)) (println "")
|
|
;; Round two: one evaluated expression, whose rendering is longer
|
|
;; than the 4K the dev runtime will hold. The program has to still be
|
|
;; here afterwards for the value to be read back off the socket, so
|
|
;; it waits a third time and leaves on end of file.
|
|
(stdin-byte)
|
|
(print (agent/poll)) (println "")
|
|
(stdin-byte)
|
|
0)))))
|