mirror of
https://github.com/janet-lang/janet
synced 2024-11-17 14:14:49 +00:00
Handle refcounts in posted events.
This commit is contained in:
parent
555e0c0b85
commit
7f852b8af4
@ -1412,6 +1412,7 @@ static void janet_ev_handle_selfpipe(void) {
|
||||
while (read(janet_vm.selfpipe[0], &response, sizeof(response)) > 0) {
|
||||
if (NULL != response.cb) {
|
||||
response.cb(response.msg);
|
||||
janet_ev_dec_refcount();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1472,6 +1473,7 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp to) {
|
||||
if (NULL != response->cb) {
|
||||
response->cb(response->msg);
|
||||
}
|
||||
janet_ev_dec_refcount();
|
||||
janet_free(response);
|
||||
} else {
|
||||
/* Normal event */
|
||||
@ -1892,6 +1894,7 @@ void janet_ev_deinit(void) {
|
||||
*/
|
||||
void janet_ev_post_event(JanetVM *vm, JanetCallback cb, JanetEVGenericMessage msg) {
|
||||
vm = vm ? vm : &janet_vm;
|
||||
janet_atomic_inc(&vm->listener_count);
|
||||
#ifdef JANET_WINDOWS
|
||||
JanetHandle iocp = vm->iocp;
|
||||
JanetSelfPipeEvent *event = janet_malloc(sizeof(JanetSelfPipeEvent));
|
||||
|
@ -517,7 +517,6 @@ static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
||||
|
||||
/* Callback that is called in main thread when subroutine completes. */
|
||||
static void janet_proc_wait_cb(JanetEVGenericMessage args) {
|
||||
janet_ev_dec_refcount();
|
||||
JanetProc *proc = (JanetProc *) args.argp;
|
||||
if (NULL != proc) {
|
||||
int status = args.tag;
|
||||
@ -827,7 +826,6 @@ static void janet_signal_callback(JanetEVGenericMessage msg) {
|
||||
JanetFunction *handler = janet_unwrap_function(handlerv);
|
||||
JanetFiber *fiber = janet_fiber(handler, 64, 0, NULL);
|
||||
janet_schedule_soon(fiber, janet_wrap_nil(), JANET_SIGNAL_OK);
|
||||
janet_ev_dec_refcount();
|
||||
}
|
||||
|
||||
static void janet_signal_trampoline_no_interrupt(int sig) {
|
||||
@ -836,7 +834,6 @@ static void janet_signal_trampoline_no_interrupt(int sig) {
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.tag = sig;
|
||||
janet_ev_post_event(&janet_vm, janet_signal_callback, msg);
|
||||
janet_ev_inc_refcount();
|
||||
}
|
||||
|
||||
static void janet_signal_trampoline(int sig) {
|
||||
@ -847,7 +844,6 @@ static void janet_signal_trampoline(int sig) {
|
||||
msg.argi = 1;
|
||||
janet_interpreter_interrupt(NULL);
|
||||
janet_ev_post_event(&janet_vm, janet_signal_callback, msg);
|
||||
janet_ev_inc_refcount();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user