From b414f01ccf554a49363d204b0fe433695fe6dd6f Mon Sep 17 00:00:00 2001 From: Salikh Zakirov Date: Thu, 1 Mar 2007 11:45:32 +0300 Subject: [PATCH] hythread_global_lock(): make sure we are not requested to suspend --- vm/thread/src/thread_init.c | 33 ++++++++++++++++++++++++++- vm/vmcore/src/class_support/C_Interface.cpp | 2 - 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/vm/thread/src/thread_init.c b/vm/thread/src/thread_init.c index ab2f078..3dd903d 100644 --- a/vm/thread/src/thread_init.c +++ b/vm/thread/src/thread_init.c @@ -229,7 +229,38 @@ void VMCALL hythread_lib_unlock(hythread_t self) { * The lock blocks new thread creation and thread exit operations. */ IDATA VMCALL hythread_global_lock() { - return hymutex_lock(TM_LIBRARY->TM_LOCK); + IDATA r = 0; + hythread_t self = tm_self_tls; + int saved_count; + + // we need not care about suspension if the thread + // is not even tattached to hythread + if (self == NULL) + return hymutex_lock(TM_LIBRARY->TM_LOCK); + + // suspend_disable_count must be 0 on potentially + // blocking operation to prevent suspension deadlocks, + // meaning that the thread is safe for suspension + saved_count = reset_suspend_disable(); + r = hymutex_lock(TM_LIBRARY->TM_LOCK); + if (r) return r; + + // make sure we do not get a global thread lock + // while being requested to suspend + while (self->suspend_request) { + // give up global thread lock before safepoint, + // because this thread can be suspended at a safepoint + r = hymutex_unlock(TM_LIBRARY->TM_LOCK); + if (r) return r; + hythread_safe_point(); + r = hymutex_lock(TM_LIBRARY->TM_LOCK); + if (r) return r; + } + + // do not use set_suspend_disable() as we do not + // want safe points happening under global lock + self->suspend_disable_count = saved_count; + return 0; } /** diff --git a/vm/vmcore/src/class_support/C_Interface.cpp b/vm/vmcore/src/class_support/C_Interface.cpp index ab61b2f..2d587c1 100644 --- a/vm/vmcore/src/class_support/C_Interface.cpp +++ b/vm/vmcore/src/class_support/C_Interface.cpp @@ -2296,9 +2296,7 @@ enum safepoint_state get_global_safepoint_status() void vm_gc_lock_enum() { - tmn_suspend_enable(); hythread_global_lock(); - tmn_suspend_disable(); } // vm_gc_lock_enum -- 1.5.0.32.g0dacb