< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page




3580   return ret ? OS_OK : OS_ERR;
3581 }
3582 
3583 OSReturn os::get_native_priority(const Thread* const thread,
3584                                  int* priority_ptr) {
3585   if (!UseThreadPriorities) {
3586     *priority_ptr = java_to_os_priority[NormPriority];
3587     return OS_OK;
3588   }
3589   int os_prio = GetThreadPriority(thread->osthread()->thread_handle());
3590   if (os_prio == THREAD_PRIORITY_ERROR_RETURN) {
3591     assert(false, "GetThreadPriority failed");
3592     return OS_ERR;
3593   }
3594   *priority_ptr = os_prio;
3595   return OS_OK;
3596 }
3597 
3598 void os::interrupt(Thread* thread) {
3599   debug_only(Thread::check_for_dangling_thread_pointer(thread);)
3600 

3601   OSThread* osthread = thread->osthread();
3602   osthread->set_interrupted(true);
3603   // More than one thread can get here with the same value of osthread,
3604   // resulting in multiple notifications.  We do, however, want the store
3605   // to interrupted() to be visible to other threads before we post
3606   // the interrupt event.
3607   OrderAccess::release();
3608   SetEvent(osthread->interrupt_event());
3609   // For JSR166:  unpark after setting status
3610   if (thread->is_Java_thread()) {
3611     ((JavaThread*)thread)->parker()->unpark();
3612   }
3613 
3614   ParkEvent * ev = thread->_ParkEvent;
3615   if (ev != NULL) ev->unpark();
3616 
3617   ev = thread->_SleepEvent;
3618   if (ev != NULL) ev->unpark();
3619 }
3620 
3621 
3622 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3623   debug_only(Thread::check_for_dangling_thread_pointer(thread);)
3624 
3625   OSThread* osthread = thread->osthread();
3626   // There is no synchronization between the setting of the interrupt
3627   // and it being cleared here. It is critical - see 6535709 - that
3628   // we only clear the interrupt state, and reset the interrupt event,
3629   // if we are going to report that we were indeed interrupted - else
3630   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3631   // depending on the timing. By checking thread interrupt event to see
3632   // if the thread gets real interrupt thus prevent spurious wakeup.
3633   bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0);
3634   if (interrupted && clear_interrupted) {
3635     osthread->set_interrupted(false);
3636     ResetEvent(osthread->interrupt_event());
3637   } // Otherwise leave the interrupted state alone




3580   return ret ? OS_OK : OS_ERR;
3581 }
3582 
3583 OSReturn os::get_native_priority(const Thread* const thread,
3584                                  int* priority_ptr) {
3585   if (!UseThreadPriorities) {
3586     *priority_ptr = java_to_os_priority[NormPriority];
3587     return OS_OK;
3588   }
3589   int os_prio = GetThreadPriority(thread->osthread()->thread_handle());
3590   if (os_prio == THREAD_PRIORITY_ERROR_RETURN) {
3591     assert(false, "GetThreadPriority failed");
3592     return OS_ERR;
3593   }
3594   *priority_ptr = os_prio;
3595   return OS_OK;
3596 }
3597 
3598 void os::interrupt(Thread* thread) {
3599   debug_only(Thread::check_for_dangling_thread_pointer(thread);)
3600   assert(thread->is_Java_thread(), "invariant");
3601   JavaThread* jt = (JavaThread*) thread;
3602   OSThread* osthread = thread->osthread();
3603   osthread->set_interrupted(true);
3604   // More than one thread can get here with the same value of osthread,
3605   // resulting in multiple notifications.  We do, however, want the store
3606   // to interrupted() to be visible to other threads before we post
3607   // the interrupt event.
3608   OrderAccess::release();
3609   SetEvent(osthread->interrupt_event());
3610   // For JSR166:  unpark after setting status
3611   jt->parker()->unpark();


3612 
3613   ParkEvent * ev = thread->_ParkEvent;
3614   if (ev != NULL) ev->unpark();
3615 
3616   ev = jt->_SleepEvent;
3617   if (ev != NULL) ev->unpark();
3618 }
3619 
3620 
3621 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3622   debug_only(Thread::check_for_dangling_thread_pointer(thread);)
3623 
3624   OSThread* osthread = thread->osthread();
3625   // There is no synchronization between the setting of the interrupt
3626   // and it being cleared here. It is critical - see 6535709 - that
3627   // we only clear the interrupt state, and reset the interrupt event,
3628   // if we are going to report that we were indeed interrupted - else
3629   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3630   // depending on the timing. By checking thread interrupt event to see
3631   // if the thread gets real interrupt thus prevent spurious wakeup.
3632   bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0);
3633   if (interrupted && clear_interrupted) {
3634     osthread->set_interrupted(false);
3635     ResetEvent(osthread->interrupt_event());
3636   } // Otherwise leave the interrupted state alone


< prev index next >