< prev index next >

src/hotspot/os/posix/os_posix.cpp

Print this page

        

*** 638,702 **** assert(ms < MILLIUNITS, "Un-interruptable sleep, short time use only"); os::naked_short_nanosleep(ms * (NANOUNITS / MILLIUNITS)); return; } - //////////////////////////////////////////////////////////////////////////////// - // interrupt support - - void os::interrupt(Thread* thread) { - debug_only(Thread::check_for_dangling_thread_pointer(thread);) - assert(thread->is_Java_thread(), "invariant"); - JavaThread* jt = (JavaThread*) thread; - OSThread* osthread = thread->osthread(); - - if (!osthread->interrupted()) { - osthread->set_interrupted(true); - // More than one thread can get here with the same value of osthread, - // resulting in multiple notifications. We do, however, want the store - // to interrupted() to be visible to other threads before we execute unpark(). - OrderAccess::fence(); - ParkEvent * const slp = jt->_SleepEvent ; - if (slp != NULL) slp->unpark() ; - } - - // For JSR166. Unpark even if interrupt status already was set - jt->parker()->unpark(); - - ParkEvent * ev = thread->_ParkEvent ; - if (ev != NULL) ev->unpark() ; - } - - bool os::is_interrupted(Thread* thread, bool clear_interrupted) { - debug_only(Thread::check_for_dangling_thread_pointer(thread);) - - OSThread* osthread = thread->osthread(); - - bool interrupted = osthread->interrupted(); - - // NOTE that since there is no "lock" around the interrupt and - // is_interrupted operations, there is the possibility that the - // interrupted flag (in osThread) will be "false" but that the - // low-level events will be in the signaled state. This is - // intentional. The effect of this is that Object.wait() and - // LockSupport.park() will appear to have a spurious wakeup, which - // is allowed and not harmful, and the possibility is so rare that - // it is not worth the added complexity to add yet another lock. - // For the sleep event an explicit reset is performed on entry - // to JavaThread::sleep, so there is no early return. It has also been - // recommended not to put the interrupted flag into the "event" - // structure because it hides the issue. - if (interrupted && clear_interrupted) { - osthread->set_interrupted(false); - // consider thread->_SleepEvent->reset() ... optional optimization - } - - return interrupted; - } - - - static const struct { int sig; const char* name; } g_signal_info[] = { --- 638,647 ----
*** 2105,2115 **** assert(thread->is_Java_thread(), "Must be JavaThread"); JavaThread *jt = (JavaThread *)thread; // Optional optimization -- avoid state transitions if there's // an interrupt pending. ! if (Thread::is_interrupted(thread, false)) { return; } // Next, demultiplex/decode time arguments struct timespec absTime; --- 2050,2060 ---- assert(thread->is_Java_thread(), "Must be JavaThread"); JavaThread *jt = (JavaThread *)thread; // Optional optimization -- avoid state transitions if there's // an interrupt pending. ! if (jt->is_interrupted(false)) { return; } // Next, demultiplex/decode time arguments struct timespec absTime;
*** 2128,2138 **** // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock. ThreadBlockInVM tbivm(jt); // Don't wait if cannot get lock since interference arises from // unparking. Also re-check interrupt before trying wait. ! if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) { return; } int status; --- 2073,2083 ---- // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock. ThreadBlockInVM tbivm(jt); // Don't wait if cannot get lock since interference arises from // unparking. Also re-check interrupt before trying wait. ! if (jt->is_interrupted(false) || pthread_mutex_trylock(_mutex) != 0) { return; } int status;
< prev index next >