< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page

        

*** 60,70 **** #include "runtime/stubRoutines.hpp" #include "runtime/thread.inline.hpp" #include "runtime/threadCritical.hpp" #include "runtime/timer.hpp" #include "runtime/vm_version.hpp" - #include "semaphore_windows.hpp" #include "services/attachListener.hpp" #include "services/memTracker.hpp" #include "services/runtimeService.hpp" #include "utilities/align.hpp" #include "utilities/decoder.hpp" --- 60,69 ----
*** 1843,1882 **** error = errno; } return (int)error; } - WindowsSemaphore::WindowsSemaphore(uint value) { - _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL); - - guarantee(_semaphore != NULL, "CreateSemaphore failed with error code: %lu", GetLastError()); - } - - WindowsSemaphore::~WindowsSemaphore() { - ::CloseHandle(_semaphore); - } - - void WindowsSemaphore::signal(uint count) { - if (count > 0) { - BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL); - - assert(ret != 0, "ReleaseSemaphore failed with error code: %lu", GetLastError()); - } - } - - void WindowsSemaphore::wait() { - DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE); - assert(ret != WAIT_FAILED, "WaitForSingleObject failed with error code: %lu", GetLastError()); - assert(ret == WAIT_OBJECT_0, "WaitForSingleObject failed with return value: %lu", ret); - } - - bool WindowsSemaphore::trywait() { - DWORD ret = ::WaitForSingleObject(_semaphore, 0); - assert(ret != WAIT_FAILED, "WaitForSingleObject failed with error code: %lu", GetLastError()); - return ret == WAIT_OBJECT_0; - } - // sun.misc.Signal // NOTE that this is a workaround for an apparent kernel bug where if // a signal handler for SIGBREAK is installed then that signal handler // takes priority over the console control handler for CTRL_CLOSE_EVENT. // See bug 4416763. --- 1842,1851 ----
*** 1964,1980 **** return NSIG; } // a counter for each possible signal value, including signal_thread exit signal static volatile jint pending_signals[NSIG+1] = { 0 }; ! static HANDLE sig_sem = NULL; void os::signal_init_pd() { // Initialize signal structures memset((void*)pending_signals, 0, sizeof(pending_signals)); ! sig_sem = ::CreateSemaphore(NULL, 0, NSIG+1, NULL); // Programs embedding the VM do not want it to attempt to receive // events like CTRL_LOGOFF_EVENT, which are used to implement the // shutdown hooks mechanism introduced in 1.3. For example, when // the VM is run as part of a Windows NT service (i.e., a servlet --- 1933,1950 ---- return NSIG; } // a counter for each possible signal value, including signal_thread exit signal static volatile jint pending_signals[NSIG+1] = { 0 }; ! static Semaphore* sig_sem = NULL; void os::signal_init_pd() { // Initialize signal structures memset((void*)pending_signals, 0, sizeof(pending_signals)); ! // Initialize signal semaphore ! sig_sem = new Semaphore(); // Programs embedding the VM do not want it to attempt to receive // events like CTRL_LOGOFF_EVENT, which are used to implement the // shutdown hooks mechanism introduced in 1.3. For example, when // the VM is run as part of a Windows NT service (i.e., a servlet
*** 1992,2012 **** // Add a CTRL-C handler SetConsoleCtrlHandler(consoleHandler, TRUE); } } ! void os::signal_notify(int signal_number) { ! BOOL ret; if (sig_sem != NULL) { ! Atomic::inc(&pending_signals[signal_number]); ! ret = ::ReleaseSemaphore(sig_sem, 1, NULL); ! assert(ret != 0, "ReleaseSemaphore() failed"); } } static int check_pending_signals(bool wait_for_signal) { - DWORD ret; while (true) { for (int i = 0; i < NSIG + 1; i++) { jint n = pending_signals[i]; if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) { return i; --- 1962,1983 ---- // Add a CTRL-C handler SetConsoleCtrlHandler(consoleHandler, TRUE); } } ! void os::signal_notify(int sig) { if (sig_sem != NULL) { ! Atomic::inc(&pending_signals[sig]); ! sig_sem->signal(); ! } else { ! // Signal thread is not created with ReduceSignalUsage and signal_init_pd ! // initialization isn't called. ! assert(ReduceSignalUsage, "signal semaphore should be created"); } } static int check_pending_signals(bool wait_for_signal) { while (true) { for (int i = 0; i < NSIG + 1; i++) { jint n = pending_signals[i]; if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) { return i;
*** 2022,2054 **** bool threadIsSuspended; do { thread->set_suspend_equivalent(); // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() ! ret = ::WaitForSingleObject(sig_sem, INFINITE); ! assert(ret == WAIT_OBJECT_0, "WaitForSingleObject() failed"); // were we externally suspended while we were waiting? threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); if (threadIsSuspended) { // The semaphore has been incremented, but while we were waiting // another thread suspended us. We don't want to continue running // while suspended because that would surprise the thread that // suspended us. ! ret = ::ReleaseSemaphore(sig_sem, 1, NULL); ! assert(ret != 0, "ReleaseSemaphore() failed"); thread->java_suspend_self(); } } while (threadIsSuspended); } } - int os::signal_lookup() { - return check_pending_signals(false); - } - int os::signal_wait() { return check_pending_signals(true); } // Implicit OS exception handling --- 1993,2019 ---- bool threadIsSuspended; do { thread->set_suspend_equivalent(); // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() ! sig_sem->wait(); // were we externally suspended while we were waiting? threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); if (threadIsSuspended) { // The semaphore has been incremented, but while we were waiting // another thread suspended us. We don't want to continue running // while suspended because that would surprise the thread that // suspended us. ! sig_sem->signal(); thread->java_suspend_self(); } } while (threadIsSuspended); } } int os::signal_wait() { return check_pending_signals(true); } // Implicit OS exception handling
< prev index next >