< prev index next >
src/os/linux/vm/os_linux.cpp
Print this page
*** 58,67 ****
--- 58,68 ----
#include "runtime/statSampler.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/thread.inline.hpp"
#include "runtime/threadCritical.hpp"
#include "runtime/timer.hpp"
+ #include "semaphore_posix.hpp"
#include "services/attachListener.hpp"
#include "services/memTracker.hpp"
#include "services/runtimeService.hpp"
#include "utilities/decoder.hpp"
#include "utilities/defaultStream.hpp"
*** 2391,2434 ****
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:
! sem_t _semaphore;
! };
!
! Semaphore::Semaphore() {
! sem_init(&_semaphore, 0, 0);
! }
!
! Semaphore::~Semaphore() {
! sem_destroy(&_semaphore);
! }
!
! void Semaphore::signal() {
! sem_post(&_semaphore);
! }
!
! void Semaphore::wait() {
! sem_wait(&_semaphore);
! }
!
! bool Semaphore::trywait() {
! return sem_trywait(&_semaphore) == 0;
! }
!
! bool Semaphore::timedwait(unsigned int sec, int nsec) {
!
struct timespec ts;
// Semaphore's are always associated with CLOCK_REALTIME
os::Linux::clock_gettime(CLOCK_REALTIME, &ts);
// see unpackTime for discussion on overflow checking
if (sec >= MAX_SECS) {
--- 2392,2402 ----
void* os::user_handler() {
return CAST_FROM_FN_PTR(void*, UserHandler);
}
! struct timespec PosixSemaphore::create_timespec(unsigned int sec, int nsec) {
struct timespec ts;
// Semaphore's are always associated with CLOCK_REALTIME
os::Linux::clock_gettime(CLOCK_REALTIME, &ts);
// see unpackTime for discussion on overflow checking
if (sec >= MAX_SECS) {
*** 2441,2462 ****
ts.tv_nsec -= NANOSECS_PER_SEC;
++ts.tv_sec; // note: this must be <= max_secs
}
}
! while (1) {
! int result = sem_timedwait(&_semaphore, &ts);
! if (result == 0) {
! return true;
! } else if (errno == EINTR) {
! continue;
! } else if (errno == ETIMEDOUT) {
! return false;
! } else {
! return false;
! }
! }
}
extern "C" {
typedef void (*sa_handler_t)(int);
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
--- 2409,2419 ----
ts.tv_nsec -= NANOSECS_PER_SEC;
++ts.tv_sec; // note: this must be <= max_secs
}
}
! return ts;
}
extern "C" {
typedef void (*sa_handler_t)(int);
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
*** 2492,2502 ****
// a counter for each possible signal value
static volatile jint pending_signals[NSIG+1] = { 0 };
// Linux(POSIX) specific hand shaking semaphore.
static sem_t sig_sem;
! static Semaphore sr_semaphore;
void os::signal_init_pd() {
// Initialize signal structures
::memset((void*)pending_signals, 0, sizeof(pending_signals));
--- 2449,2459 ----
// a counter for each possible signal value
static volatile jint pending_signals[NSIG+1] = { 0 };
// Linux(POSIX) specific hand shaking semaphore.
static sem_t sig_sem;
! static PosixSemaphore sr_semaphore;
void os::signal_init_pd() {
// Initialize signal structures
::memset((void*)pending_signals, 0, sizeof(pending_signals));
< prev index next >