--- old/src/os/windows/vm/os_windows.cpp 2015-06-12 14:46:29.512172460 +0200 +++ new/src/os/windows/vm/os_windows.cpp 2015-06-12 14:46:29.352167230 +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,43 @@ return (int)error; } +Semaphore::Semaphore(uint value, uint max) { + _semaphore = ::CreateSemaphore(NULL, value, max, NULL); + + guarantee(_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); + + guarantee(ret != 0, err_msg("ReleaseSemaphore failed: %d", GetLastError())); +} + +void Semaphore::signal() { + signal(1); +} + +void Semaphore::wait() { + DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE); + guarantee(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed: %d", GetLastError())); +} + +bool Semaphore::trywait() { + Unimplemented(); + return false; +} + +bool Semaphore::timedwait(unsigned int sec, int nsec) { + Unimplemented(); + return false; +} + // 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