From 43c6384d33c201303f4a6d33975c0bdefa166c8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 1 Apr 2020 18:38:01 +0200 Subject: [PATCH] :art: Improve fork_run --- src/lib/shred.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/shred.c b/src/lib/shred.c index ba78145e..a54c1af0 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -208,7 +208,12 @@ static MFUN(shred_test_cancel) { static ANN THREAD_FUNC(fork_run) { VM *vm = (VM*)data; - const M_Object me = vm->shreduler->list->self->info->me; + vm_lock(vm->parent); + const M_Object me = vm->bbq->is_running ? + vm->shreduler->list->self->info->me : NULL; + vm_unlock(vm->parent); + if(!me) + THREAD_RETURN(0); while(vm->bbq->is_running) { vm_run(vm); ++vm->bbq->pos; @@ -220,16 +225,14 @@ static ANN THREAD_FUNC(fork_run) { } else if(me->ref > 1) release(me, ME(me)); vm_unlock(vm->parent); - THREAD_RETURN(NULL); + THREAD_RETURN(0); } ANN void fork_launch(VM const* vm, const M_Object o, const m_uint sz) { - vm_lock(vm); if(vm_running(vm)) { FORK_RETSIZE(o) = sz; THREAD_CREATE(FORK_THREAD(o), fork_run, ME(o)->info->vm); } else release(o, ME(o)); - vm_unlock(vm); } ANN void fork_clean(const VM_Shred shred, const Vector v) { -- 2.43.0