--- old/src/os/solaris/vm/os_solaris.cpp 2015-06-17 19:47:27.560485391 +0200 +++ new/src/os/solaris/vm/os_solaris.cpp 2015-06-17 19:47:27.396479835 +0200 @@ -2266,56 +2266,17 @@ return CAST_FROM_FN_PTR(void*, UserHandler); } -class Semaphore : public StackObj { +class SolarisSemaphore : public os::PosixSemaphore { public: - Semaphore(); - ~Semaphore(); - void signal(); - void wait(); - bool trywait(); - bool timedwait(unsigned int sec, int nsec); - private: - sema_t _semaphore; -}; - - -Semaphore::Semaphore() { - sema_init(&_semaphore, 0, NULL, NULL); -} - -Semaphore::~Semaphore() { - sema_destroy(&_semaphore); -} - -void Semaphore::signal() { - sema_post(&_semaphore); -} - -void Semaphore::wait() { - sema_wait(&_semaphore); -} - -bool Semaphore::trywait() { - return sema_trywait(&_semaphore) == 0; -} + SolarisSemaphore(uint value = 0) : os::PosixSemaphore(value) {} -bool Semaphore::timedwait(unsigned int sec, int nsec) { - struct timespec ts; - unpackTime(&ts, false, (sec * NANOSECS_PER_SEC) + nsec); + bool timedwait(unsigned int sec, int nsec) { + struct timespec ts; + unpackTime(&ts, false, (sec * NANOSECS_PER_SEC) + nsec); - while (1) { - int result = sema_timedwait(&_semaphore, &ts); - if (result == 0) { - return true; - } else if (errno == EINTR) { - continue; - } else if (errno == ETIME) { - return false; - } else { - return false; - } + return os::PosixSemaphore::timedwait(ts); } -} +}; extern "C" { typedef void (*sa_handler_t)(int); @@ -3714,7 +3675,7 @@ osthread->set_ucontext(context); } -static Semaphore sr_semaphore; +static SolarisSemaphore sr_semaphore; void os::Solaris::SR_handler(Thread* thread, ucontext_t* uc) { // Save and restore errno to avoid confusing native code with EINTR