2735
2736 // Initialize signal semaphore
2737 sig_sem = new Semaphore();
2738 }
2739
2740 void os::signal_notify(int sig) {
2741 if (sig_sem != NULL) {
2742 Atomic::inc(&pending_signals[sig]);
2743 sig_sem->signal();
2744 } else {
2745 // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
2746 // initialization isn't called.
2747 assert(ReduceSignalUsage, "signal semaphore should be created");
2748 }
2749 }
2750
2751 static int check_pending_signals() {
2752 for (;;) {
2753 for (int i = 0; i < NSIG + 1; i++) {
2754 jint n = pending_signals[i];
2755 if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2756 return i;
2757 }
2758 }
2759 JavaThread *thread = JavaThread::current();
2760 ThreadBlockInVM tbivm(thread);
2761
2762 bool threadIsSuspended;
2763 do {
2764 thread->set_suspend_equivalent();
2765 // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
2766 sig_sem->wait();
2767
2768 // were we externally suspended while we were waiting?
2769 threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
2770 if (threadIsSuspended) {
2771 // The semaphore has been incremented, but while we were waiting
2772 // another thread suspended us. We don't want to continue running
2773 // while suspended because that would surprise the thread that
2774 // suspended us.
2775 sig_sem->signal();
|
2735
2736 // Initialize signal semaphore
2737 sig_sem = new Semaphore();
2738 }
2739
2740 void os::signal_notify(int sig) {
2741 if (sig_sem != NULL) {
2742 Atomic::inc(&pending_signals[sig]);
2743 sig_sem->signal();
2744 } else {
2745 // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
2746 // initialization isn't called.
2747 assert(ReduceSignalUsage, "signal semaphore should be created");
2748 }
2749 }
2750
2751 static int check_pending_signals() {
2752 for (;;) {
2753 for (int i = 0; i < NSIG + 1; i++) {
2754 jint n = pending_signals[i];
2755 if (n > 0 && n == Atomic::cmpxchg(&pending_signals[i], n, n - 1)) {
2756 return i;
2757 }
2758 }
2759 JavaThread *thread = JavaThread::current();
2760 ThreadBlockInVM tbivm(thread);
2761
2762 bool threadIsSuspended;
2763 do {
2764 thread->set_suspend_equivalent();
2765 // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
2766 sig_sem->wait();
2767
2768 // were we externally suspended while we were waiting?
2769 threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
2770 if (threadIsSuspended) {
2771 // The semaphore has been incremented, but while we were waiting
2772 // another thread suspended us. We don't want to continue running
2773 // while suspended because that would surprise the thread that
2774 // suspended us.
2775 sig_sem->signal();
|