mirror of
https://github.com/janet-lang/janet
synced 2025-07-06 03:52:54 +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:
parent
f181948aa9
commit
f4ecb5a90f
@ -693,9 +693,9 @@ static DWORD WINAPI janet_timeout_body(LPVOID ptr) {
|
|||||||
JanetThreadedTimeout tto = *(JanetThreadedTimeout *)ptr;
|
JanetThreadedTimeout tto = *(JanetThreadedTimeout *)ptr;
|
||||||
janet_free(ptr);
|
janet_free(ptr);
|
||||||
SleepEx((DWORD)(tto.sec * 1000), TRUE);
|
SleepEx((DWORD)(tto.sec * 1000), TRUE);
|
||||||
janet_interpreter_interrupt(tto.vm);
|
|
||||||
JanetEVGenericMessage msg = {0};
|
JanetEVGenericMessage msg = {0};
|
||||||
janet_ev_post_event(tto.vm, janet_timeout_cb, msg);
|
janet_ev_post_event(tto.vm, janet_timeout_cb, msg);
|
||||||
|
janet_interpreter_interrupt(tto.vm);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -716,9 +716,9 @@ static void *janet_timeout_body(void *ptr) {
|
|||||||
? (long)((tto.sec - ((uint32_t)tto.sec)) * 1000000000)
|
? (long)((tto.sec - ((uint32_t)tto.sec)) * 1000000000)
|
||||||
: 0;
|
: 0;
|
||||||
nanosleep(&ts, &ts);
|
nanosleep(&ts, &ts);
|
||||||
janet_interpreter_interrupt(tto.vm);
|
|
||||||
JanetEVGenericMessage msg = {0};
|
JanetEVGenericMessage msg = {0};
|
||||||
janet_ev_post_event(tto.vm, janet_timeout_cb, msg);
|
janet_ev_post_event(tto.vm, janet_timeout_cb, msg);
|
||||||
|
janet_interpreter_interrupt(tto.vm);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -106,6 +106,8 @@
|
|||||||
(calc-2 "(+ 9 10 11 12)"))
|
(calc-2 "(+ 9 10 11 12)"))
|
||||||
@[10 26 42]) "parallel subprocesses 2")
|
@[10 26 42]) "parallel subprocesses 2")
|
||||||
|
|
||||||
|
# (print "file piping")
|
||||||
|
|
||||||
# File piping
|
# File piping
|
||||||
# a1cc5ca04
|
# a1cc5ca04
|
||||||
(assert-no-error "file writing 1"
|
(assert-no-error "file writing 1"
|
||||||
@ -225,6 +227,8 @@
|
|||||||
(++ iterations)
|
(++ iterations)
|
||||||
(ev/write stream " ")))
|
(ev/write stream " ")))
|
||||||
|
|
||||||
|
# (print "local name / peer name testing")
|
||||||
|
|
||||||
# Test localname and peername
|
# Test localname and peername
|
||||||
# 077bf5eba
|
# 077bf5eba
|
||||||
(repeat 10
|
(repeat 10
|
||||||
@ -407,6 +411,8 @@
|
|||||||
(while (def msg (ev/read connection 100))
|
(while (def msg (ev/read connection 100))
|
||||||
(broadcast name (string msg)))))))
|
(broadcast name (string msg)))))))
|
||||||
|
|
||||||
|
# (print "chat app testing")
|
||||||
|
|
||||||
# Now launch the chat server
|
# Now launch the chat server
|
||||||
(def chat-server (net/listen test-host test-port))
|
(def chat-server (net/listen test-host test-port))
|
||||||
(ev/spawn
|
(ev/spawn
|
||||||
@ -500,6 +506,8 @@
|
|||||||
(let [s (net/listen :unix uds-path :stream)]
|
(let [s (net/listen :unix uds-path :stream)]
|
||||||
(:close s))))))
|
(:close s))))))
|
||||||
|
|
||||||
|
# (print "accept loop testing")
|
||||||
|
|
||||||
# net/accept-loop level triggering
|
# net/accept-loop level triggering
|
||||||
(gccollect)
|
(gccollect)
|
||||||
(def maxconn 50)
|
(def maxconn 50)
|
||||||
@ -522,6 +530,8 @@
|
|||||||
(assert (= maxconn connect-count))
|
(assert (= maxconn connect-count))
|
||||||
(:close s)
|
(:close s)
|
||||||
|
|
||||||
|
# (print "running deadline tests...")
|
||||||
|
|
||||||
# Cancel os/proc-wait with ev/deadline
|
# Cancel os/proc-wait with ev/deadline
|
||||||
(let [p (os/spawn [;run janet "-e" "(os/sleep 4)"] :p)]
|
(let [p (os/spawn [;run janet "-e" "(os/sleep 4)"] :p)]
|
||||||
(var terminated-normally false)
|
(var terminated-normally false)
|
||||||
@ -565,13 +575,13 @@
|
|||||||
(,resume ,f))))
|
(,resume ,f))))
|
||||||
|
|
||||||
(for i 0 10
|
(for i 0 10
|
||||||
# (print "iteration " i)
|
# (print "deadline 1 iteration " i)
|
||||||
(assert (= :done (with-deadline2 10
|
(assert (= :done (with-deadline2 10
|
||||||
(ev/sleep 0.01)
|
(ev/sleep 0.01)
|
||||||
:done)) "deadline with interrupt exits normally"))
|
:done)) "deadline with interrupt exits normally"))
|
||||||
|
|
||||||
(for i 0 10
|
(for i 0 10
|
||||||
# (print "iteration " i)
|
# (print "deadline 2 iteration " i)
|
||||||
(let [f (coro (forever :foo))]
|
(let [f (coro (forever :foo))]
|
||||||
(ev/deadline 0.01 nil f true)
|
(ev/deadline 0.01 nil f true)
|
||||||
(assert-error "deadline expired" (resume f))))
|
(assert-error "deadline expired" (resume f))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user