destroy mailboxes on thread exit
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m42s
Build and Deploy / build-windows (CLANG64) (push) Failing after 10m57s
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m42s
Build and Deploy / build-windows (CLANG64) (push) Failing after 10m57s
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
This commit is contained in:
@@ -24,6 +24,10 @@ prosperon.dispatch = function(type, data) {
|
|||||||
var os = use_embed('os')
|
var os = use_embed('os')
|
||||||
var js = use_embed('js')
|
var js = use_embed('js')
|
||||||
|
|
||||||
|
prosperon.on('exit', _ => {
|
||||||
|
os.mailbox_destroy(prosperon.id);
|
||||||
|
})
|
||||||
|
|
||||||
prosperon.on('SIGINT', function() {
|
prosperon.on('SIGINT', function() {
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
})
|
})
|
||||||
@@ -851,7 +855,6 @@ function handle_actor_disconnect(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handle_local(msg) {
|
function handle_local(msg) {
|
||||||
console.log(`got an arraybuffer of length ${msg.byteLength}`)
|
|
||||||
handle_message(wota.decode(msg))
|
handle_message(wota.decode(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7176,7 +7176,7 @@ JSC_CCALL(os_mailbox_push,
|
|||||||
|
|
||||||
if (!buf) return JS_ThrowInternalError(js, "Could not get data from arraybuffer.");
|
if (!buf) return JS_ThrowInternalError(js, "Could not get data from arraybuffer.");
|
||||||
|
|
||||||
void *data = malloc(size);
|
void *data = js_malloc_rt(JS_GetRuntime(js), size);
|
||||||
if (!data) return JS_ThrowInternalError(js, "Memory allocation failed.");
|
if (!data) return JS_ThrowInternalError(js, "Memory allocation failed.");
|
||||||
|
|
||||||
memcpy(data,buf,size);
|
memcpy(data,buf,size);
|
||||||
@@ -7248,6 +7248,31 @@ JSC_CCALL(os_mailbox_start,
|
|||||||
JS_FreeCString(js, id);
|
JS_FreeCString(js, id);
|
||||||
)
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(os_mailbox_destroy,
|
||||||
|
if (argc < 1) return JS_ThrowInternalError(js, "Need an actor/mailbox ID to destroy");
|
||||||
|
|
||||||
|
const char *id = JS_ToCString(js, argv[0]);
|
||||||
|
int mailbox_index = shgeti(mailboxes, id);
|
||||||
|
JS_FreeCString(js, id);
|
||||||
|
|
||||||
|
if (mailbox_index != -1) {
|
||||||
|
mailbox *mb = &mailboxes[mailbox_index].value;
|
||||||
|
SDL_LockMutex(mb->mutex);
|
||||||
|
|
||||||
|
int count = arrlen(mb->messages);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
js_free_rt(JS_GetRuntime(js), mb->messages[i].data);
|
||||||
|
arrfree(mb->messages);
|
||||||
|
SDL_UnlockMutex(mb->mutex);
|
||||||
|
|
||||||
|
SDL_DestroyMutex(mb->mutex);
|
||||||
|
|
||||||
|
SDL_LockMutex(mailboxes_mutex);
|
||||||
|
shdel(mailboxes, id);
|
||||||
|
SDL_UnlockMutex(mailboxes_mutex);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
JSC_CCALL(os_waitevent,
|
JSC_CCALL(os_waitevent,
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
double secs;
|
double secs;
|
||||||
@@ -7311,6 +7336,7 @@ static const JSCFunctionListEntry js_os_funcs[] = {
|
|||||||
MIST_FUNC_DEF(os, mailbox_service, 2),
|
MIST_FUNC_DEF(os, mailbox_service, 2),
|
||||||
MIST_FUNC_DEF(os, mailbox_start, 1),
|
MIST_FUNC_DEF(os, mailbox_start, 1),
|
||||||
MIST_FUNC_DEF(os, mailbox_exist, 1),
|
MIST_FUNC_DEF(os, mailbox_exist, 1),
|
||||||
|
MIST_FUNC_DEF(os, mailbox_destroy, 1),
|
||||||
MIST_FUNC_DEF(os, createthread, 1),
|
MIST_FUNC_DEF(os, createthread, 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user