@@ -57,11 +57,15 @@ static i32 extension_recv(CompilerExtension *ext, void *buf, i32 maxlen) {
57
57
return bytes_read ;
58
58
}
59
59
60
+ static void extension_wait (CompilerExtension * ext ) {
61
+ int status ;
62
+ waitpid (ext -> pid , & status , 0 );
63
+ }
64
+
60
65
static void extension_kill (CompilerExtension * ext ) {
61
66
ext -> alive = 0 ;
62
67
kill (ext -> pid , SIGKILL );
63
- int status ;
64
- waitpid (ext -> pid , & status , 0 );
68
+ extension_wait (ext );
65
69
}
66
70
67
71
static b32 extension_spawn (CompilerExtension * ext , const char * path ) {
@@ -119,6 +123,9 @@ static b32 extension_poll_recv(CompilerExtension *ext) {
119
123
return 0 ;
120
124
}
121
125
126
+ static void extension_wait (CompilerExtension * ext ) {
127
+ }
128
+
122
129
static void extension_kill (CompilerExtension * ext ) {
123
130
}
124
131
@@ -262,13 +269,11 @@ b32 compiler_extension_negotiate_capabilities(Context *context, CompilerExtensio
262
269
}
263
270
}
264
271
265
- {
266
- compiler_event_log (
267
- context ,
268
- "Extension '%s' spawned with protocol version %d." ,
269
- ext -> name , extension_protocol_version
270
- );
271
- }
272
+ compiler_event_log (
273
+ context ,
274
+ "Extension '%s' spawned with protocol version %d." ,
275
+ ext -> name , extension_protocol_version
276
+ );
272
277
273
278
bh_arena_clear (& ext -> arena );
274
279
return 1 ;
@@ -493,3 +498,22 @@ TypeMatch compiler_extension_hook_stalled(Context *context, int extension_id) {
493
498
}
494
499
}
495
500
501
+ void compiler_extension_terminate (Context * context , int extension_id ) {
502
+ if (extension_id <= 0 || extension_id > bh_arr_length (context -> extensions )) return ;
503
+
504
+ CompilerExtension * ext = & context -> extensions [extension_id - 1 ];
505
+
506
+ if (!ext -> alive ) return ;
507
+ if (ext -> state != COMP_EXT_STATE_READY ) return ;
508
+
509
+ extension_send_int (ext , MSG_HOST_TERMINATE );
510
+
511
+ compiler_event_log (
512
+ context ,
513
+ "Waiting for extension '%s' to exit..." ,
514
+ ext -> name
515
+ );
516
+
517
+ extension_wait (ext );
518
+ }
519
+
0 commit comments