< prev index next >
src/hotspot/os/solaris/os_solaris.cpp
Print this page
@@ -2060,11 +2060,11 @@
void* os::user_handler() {
return CAST_FROM_FN_PTR(void*, UserHandler);
}
-struct timespec PosixSemaphore::create_timespec(unsigned int sec, int nsec) {
+static struct timespec create_timespec(unsigned int sec, int nsec) {
struct timespec ts;
unpackTime(&ts, false, (sec * NANOSECS_PER_SEC) + nsec);
return ts;
}
@@ -2098,11 +2098,11 @@
// a counter for each possible signal value
static int Sigexit = 0;
static jint *pending_signals = NULL;
static int *preinstalled_sigs = NULL;
static struct sigaction *chainedsigactions = NULL;
-static sema_t sig_sem;
+static Semaphore* sig_sem = NULL;
typedef int (*version_getting_t)();
version_getting_t os::Solaris::get_libjsig_version = NULL;
int os::sigexitnum_pd() {
assert(Sigexit > 0, "signal memory not yet initialized");
@@ -2113,10 +2113,11 @@
// Initialize signal structures
Maxsignum = SIGRTMAX;
Sigexit = Maxsignum+1;
assert(Maxsignum >0, "Unable to obtain max signal number");
+ // Initialize signal structures
// pending_signals has one int per signal
// The additional signal is for SIGEXIT - exit signal to signal_thread
pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1), mtInternal);
memset(pending_signals, 0, (sizeof(jint) * (Sigexit+1)));
@@ -2130,22 +2131,23 @@
ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
}
void os::signal_init_pd() {
- int ret;
-
- ret = ::sema_init(&sig_sem, 0, NULL, NULL);
- assert(ret == 0, "sema_init() failed");
+ // Initialize signal semaphore
+ sig_sem = new Semaphore();
}
-void os::signal_notify(int signal_number) {
- int ret;
-
- Atomic::inc(&pending_signals[signal_number]);
- ret = ::sema_post(&sig_sem);
- assert(ret == 0, "sema_post() failed");
+void os::signal_notify(int sig) {
+ if (sig_sem != NULL) {
+ Atomic::inc(&pending_signals[sig]);
+ sig_sem->signal();
+ } else {
+ // Signal thread is not created with ReduceSignalUsage and signal_init_pd
+ // initialization isn't called.
+ assert(ReduceSignalUsage, "signal semaphore should be created");
+ }
}
static int check_pending_signals(bool wait_for_signal) {
int ret;
while (true) {
@@ -2162,35 +2164,27 @@
ThreadBlockInVM tbivm(thread);
bool threadIsSuspended;
do {
thread->set_suspend_equivalent();
- // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
- while ((ret = ::sema_wait(&sig_sem)) == EINTR)
- ;
- assert(ret == 0, "sema_wait() failed");
+ sig_sem->wait();
// were we externally suspended while we were waiting?
threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
if (threadIsSuspended) {
// The semaphore has been incremented, but while we were waiting
// another thread suspended us. We don't want to continue running
// while suspended because that would surprise the thread that
// suspended us.
- ret = ::sema_post(&sig_sem);
- assert(ret == 0, "sema_post() failed");
+ sig_sem->signal();
thread->java_suspend_self();
}
} while (threadIsSuspended);
}
}
-int os::signal_lookup() {
- return check_pending_signals(false);
-}
-
int os::signal_wait() {
return check_pending_signals(true);
}
////////////////////////////////////////////////////////////////////////////////
@@ -3597,11 +3591,11 @@
ShouldNotReachHere();
}
// managed to send the signal and switch to SUSPEND_REQUEST, now wait for SUSPENDED
while (true) {
- if (sr_semaphore.timedwait(0, 2000 * NANOSECS_PER_MILLISEC)) {
+ if (sr_semaphore.timedwait(create_timespec(0, 2000 * NANOSECS_PER_MILLISEC))) {
break;
} else {
// timeout
os::SuspendResume::State cancelled = osthread->sr.cancel_suspend();
if (cancelled == os::SuspendResume::SR_RUNNING) {
@@ -3631,11 +3625,11 @@
return;
}
while (true) {
if (sr_notify(osthread) == 0) {
- if (sr_semaphore.timedwait(0, 2 * NANOSECS_PER_MILLISEC)) {
+ if (sr_semaphore.timedwait(create_timespec(0, 2 * NANOSECS_PER_MILLISEC))) {
if (osthread->sr.is_running()) {
return;
}
}
} else {
< prev index next >