< prev index next >
src/os/solaris/vm/os_solaris.cpp
Print this page
*** 65,74 ****
--- 65,75 ----
#include "services/runtimeService.hpp"
#include "utilities/decoder.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/events.hpp"
#include "utilities/growableArray.hpp"
+ #include "utilities/semaphore.hpp"
#include "utilities/vmError.hpp"
// put OS-includes here
# include <dlfcn.h>
# include <errno.h>
*** 2264,2300 ****
void* os::user_handler() {
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;
! };
! 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;
}
--- 2265,2313 ----
void* os::user_handler() {
return CAST_FROM_FN_PTR(void*, UserHandler);
}
! static int sem_max_value = -1;
+ Semaphore::Semaphore(uint value, uint max) {
+ guarantee(value <= max, "value lower than max");
! 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() {
sema_destroy(&_semaphore);
}
void Semaphore::signal() {
! 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() {
! 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() {
return sema_trywait(&_semaphore) == 0;
}
< prev index next >