< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page
rev 47862 : imported patch 10.07.open.rebase_20171110.dcubed


3473                                  int* priority_ptr) {
3474   if (!UseThreadPriorities) {
3475     *priority_ptr = java_to_os_priority[NormPriority];
3476     return OS_OK;
3477   }
3478   int os_prio = GetThreadPriority(thread->osthread()->thread_handle());
3479   if (os_prio == THREAD_PRIORITY_ERROR_RETURN) {
3480     assert(false, "GetThreadPriority failed");
3481     return OS_ERR;
3482   }
3483   *priority_ptr = os_prio;
3484   return OS_OK;
3485 }
3486 
3487 
3488 // Hint to the underlying OS that a task switch would not be good.
3489 // Void return because it's a hint and can fail.
3490 void os::hint_no_preempt() {}
3491 
3492 void os::interrupt(Thread* thread) {
3493   assert(!thread->is_Java_thread() || Thread::current() == thread ||
3494          Threads_lock->owned_by_self(),
3495          "possibility of dangling Thread pointer");
3496 
3497   OSThread* osthread = thread->osthread();
3498   osthread->set_interrupted(true);
3499   // More than one thread can get here with the same value of osthread,
3500   // resulting in multiple notifications.  We do, however, want the store
3501   // to interrupted() to be visible to other threads before we post
3502   // the interrupt event.
3503   OrderAccess::release();
3504   SetEvent(osthread->interrupt_event());
3505   // For JSR166:  unpark after setting status
3506   if (thread->is_Java_thread()) {
3507     ((JavaThread*)thread)->parker()->unpark();
3508   }
3509 
3510   ParkEvent * ev = thread->_ParkEvent;
3511   if (ev != NULL) ev->unpark();
3512 }
3513 
3514 
3515 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3516   assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(),
3517          "possibility of dangling Thread pointer");
3518 
3519   OSThread* osthread = thread->osthread();
3520   // There is no synchronization between the setting of the interrupt
3521   // and it being cleared here. It is critical - see 6535709 - that
3522   // we only clear the interrupt state, and reset the interrupt event,
3523   // if we are going to report that we were indeed interrupted - else
3524   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3525   // depending on the timing. By checking thread interrupt event to see
3526   // if the thread gets real interrupt thus prevent spurious wakeup.
3527   bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0);
3528   if (interrupted && clear_interrupted) {
3529     osthread->set_interrupted(false);
3530     ResetEvent(osthread->interrupt_event());
3531   } // Otherwise leave the interrupted state alone
3532 
3533   return interrupted;
3534 }
3535 
3536 // GetCurrentThreadId() returns DWORD
3537 intx os::current_thread_id()  { return GetCurrentThreadId(); }




3473                                  int* priority_ptr) {
3474   if (!UseThreadPriorities) {
3475     *priority_ptr = java_to_os_priority[NormPriority];
3476     return OS_OK;
3477   }
3478   int os_prio = GetThreadPriority(thread->osthread()->thread_handle());
3479   if (os_prio == THREAD_PRIORITY_ERROR_RETURN) {
3480     assert(false, "GetThreadPriority failed");
3481     return OS_ERR;
3482   }
3483   *priority_ptr = os_prio;
3484   return OS_OK;
3485 }
3486 
3487 
3488 // Hint to the underlying OS that a task switch would not be good.
3489 // Void return because it's a hint and can fail.
3490 void os::hint_no_preempt() {}
3491 
3492 void os::interrupt(Thread* thread) {
3493   debug_only(Thread::check_for_dangling_thread_pointer(thread);)


3494 
3495   OSThread* osthread = thread->osthread();
3496   osthread->set_interrupted(true);
3497   // More than one thread can get here with the same value of osthread,
3498   // resulting in multiple notifications.  We do, however, want the store
3499   // to interrupted() to be visible to other threads before we post
3500   // the interrupt event.
3501   OrderAccess::release();
3502   SetEvent(osthread->interrupt_event());
3503   // For JSR166:  unpark after setting status
3504   if (thread->is_Java_thread()) {
3505     ((JavaThread*)thread)->parker()->unpark();
3506   }
3507 
3508   ParkEvent * ev = thread->_ParkEvent;
3509   if (ev != NULL) ev->unpark();
3510 }
3511 
3512 
3513 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3514   debug_only(Thread::check_for_dangling_thread_pointer(thread);)

3515 
3516   OSThread* osthread = thread->osthread();
3517   // There is no synchronization between the setting of the interrupt
3518   // and it being cleared here. It is critical - see 6535709 - that
3519   // we only clear the interrupt state, and reset the interrupt event,
3520   // if we are going to report that we were indeed interrupted - else
3521   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3522   // depending on the timing. By checking thread interrupt event to see
3523   // if the thread gets real interrupt thus prevent spurious wakeup.
3524   bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0);
3525   if (interrupted && clear_interrupted) {
3526     osthread->set_interrupted(false);
3527     ResetEvent(osthread->interrupt_event());
3528   } // Otherwise leave the interrupted state alone
3529 
3530   return interrupted;
3531 }
3532 
3533 // GetCurrentThreadId() returns DWORD
3534 intx os::current_thread_id()  { return GetCurrentThreadId(); }


< prev index next >