--- a/hotspot/src/os/windows/vm/os_windows.cpp Thu Jun 25 20:47:46 2015 +0000
+++ b/hotspot/src/os/windows/vm/os_windows.cpp Mon Jan 19 11:06:08 2015 +0100
@@ -63,6 +63,7 @@
#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"
@@ -1901,6 +1902,30 @@
return (int)error;
}
+WindowsSemaphore::WindowsSemaphore(uint value) {
+ _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL);
+
+ guarantee(_semaphore != NULL, err_msg("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, err_msg("ReleaseSemaphore failed with error code: %lu", GetLastError()));
+ }
+}
+
+void WindowsSemaphore::wait() {
+ DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE);
+ assert(ret != WAIT_FAILED, err_msg("WaitForSingleObject failed with error code: %lu", GetLastError()));
+ assert(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed with return value: %lu", ret));
+}
+
// 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