--- old/src/os/windows/vm/os_windows.cpp 2015-06-15 21:33:54.301130129 +0200 +++ new/src/os/windows/vm/os_windows.cpp 2015-06-15 21:33:54.141124754 +0200 @@ -70,6 +70,7 @@ #include "utilities/defaultStream.hpp" #include "utilities/events.hpp" #include "utilities/growableArray.hpp" +#include "utilities/semaphore.hpp" #include "utilities/vmError.hpp" #ifdef _DEBUG @@ -1895,6 +1896,33 @@ return (int)error; } +Semaphore::Semaphore(uint value, uint max) { + _semaphore = ::CreateSemaphore(NULL, value, max, NULL); + + assert(_semaphore != NULL, err_msg("CreateSemaphore failed: %ld", GetLastError())); +} + +Semaphore::~Semaphore() { + if (_semaphore != NULL) { + ::CloseHandle(_semaphore); + } +} + +void Semaphore::signal(uint count) { + BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL); + + assert(ret != 0, err_msg("ReleaseSemaphore failed: %d", GetLastError())); +} + +void Semaphore::signal() { + signal(1); +} + +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