< prev index next >
src/os/linux/vm/os_linux.cpp
Print this page
@@ -67,11 +67,10 @@
#include "utilities/defaultStream.hpp"
#include "utilities/events.hpp"
#include "utilities/elfFile.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/macros.hpp"
-#include "utilities/semaphore.hpp"
#include "utilities/vmError.hpp"
// put OS-includes here
# include <sys/types.h>
# include <sys/mman.h>
@@ -2392,45 +2391,15 @@
void* os::user_handler() {
return CAST_FROM_FN_PTR(void*, UserHandler);
}
-Semaphore::Semaphore(uint value, uint max) {
- guarantee(value <= max, "value lower than max");
- guarantee(max == Semaphore::NoMaxCount || max <= SEM_VALUE_MAX, "Max value set too high");
-
- int ret = sem_init(&_semaphore, 0, value);
- guarantee(ret == 0, "Failed to initialize semaphore");
-}
-
-Semaphore::~Semaphore() {
- sem_destroy(&_semaphore);
-}
-
-void Semaphore::signal() {
- int ret = sem_post(&_semaphore);
- guarantee(ret == 0, err_msg("sem_post failed: %d", ret));
-}
-
-void Semaphore::signal(uint count) {
- for (uint i = 0; i < count; i++) {
- signal();
- }
-}
-
-void Semaphore::wait() {
- while (sem_wait(&_semaphore) == -1 && errno == EINTR) {
- // Retry if the wait was interrupted by a signal.
- }
-}
-
-bool Semaphore::trywait() {
- return sem_trywait(&_semaphore) == 0;
-}
-
-bool Semaphore::timedwait(unsigned int sec, int nsec) {
+class LinuxSemaphore : public os::PosixSemaphore {
+ public:
+ LinuxSemaphore(uint value = 0) : os::PosixSemaphore(value) {}
+ bool 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) {
@@ -2443,23 +2412,13 @@
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;
- }
+ return os::PosixSemaphore::timedwait(ts);
}
-}
+};
extern "C" {
typedef void (*sa_handler_t)(int);
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
}
@@ -2494,11 +2453,11 @@
// 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;
+static LinuxSemaphore sr_semaphore;
void os::signal_init_pd() {
// Initialize signal structures
::memset((void*)pending_signals, 0, sizeof(pending_signals));
< prev index next >