--- old/src/os/solaris/vm/os_solaris.cpp 2015-06-12 14:46:29.132160039 +0200 +++ new/src/os/solaris/vm/os_solaris.cpp 2015-06-12 14:46:28.980155071 +0200 @@ -67,6 +67,7 @@ #include "utilities/defaultStream.hpp" #include "utilities/events.hpp" #include "utilities/growableArray.hpp" +#include "utilities/semaphore.hpp" #include "utilities/vmError.hpp" // put OS-includes here @@ -2266,21 +2267,18 @@ return CAST_FROM_FN_PTR(void*, UserHandler); } -class Semaphore : public StackObj { - public: - Semaphore(); - ~Semaphore(); - void signal(); - void wait(); - bool trywait(); - bool timedwait(unsigned int sec, int nsec); - private: - sema_t _semaphore; -}; +static int sem_max_value = -1; +Semaphore::Semaphore(uint value, uint max) { + guarantee(value <= max, "value lower than max"); -Semaphore::Semaphore() { - sema_init(&_semaphore, 0, NULL, NULL); + static long sem_value_max = sysconf(_SC_SEM_VALUE_MAX); + guarantee(max == Semaphore::NoMaxCount || value <= sem_max_value, + err_msg("Max value: %u set higher than SEM_VALUE_MAX: %l", sem_value_max)); + + int ret = sema_init(&_semaphore, value, NULL, NULL); + + guarantee(ret == 0, "Failed to initialize semaphore"); } Semaphore::~Semaphore() { @@ -2288,11 +2286,26 @@ } void Semaphore::signal() { - sema_post(&_semaphore); + int ret = sema_post(&_semaphore); + + assert(ret == 0, err_msg("Semaphore signal failed: %d", errno)); +} + +void Semaphore::signal(uint count) { + for (uint i = 0; i < count; i++) { + signal(); + } } void Semaphore::wait() { - sema_wait(&_semaphore); + int ret; + + do { + ret = sema_wait(&_semaphore); + // Retry if the wait was interrupted by a signal. + } while (errno == EINTR); + + assert(ret == 0, err_msg("Semaphore wait failed: %d", errno)); } bool Semaphore::trywait() {