From: Jérémie Astor Date: Fri, 6 Dec 2019 19:59:27 +0000 (+0100) Subject: :art: Improve shred X-Git-Tag: nightly~2068^2~9 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=bb4dc6f3a8fa9c72ad05eb7535ae5b573d5c3cae;p=gwion.git :art: Improve shred --- diff --git a/src/lib/shred.c b/src/lib/shred.c index 71dc6892..7f9daa51 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -146,9 +146,11 @@ static MFUN(shred_unlock) { } static void stop(const M_Object o) { - VM *vm = ME(o)->info->vm->parent; + VM *vm = ME(o)->info->vm; MUTEX_LOCK(vm->shreduler->mutex); + MUTEX_LOCK(vm->parent->shreduler->mutex); vm->shreduler->bbq->is_running = 0; + MUTEX_UNLOCK(vm->parent->shreduler->mutex); MUTEX_UNLOCK(vm->shreduler->mutex); } @@ -162,13 +164,11 @@ static void join(const M_Object o) { static DTOR(fork_dtor) { stop(o); VM *vm = ME(o)->info->vm->parent; - if(*(m_int*)(o->data + o_fork_done)) { - const m_int idx = vector_find(&vm->gwion->data->child, (vtype)o); - VPTR(&vm->gwion->data->child, idx) = 0; - if(!vm->gwion->data->child2.ptr) - vector_init(&vm->gwion->data->child2); - vector_add(&vm->gwion->data->child2, (vtype)ME(o)->info->vm->gwion); - } + const m_int idx = vector_find(&vm->gwion->data->child, (vtype)o); + VPTR(&vm->gwion->data->child, idx) = 0; + if(!vm->gwion->data->child2.ptr) + vector_init(&vm->gwion->data->child2); + vector_add(&vm->gwion->data->child2, (vtype)ME(o)->info->vm->gwion); gwion_end_child(shred, ME(o)->info->vm->gwion); join(o); } @@ -216,15 +216,17 @@ static ANN void* fork_run(void* data) { VM *vm = (VM*)data; const M_Object me = vm->shreduler->list->self->info->me; while(vm->bbq->is_running) { -// while(vm_running(vm)) { vm_run(vm); ++vm->bbq->pos; } - fork_retval(me); - MUTEX_LOCK(vm->shreduler->mutex); - *(m_int*)(me->data + o_fork_done) = 1; - broadcast(*(M_Object*)(me->data + o_fork_ev)); - MUTEX_UNLOCK(vm->shreduler->mutex); + vm_lock(vm->parent); + if(vm_running(vm->parent)) { + fork_retval(me); + *(m_int*)(me->data + o_fork_done) = 1; + broadcast(*(M_Object*)(me->data + o_fork_ev)); + } else + release(me, ME(me)); + vm_unlock(vm->parent); THREAD_RETURN(NULL); }