From da046861765d1eb5b7e7b4e419a143e821634395 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sat, 25 Mar 2017 05:16:18 +0000 Subject: [PATCH] fixed a bug in handling io semaphores when no process is runnable --- moo/lib/exec.c | 40 +++++++++++++++++++++++++++------------- moo/mod/x11.c | 30 +----------------------------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 7ebb6d3..5b83c6b 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -140,7 +140,7 @@ static MOO_INLINE void vm_sleep (moo_t* moo, const moo_ntime_t* dur) moo->vmprim.vm_sleep (moo, dur); } -static MOO_INLINE void vm_vm_muxwait (moo_t* moo, const moo_ntime_t* dur) +static MOO_INLINE void vm_muxwait (moo_t* moo, const moo_ntime_t* dur) { moo->vmprim.vm_muxwait (moo, dur, signal_io_semaphore); } @@ -839,7 +839,6 @@ static void signal_io_semaphore (moo_t* moo, int mask, void* ctx) wake_new_process (moo, proc); /* switch to running */ moo->proc_switched = 1; } - } else { @@ -3368,7 +3367,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) /* [NOTE] no moo_pushtmp() on proc. no GC must occur * in the following line until it's used for * wake_new_process() below. */ - delete_from_sem_heap (moo, 0); + delete_from_sem_heap (moo, 0); /* moo->sem_heap_count is decremented */ /* if no process is waiting on the semaphore, * signal_semaphore() returns moo->_nil. */ @@ -3394,10 +3393,15 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) if (moo->sem_io_wait_count > 0) { - vm_vm_muxwait (moo, &ft); + /* no running process but io semaphore being waited on */ + vm_muxwait (moo, &ft); + + /* if a process has been woken up, + if (moo->processor->active != moo->nil_process) break; } else { + /* no running process, no io semaphore */ vm_sleep (moo, &ft); } vm_gettime (moo, &now); @@ -3413,7 +3417,23 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) if (moo->sem_io_wait_count > 0) { - vm_vm_muxwait (moo, MOO_NULL); + moo_ntime_t now; + + if (moo->processor->active == moo->nil_process) + { + /* no runnable process while there is an io semaphore being waited */ + do + { + vm_gettime (moo, &now); + now.sec += 3; + vm_muxwait (moo, &now); + } + while (moo->processor->active == moo->nil_process && !moo->abort_req); + } + else + { + vm_muxwait (moo, MOO_NULL); + } } if (moo->processor->active == moo->nil_process) @@ -3421,23 +3441,17 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) /* no more waiting semaphore and no more process */ MOO_ASSERT (moo, moo->processor->tally = MOO_SMOOI_TO_OOP(0)); MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "No more runnable process\n"); - - #if 0 - if (there is semaphore awaited.... ) - { - /* DO SOMETHING */ - } - #endif - return 0; } +#if 0 while (moo->sem_list_count > 0) { /* handle async signals */ --moo->sem_list_count; signal_semaphore (moo, moo->sem_list[moo->sem_list_count]); } +#endif /* if (semaphore heap has pending request) { diff --git a/moo/mod/x11.c b/moo/mod/x11.c index 14933cd..0f07d6a 100644 --- a/moo/mod/x11.c +++ b/moo/mod/x11.c @@ -53,8 +53,6 @@ typedef struct x11_modctx_t x11_modctx_t; struct x11_modctx_t { moo_oop_class_t x11_class; - moo_oop_class_t mouse_event_class; - moo_oop_class_t key_event_class; }; typedef struct x11_t x11_t; @@ -371,8 +369,7 @@ static void x11_gc (moo_t* moo, moo_mod_t* mod) x11_modctx_t* ctx = mod->ctx; MOO_ASSERT (moo, ctx != MOO_NULL); - ctx->mouse_event_class = (moo_oop_class_t)moo_moveoop (moo, (moo_oop_t)ctx->mouse_event_class); - ctx->key_event_class = (moo_oop_class_t)moo_moveoop (moo, (moo_oop_t)ctx->key_event_class); + ctx->x11_class = (moo_oop_class_t)moo_moveoop (moo, (moo_oop_t)ctx->x11_class); } int moo_mod_x11 (moo_t* moo, moo_mod_t* mod) @@ -387,8 +384,6 @@ int moo_mod_x11 (moo_t* moo, moo_mod_t* mod) x11_modctx_t* ctx; static moo_ooch_t name_x11[] = { 'X','1','1','\0' }; - static moo_ooch_t name_mouse_event[] = { 'M','o','u','s','e','E','v','e','n','t','\0' }; - static moo_ooch_t name_key_event[] = { 'K','e','y','E','v','e','n','t','\0' }; ctx = moo_callocmem (moo, MOO_SIZEOF(*ctx)); if (!ctx) return -1; @@ -398,33 +393,10 @@ int moo_mod_x11 (moo_t* moo, moo_mod_t* mod) { /* Not a single X11.XXX has been defined. */ MOO_DEBUG0 (moo, "X11 class not found\n"); - oops: moo_freemem (moo, ctx); return -1; } - if ((moo_oop_t)ctx->x11_class->nsdic == moo->_nil) - { - MOO_DEBUG0 (moo, "No class defined in X11\n"); - goto oops; - } - -/* TODO: check on instance size... etc */ -/* TODO: tabulate key event classes */ - ctx->mouse_event_class = (moo_oop_class_t)moo_findclass (moo, ctx->x11_class->nsdic, name_mouse_event); - if (!ctx->mouse_event_class) - { - MOO_DEBUG0 (moo, "X11.MouseEvent class not found\n"); - goto oops; - } - ctx->key_event_class = (moo_oop_class_t)moo_findclass (moo, ctx->x11_class->nsdic, name_key_event); - - if (!ctx->key_event_class) - { - MOO_DEBUG0 (moo, "X11.KeyEvent class not found\n"); - goto oops; - } - mod->gc = x11_gc; mod->ctx = ctx; }