From c638313fc7e5f95f898963ab8092b3e929bfcc25 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 11 Oct 2019 00:27:03 +0200 Subject: [PATCH] :art: Test shred.cancel --- src/lib/shred.c | 20 +++++++++++++------- tests/tree/shred_cancel.gw | 5 +++++ 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 tests/tree/shred_cancel.gw diff --git a/src/lib/shred.c b/src/lib/shred.c index 8ab29424..85d2bb66 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -178,16 +178,22 @@ static MFUN(fork_join) { } static MFUN(shred_cancel) { -MUTEX_LOCK(ME(o)->tick->shreduler->mutex); + MUTEX_LOCK(ME(o)->tick->shreduler->mutex); *(m_int*)(o->data + o_shred_cancel) = *(m_int*)MEM(SZ_INT); -MUTEX_UNLOCK(ME(o)->tick->shreduler->mutex); + MUTEX_UNLOCK(ME(o)->tick->shreduler->mutex); } static MFUN(shred_test_cancel) { -MUTEX_LOCK(ME(o)->tick->shreduler->mutex); - if(*(m_int*)(o->data + o_shred_cancel)) + MUTEX_LOCK(ME(o)->tick->shreduler->mutex); + if(*(m_int*)(o->data + o_shred_cancel)) { + const m_bool is_me = ME(o) == shred; + if(is_me) + MUTEX_UNLOCK(ME(o)->tick->shreduler->mutex); vm_shred_exit(ME(o)); -MUTEX_UNLOCK(ME(o)->tick->shreduler->mutex); + if(is_me) + return; + } + MUTEX_UNLOCK(ME(o)->tick->shreduler->mutex); } void fork_retval(const M_Object o) { @@ -236,10 +242,10 @@ GWION_IMPORT(shred) { GWI_BB(gwi_class_ini(gwi, t_shred, NULL, shred_dtor)) gwi_item_ini(gwi, "int", "@me"); - GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL)) + GWI_BB(gwi_item_end(gwi, ae_flag_const, NULL)) gwi_item_ini(gwi, "int", "cancel"); - GWI_BB((o_shred_cancel = gwi_item_end(gwi, 0, NULL))) + GWI_BB((o_shred_cancel = gwi_item_end(gwi, ae_flag_const, NULL))) gwi_func_ini(gwi, "void", "exit", gw_shred_exit); GWI_BB(gwi_func_end(gwi, 0)) diff --git a/tests/tree/shred_cancel.gw b/tests/tree/shred_cancel.gw new file mode 100644 index 00000000..92151a2c --- /dev/null +++ b/tests/tree/shred_cancel.gw @@ -0,0 +1,5 @@ +me.set_cancel(0); +me.test_cancel(); +me.set_cancel(1); +me.test_cancel(); +<<< "wont reach" >>>; -- 2.43.0