3573 // Void return because it's a hint and can fail.
3574 void os::hint_no_preempt() {
3575 schedctl_start(schedctl_init());
3576 }
3577
3578 static void resume_clear_context(OSThread *osthread) {
3579 osthread->set_ucontext(NULL);
3580 }
3581
3582 static void suspend_save_context(OSThread *osthread, ucontext_t* context) {
3583 osthread->set_ucontext(context);
3584 }
3585
3586 static PosixSemaphore sr_semaphore;
3587
3588 void os::Solaris::SR_handler(Thread* thread, ucontext_t* uc) {
3589 // Save and restore errno to avoid confusing native code with EINTR
3590 // after sigsuspend.
3591 int old_errno = errno;
3592
3593 OSThread* osthread = thread->osthread();
3594 assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread");
3595
3596 os::SuspendResume::State current = osthread->sr.state();
3597 if (current == os::SuspendResume::SR_SUSPEND_REQUEST) {
3598 suspend_save_context(osthread, uc);
3599
3600 // attempt to switch the state, we assume we had a SUSPEND_REQUEST
3601 os::SuspendResume::State state = osthread->sr.suspended();
3602 if (state == os::SuspendResume::SR_SUSPENDED) {
3603 sigset_t suspend_set; // signals for sigsuspend()
3604
3605 // get current set of blocked signals and unblock resume signal
3606 pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
3607 sigdelset(&suspend_set, os::Solaris::SIGasync());
3608
3609 sr_semaphore.signal();
3610 // wait here until we are resumed
3611 while (1) {
3612 sigsuspend(&suspend_set);
3613
3614 os::SuspendResume::State result = osthread->sr.running();
|
3573 // Void return because it's a hint and can fail.
3574 void os::hint_no_preempt() {
3575 schedctl_start(schedctl_init());
3576 }
3577
3578 static void resume_clear_context(OSThread *osthread) {
3579 osthread->set_ucontext(NULL);
3580 }
3581
3582 static void suspend_save_context(OSThread *osthread, ucontext_t* context) {
3583 osthread->set_ucontext(context);
3584 }
3585
3586 static PosixSemaphore sr_semaphore;
3587
3588 void os::Solaris::SR_handler(Thread* thread, ucontext_t* uc) {
3589 // Save and restore errno to avoid confusing native code with EINTR
3590 // after sigsuspend.
3591 int old_errno = errno;
3592
3593 assert(thread == Thread::current_or_null_safe(), "Incorrect thread context");
3594 assert(thread != NULL, "Missing current thread in SR_handler");
3595
3596 // On some systems we have seen signal delivery get "stuck" until the signal
3597 // mask is changed as part of thread termination. Check the current thread
3598 // has not already terminated (via SR_lock()) - else the following assertion
3599 // will fail because the thread is no longer a JavaThread as the ~JavaThread
3600 // destructor has completed.
3601
3602 if (thread->SR_lock() == NULL)
3603 return;
3604
3605 assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread");
3606
3607 OSThread* osthread = thread->osthread();
3608
3609 os::SuspendResume::State current = osthread->sr.state();
3610 if (current == os::SuspendResume::SR_SUSPEND_REQUEST) {
3611 suspend_save_context(osthread, uc);
3612
3613 // attempt to switch the state, we assume we had a SUSPEND_REQUEST
3614 os::SuspendResume::State state = osthread->sr.suspended();
3615 if (state == os::SuspendResume::SR_SUSPENDED) {
3616 sigset_t suspend_set; // signals for sigsuspend()
3617
3618 // get current set of blocked signals and unblock resume signal
3619 pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
3620 sigdelset(&suspend_set, os::Solaris::SIGasync());
3621
3622 sr_semaphore.signal();
3623 // wait here until we are resumed
3624 while (1) {
3625 sigsuspend(&suspend_set);
3626
3627 os::SuspendResume::State result = osthread->sr.running();
|