From 0e4681f25a851eab38795c31f276effd042ac4fa Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 8 Oct 2019 23:08:56 +0200 Subject: [PATCH] :art: ReEnable Forks --- include/gwiondata.h | 1 + src/emit/emit.c | 4 ---- src/lib/shred.c | 7 +++---- src/vm/vm.c | 5 ++--- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/gwiondata.h b/include/gwiondata.h index c21a27ac..742e1c99 100644 --- a/include/gwiondata.h +++ b/include/gwiondata.h @@ -8,6 +8,7 @@ typedef struct GwionData_ { struct Vector_ reserved; struct Map_ pass_map; struct Vector_ pass; + struct Gwion_ *base; } GwionData; ANN GwionData* new_gwiondata(MemPool); diff --git a/src/emit/emit.c b/src/emit/emit.c index 9d2aaf15..085c6dc4 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1077,8 +1077,6 @@ if(is_spork) { } else { const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd); spork->m_val = exp_self(unary)->emit_var; - if(!(spork->m_val = exp_self(unary)->emit_var)) -return NULL;// err_msg } } else { if(GET_FLAG(f, member) && is_fptr(emit->gwion, f->value_ref->type)) { @@ -1090,8 +1088,6 @@ return NULL;// err_msg } else emit_exp_spork_finish(emit, f->def->stack_depth); const Instr end = emit_add_instr(emit, is_spork ? SporkEnd : ForkEnd); - if(!is_spork && !(end->m_val = exp_self(unary)->emit_var)) - return NULL;// err_msg end->m_val2 = f->def->base->ret_type->size; } return ini; diff --git a/src/lib/shred.c b/src/lib/shred.c index ab08d86a..41aeed37 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -153,6 +153,8 @@ static MFUN(shred_unlock) { } static DTOR(fork_dtor) { + if(*(m_int*)(o->data + o_fork_done)) + vector_rem2(&FORK_ORIG(o)->gwion->data->child, (vtype)o); THREAD_JOIN(FORK_THREAD(o)); VM *vm = ME(o)->info->vm; free_vm(vm); @@ -201,9 +203,6 @@ static ANN void* fork_run(void* data) { } while(vm->bbq->is_running); fork_retval(me); MUTEX_LOCK(vm->shreduler->mutex); -// MUTEX_LOCK(FORK_ORIG(me)->shreduler->mutex); - vector_rem2(&FORK_ORIG(me)->gwion->data->child, (vtype)me); -// MUTEX_UNLOCK(FORK_ORIG(me)->shreduler->mutex); *(m_int*)(me->data + o_fork_done) = 1; broadcast(*(M_Object*)(me->data + o_fork_ev)); MUTEX_UNLOCK(vm->shreduler->mutex); @@ -220,7 +219,7 @@ ANN void fork_clean(const VM *vm, const Vector v) { } void fork_launch(const VM* vm, const M_Object o, const m_uint sz) { - o->ref += 2; + o->ref += 1; if(!vm->gwion->data->child.ptr) vector_init(&vm->gwion->data->child); vector_add(&vm->gwion->data->child, (vtype)o); diff --git a/src/vm/vm.c b/src/vm/vm.c index 75a9f40f..51742e90 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -78,9 +78,10 @@ ANN void vm_add_shred(const VM* vm, const VM_Shred shred) { #include "gwion.h" ANN void vm_fork(const VM* src, const VM_Shred shred) { - VM* vm = shred->info->vm = gwion_cpy(src); + VM* vm = (shred->info->vm = gwion_cpy(src)); shred->info->me = new_shred(shred, 0); shreduler_add(vm->shreduler, shred); + vm->gwion->data->base = src->gwion; } __attribute__((hot)) @@ -128,8 +129,6 @@ ANN static inline VM_Shred init_spork_shred(const VM_Shred shred, const VM_Code ANN static inline VM_Shred init_fork_shred(const VM_Shred shred, const VM_Code code) { const VM_Shred sh = new_shred_base(shred, code); vm_fork(shred->info->vm, sh); - assert(sh->info->me); - vector_add(&shred->gc, (vtype)sh->info->me); return sh; } -- 2.43.0