4747extern "C" {
4848#endif
4949
50+ static uv_async_t signal_async ;
51+
52+ static void jl_signal_async_cb (uv_async_t * hdl )
53+ {
54+ // This should abort the current loop and the julia code it returns to
55+ // or the safepoint in the callers of `uv_run` should throw the exception.
56+ (void )hdl ;
57+ uv_stop (jl_io_loop );
58+ }
59+
60+ void jl_wake_libuv (void )
61+ {
62+ uv_async_send (& signal_async );
63+ }
64+
65+ void jl_init_signal_async (void )
66+ {
67+ uv_async_init (jl_io_loop , & signal_async , jl_signal_async_cb );
68+ }
69+
5070extern jl_module_t * jl_old_base_module ;
5171static jl_value_t * close_cb = NULL ;
5272
@@ -80,6 +100,8 @@ JL_DLLEXPORT void jl_uv_closeHandle(uv_handle_t *handle)
80100 // also let the client app do its own cleanup
81101 if (handle -> type != UV_FILE && handle -> data )
82102 jl_uv_call_close_callback ((jl_value_t * )handle -> data );
103+ if (handle == (uv_handle_t * )& signal_async )
104+ return ;
83105 free (handle );
84106}
85107
@@ -114,6 +136,7 @@ JL_DLLEXPORT int jl_run_once(uv_loop_t *loop)
114136{
115137 if (loop ) {
116138 loop -> stop_flag = 0 ;
139+ jl_gc_safepoint ();
117140 return uv_run (loop ,UV_RUN_ONCE );
118141 }
119142 else return 0 ;
@@ -123,6 +146,7 @@ JL_DLLEXPORT void jl_run_event_loop(uv_loop_t *loop)
123146{
124147 if (loop ) {
125148 loop -> stop_flag = 0 ;
149+ jl_gc_safepoint ();
126150 uv_run (loop ,UV_RUN_DEFAULT );
127151 }
128152}
@@ -131,6 +155,7 @@ JL_DLLEXPORT int jl_process_events(uv_loop_t *loop)
131155{
132156 if (loop ) {
133157 loop -> stop_flag = 0 ;
158+ jl_gc_safepoint ();
134159 return uv_run (loop ,UV_RUN_NOWAIT );
135160 }
136161 else return 0 ;
0 commit comments