From: fennecdjay Date: Sun, 3 Jul 2022 19:51:37 +0000 (+0200) Subject: :bug: Clean shred on exit X-Git-Tag: nightly~264^2~105 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=b2782f74ba92c13c816aa07f0285e53c9342aee6;p=gwion.git :bug: Clean shred on exit --- diff --git a/include/vm.h b/include/vm.h index deca0f85..e57b036d 100644 --- a/include/vm.h +++ b/include/vm.h @@ -131,7 +131,7 @@ ANN m_str code_name(const m_str, const bool); ANN uint32_t gw_rand(uint32_t s[2]); ANN void gw_seed(uint32_t s[2], const uint64_t); ANN void handle(VM_Shred shred, const m_str effect); - +ANN bool unwind(const VM_Shred shred, const Symbol effect, const m_uint size); #define BBQ_POS_MAX 16777216 diff --git a/src/lib/shred.c b/src/lib/shred.c index 0d3f5100..7d585680 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -58,7 +58,7 @@ ANN M_Object new_fork(const VM_Shred shred, const VM_Code code, const Type t) { static MFUN(gw_shred_exit) { const VM_Shred s = ME(o); if((m_int)s->tick->prev != -1) - shreduler_remove(s->tick->shreduler, s, true); + shreduler_remove(s->tick->shreduler, s, true); } static MFUN(vm_shred_id) { diff --git a/src/vm/shreduler.c b/src/vm/shreduler.c index 9266ba83..a849dd79 100644 --- a/src/vm/shreduler.c +++ b/src/vm/shreduler.c @@ -40,15 +40,19 @@ ANN static inline void shreduler_child(const Vector v) { ANN static void shreduler_erase(const Shreduler s, struct ShredTick_ *const tk) { - MUTEX_LOCK(tk->self->mutex); + const VM_Shred shred = tk->self; + const m_uint size = + shred->info->frame.ptr ? vector_size(&shred->info->frame) : 0; + unwind(shred, (Symbol)-1, size); + MUTEX_LOCK(shred->mutex); if (tk->parent) { MUTEX_LOCK(tk->parent->self->mutex); vector_rem2(&tk->parent->child, (vtype)tk->self); MUTEX_UNLOCK(tk->parent->self->mutex); } if (tk->child.ptr) shreduler_child(&tk->child); - vector_rem2(&s->active_shreds, (vtype)tk->self); - MUTEX_UNLOCK(tk->self->mutex); + vector_rem2(&s->active_shreds, (vtype)shred); + MUTEX_UNLOCK(shred->mutex); } ANN void shreduler_remove(const Shreduler s, const VM_Shred out, diff --git a/src/vm/vm.c b/src/vm/vm.c index 52c55008..ef769d2b 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -92,7 +92,7 @@ ANN static inline bool find_handle(const VM_Shred shred, const Symbol effect, co return true; } -ANN static bool unwind(const VM_Shred shred, const Symbol effect, const m_uint size) { +ANN bool unwind(const VM_Shred shred, const Symbol effect, const m_uint size) { const VM_Code code = shred->code; if (code->live_values.ptr) clean_values(shred);