From 19153f312e317ead987876e0197392bcaff3f2cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 2 Dec 2019 23:41:42 +0100 Subject: [PATCH] :art: Use vm->parent --- include/vm.h | 1 + src/lib/shred.c | 9 ++------- src/vm/vm.c | 3 ++- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/vm.h b/include/vm.h index 3f9ec9cc..47fecd79 100644 --- a/include/vm.h +++ b/include/vm.h @@ -25,6 +25,7 @@ typedef struct VM_ { struct BBQ_* bbq; struct Gwion_* gwion; VM_Shred cleaner_shred; + struct VM_ *parent; uint32_t rand[2]; } VM; diff --git a/src/lib/shred.c b/src/lib/shred.c index f25f028f..a139a6e3 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -13,13 +13,11 @@ #include "specialid.h" #include "gwi.h" -static m_int o_fork_thread, o_shred_cancel, o_fork_done, o_fork_ev, o_fork_retsize, o_fork_retval, - o_fork_orig; +static m_int o_fork_thread, o_shred_cancel, o_fork_done, o_fork_ev, o_fork_retsize, o_fork_retval; #define FORK_THREAD(o) *(THREAD_TYPE*)(o->data + o_fork_thread) #define FORK_RETSIZE(o) *(m_int*)(o->data + o_fork_retsize) #define FORK_RETVAL(o) (o->data + o_fork_retval) -#define FORK_ORIG(o) (*(VM**)((o)->data + o_fork_orig)) VM_Shred new_shred_base(const VM_Shred shred, const VM_Code code) { const VM_Shred sh = new_vm_shred(shred->info->mp, code); @@ -149,7 +147,7 @@ static MFUN(shred_unlock) { static DTOR(fork_dtor) { THREAD_JOIN(FORK_THREAD(o)); - const VM *vm = FORK_ORIG(o); + const VM *vm = ME(o)->info->vm->parent; if(*(m_int*)(o->data + o_fork_done)) { vector_rem2(&vm->gwion->data->child, (vtype)o); if(!vm->gwion->data->child2.ptr) @@ -217,7 +215,6 @@ ANN void fork_launch(const VM* vm, const M_Object o, const m_uint sz) { if(!vm->gwion->data->child.ptr) vector_init(&vm->gwion->data->child); vector_add(&vm->gwion->data->child, (vtype)o); - FORK_ORIG(o) = (VM*)vm; FORK_RETSIZE(o) = sz; THREAD_CREATE(FORK_THREAD(o), fork_run, o); } @@ -314,8 +311,6 @@ GWION_IMPORT(shred) { GWI_BB((o_fork_ev = gwi_item_end(gwi, ae_flag_const, NULL))) gwi_item_ini(gwi, "int", "retsize"); GWI_BB((o_fork_retsize = gwi_item_end(gwi, ae_flag_const, NULL))) - gwi_item_ini(gwi, "@internal", "@orig"); - GWI_BB((o_fork_orig = gwi_item_end(gwi, ae_flag_const, NULL))) o_fork_retval = t_fork->nspc->info->offset; GWI_BB(gwi_union_ini(gwi, NULL, NULL)) GWI_BB(gwi_union_add(gwi, "int", "i")) diff --git a/src/vm/vm.c b/src/vm/vm.c index fa3dd6ba..d1d4368e 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -69,8 +69,9 @@ 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) { +ANN static void vm_fork(VM* src, const VM_Shred shred) { VM* vm = (shred->info->vm = gwion_cpy(src)); + vm->parent = src; shred->info->me = new_shred(shred, 0); shreduler_add(vm->shreduler, shred); } -- 2.43.0