< prev index next >
src/os/windows/vm/os_windows.cpp
Print this page
@@ -68,10 +68,11 @@
#include "services/runtimeService.hpp"
#include "utilities/decoder.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/events.hpp"
#include "utilities/growableArray.hpp"
+#include "utilities/semaphore.hpp"
#include "utilities/vmError.hpp"
#ifdef _DEBUG
#include <crtdbg.h>
#endif
@@ -1893,10 +1894,35 @@
error = errno;
}
return (int)error;
}
+Semaphore::Semaphore(uint value) {
+ _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL);
+
+ assert(_semaphore != NULL, err_msg("CreateSemaphore failed: %ld", GetLastError()));
+}
+
+Semaphore::~Semaphore() {
+ if (_semaphore != NULL) {
+ ::CloseHandle(_semaphore);
+ }
+}
+
+void Semaphore::signal(uint count) {
+ if (count > 0) {
+ BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL);
+
+ assert(ret != 0, err_msg("ReleaseSemaphore failed: %d", GetLastError()));
+ }
+}
+
+void Semaphore::wait() {
+ DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE);
+ assert(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed: %d", GetLastError()));
+}
+
// 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.
< prev index next >