--- old/src/os/bsd/vm/os_bsd.cpp 2015-06-25 18:20:28.509432006 +0200 +++ new/src/os/bsd/vm/os_bsd.cpp 2015-06-25 18:20:28.385427783 +0200 @@ -1968,7 +1968,7 @@ } } -OSXSemaphore::OSXSemaphore(uint value) : _semaphore(0) { +OSXSemaphore::OSXSemaphore(uint value) { kern_return_t ret = SEM_INIT(_semaphore, value); guarantee(ret == KERN_SUCCESS, err_msg("Failed to create semaphore: %s", sem_init_strerror(ret))); --- old/src/os/bsd/vm/semaphore_bsd.hpp 2015-06-25 18:20:28.857443857 +0200 +++ new/src/os/bsd/vm/semaphore_bsd.hpp 2015-06-25 18:20:28.705438681 +0200 @@ -25,14 +25,14 @@ #ifndef OS_BSD_VM_SEMAPHORE_BSD_HPP #define OS_BSD_VM_SEMAPHORE_BSD_HPP -#include "memory/allocation.hpp" - -#include - #ifndef __APPLE__ +// Use POSIX semaphores. # include "semaphore_posix.hpp" + #else // OS X doesn't support unamed POSIX semaphores, so the implementation in os_posix.cpp can't be used. +# include "memory/allocation.hpp" +# include class OSXSemaphore : public CHeapObj{ semaphore_t _semaphore; --- old/src/os/posix/vm/os_posix.cpp 2015-06-25 18:20:29.113452575 +0200 +++ new/src/os/posix/vm/os_posix.cpp 2015-06-25 18:20:28.965447535 +0200 @@ -1050,18 +1050,24 @@ void PosixSemaphore::wait() { int ret; - while ((ret = sem_wait(&_semaphore)) == -1 && errno == EINTR) { - // Retry if the wait was interrupted by a signal. - } + + do { + ret = sem_wait(&_semaphore); + } while (ret != 0 && errno == EINTR); + assert_with_errno(ret == 0, "sem_wait failed"); } bool PosixSemaphore::trywait() { - bool succeeded = sem_trywait(&_semaphore) == 0; + int ret; + + do { + ret = sem_trywait(&_semaphore); + } while (ret != 0 && errno == EINTR); - assert_with_errno(succeeded || errno == EAGAIN, "trywait failed"); + assert_with_errno(ret == 0 || errno == EAGAIN, "trywait failed"); - return succeeded; + return ret == 0; } bool PosixSemaphore::timedwait(const struct timespec ts) { --- old/src/os/windows/vm/os_windows.cpp 2015-06-25 18:20:29.377461565 +0200 +++ new/src/os/windows/vm/os_windows.cpp 2015-06-25 18:20:29.237456797 +0200 @@ -1903,9 +1903,7 @@ } WindowsSemaphore::~WindowsSemaphore() { - if (_semaphore != NULL) { - ::CloseHandle(_semaphore); - } + ::CloseHandle(_semaphore); } void WindowsSemaphore::signal(uint count) { --- old/src/os/windows/vm/semaphore_windows.hpp 2015-06-25 18:20:29.693472326 +0200 +++ new/src/os/windows/vm/semaphore_windows.hpp 2015-06-25 18:20:29.561467831 +0200 @@ -27,7 +27,7 @@ #include "memory/allocation.hpp" -#include +#include class WindowsSemaphore : public CHeapObj { HANDLE _semaphore; @@ -40,7 +40,7 @@ WindowsSemaphore(uint value = 0); ~WindowsSemaphore(); - void signal(uint count = 0); + void signal(uint count = 1); void wait(); }; --- old/src/share/vm/runtime/semaphore.cpp 2015-06-25 18:20:29.913479818 +0200 +++ new/src/share/vm/runtime/semaphore.cpp 2015-06-25 18:20:29.785475459 +0200 @@ -26,12 +26,6 @@ #include "utilities/debug.hpp" #include "runtime/semaphore.hpp" -// Implements the limited, platform independent Semaphore API. -Semaphore::Semaphore(uint value) : _impl(value) {} -Semaphore::~Semaphore() {} -void Semaphore::signal(uint count) { _impl.signal(count); } -void Semaphore::wait() { _impl.wait(); } - /////////////// Unit tests /////////////// #ifndef PRODUCT --- old/src/share/vm/runtime/semaphore.hpp 2015-06-25 18:20:30.149487855 +0200 +++ new/src/share/vm/runtime/semaphore.hpp 2015-06-25 18:20:30.013483224 +0200 @@ -37,6 +37,7 @@ # error "No semaphore implementation provided for this OS" #endif +// Implements the limited, platform independent Semaphore API. class Semaphore : public CHeapObj { private: // Prevent copying and assignment of Semaphore instances. @@ -47,12 +48,12 @@ SemaphoreImpl _impl; public: - Semaphore(uint value = 0); - ~Semaphore(); + Semaphore(uint value = 0) : _impl(value) {} + ~Semaphore() {} - void signal(uint count = 1); + void signal(uint count = 1) { _impl.signal(count); } - void wait(); + void wait() { _impl.wait(); } };