1
0
mirror of https://github.com/janet-lang/janet synced 2025-07-05 19:42:55 +00:00

Reorder post event / interrupt sequence in deadline.

The interrupt message should come _after_ the post event is made.
This commit is contained in:
Calvin Rose 2025-06-18 22:13:14 -05:00
parent f181948aa9
commit f4ecb5a90f
2 changed files with 14 additions and 4 deletions

View File

@ -693,9 +693,9 @@ static DWORD WINAPI janet_timeout_body(LPVOID ptr) {
JanetThreadedTimeout tto = *(JanetThreadedTimeout *)ptr;
janet_free(ptr);
SleepEx((DWORD)(tto.sec * 1000), TRUE);
janet_interpreter_interrupt(tto.vm);
JanetEVGenericMessage msg = {0};
janet_ev_post_event(tto.vm, janet_timeout_cb, msg);
janet_interpreter_interrupt(tto.vm);
return 0;
}
#else
@ -716,9 +716,9 @@ static void *janet_timeout_body(void *ptr) {
? (long)((tto.sec - ((uint32_t)tto.sec)) * 1000000000)
: 0;
nanosleep(&ts, &ts);
janet_interpreter_interrupt(tto.vm);
JanetEVGenericMessage msg = {0};
janet_ev_post_event(tto.vm, janet_timeout_cb, msg);
janet_interpreter_interrupt(tto.vm);
return NULL;
}
#endif

View File

@ -106,6 +106,8 @@
(calc-2 "(+ 9 10 11 12)"))
@[10 26 42]) "parallel subprocesses 2")
# (print "file piping")
# File piping
# a1cc5ca04
(assert-no-error "file writing 1"
@ -225,6 +227,8 @@
(++ iterations)
(ev/write stream " ")))
# (print "local name / peer name testing")
# Test localname and peername
# 077bf5eba
(repeat 10
@ -407,6 +411,8 @@
(while (def msg (ev/read connection 100))
(broadcast name (string msg)))))))
# (print "chat app testing")
# Now launch the chat server
(def chat-server (net/listen test-host test-port))
(ev/spawn
@ -500,6 +506,8 @@
(let [s (net/listen :unix uds-path :stream)]
(:close s))))))
# (print "accept loop testing")
# net/accept-loop level triggering
(gccollect)
(def maxconn 50)
@ -522,6 +530,8 @@
(assert (= maxconn connect-count))
(:close s)
# (print "running deadline tests...")
# Cancel os/proc-wait with ev/deadline
(let [p (os/spawn [;run janet "-e" "(os/sleep 4)"] :p)]
(var terminated-normally false)
@ -565,13 +575,13 @@
(,resume ,f))))
(for i 0 10
# (print "iteration " i)
# (print "deadline 1 iteration " i)
(assert (= :done (with-deadline2 10
(ev/sleep 0.01)
:done)) "deadline with interrupt exits normally"))
(for i 0 10
# (print "iteration " i)
# (print "deadline 2 iteration " i)
(let [f (coro (forever :foo))]
(ev/deadline 0.01 nil f true)
(assert-error "deadline expired" (resume f))))