610 if (interrupt_event == NULL) { |
610 if (interrupt_event == NULL) { |
611 delete osthread; |
611 delete osthread; |
612 return false; |
612 return false; |
613 } |
613 } |
614 osthread->set_interrupt_event(interrupt_event); |
614 osthread->set_interrupt_event(interrupt_event); |
615 osthread->set_interrupted(false); |
615 // We don't call set_interrupted(false) as it will trip the assert in there |
|
616 // as we are not operating on the current thread. We don't need to call it |
|
617 // because the initial state is already correct. |
616 |
618 |
617 thread->set_osthread(osthread); |
619 thread->set_osthread(osthread); |
618 |
620 |
619 if (stack_size == 0) { |
621 if (stack_size == 0) { |
620 switch (thr_type) { |
622 switch (thr_type) { |
712 // but we can only really operate on the current thread. |
713 // but we can only really operate on the current thread. |
713 assert(Thread::current()->osthread() == osthread, |
714 assert(Thread::current()->osthread() == osthread, |
714 "os::free_thread but not current thread"); |
715 "os::free_thread but not current thread"); |
715 |
716 |
716 CloseHandle(osthread->thread_handle()); |
717 CloseHandle(osthread->thread_handle()); |
717 CloseHandle(osthread->interrupt_event()); |
|
718 delete osthread; |
718 delete osthread; |
719 } |
719 } |
720 |
720 |
721 static jlong first_filetime; |
721 static jlong first_filetime; |
722 static jlong initial_performance_count; |
722 static jlong initial_performance_count; |
3483 // >1: Thread is still suspended. |
3483 // >1: Thread is still suspended. |
3484 assert(ret != SYS_THREAD_ERROR, "StartThread failed"); // should propagate back |
3484 assert(ret != SYS_THREAD_ERROR, "StartThread failed"); // should propagate back |
3485 } |
3485 } |
3486 |
3486 |
3487 |
3487 |
3488 |
|
3489 // Short sleep, direct OS call. |
3488 // Short sleep, direct OS call. |
3490 // |
3489 // |
3491 // ms = 0, means allow others (if any) to run. |
3490 // ms = 0, means allow others (if any) to run. |
3492 // |
3491 // |
3493 void os::naked_short_sleep(jlong ms) { |
3492 void os::naked_short_sleep(jlong ms) { |
3589 assert(false, "GetThreadPriority failed"); |
3588 assert(false, "GetThreadPriority failed"); |
3590 return OS_ERR; |
3589 return OS_ERR; |
3591 } |
3590 } |
3592 *priority_ptr = os_prio; |
3591 *priority_ptr = os_prio; |
3593 return OS_OK; |
3592 return OS_OK; |
3594 } |
|
3595 |
|
3596 void os::interrupt(Thread* thread) { |
|
3597 debug_only(Thread::check_for_dangling_thread_pointer(thread);) |
|
3598 assert(thread->is_Java_thread(), "invariant"); |
|
3599 JavaThread* jt = (JavaThread*) thread; |
|
3600 OSThread* osthread = thread->osthread(); |
|
3601 osthread->set_interrupted(true); |
|
3602 // More than one thread can get here with the same value of osthread, |
|
3603 // resulting in multiple notifications. We do, however, want the store |
|
3604 // to interrupted() to be visible to other threads before we post |
|
3605 // the interrupt event. |
|
3606 OrderAccess::release(); |
|
3607 SetEvent(osthread->interrupt_event()); |
|
3608 // For JSR166: unpark after setting status |
|
3609 jt->parker()->unpark(); |
|
3610 |
|
3611 ParkEvent * ev = thread->_ParkEvent; |
|
3612 if (ev != NULL) ev->unpark(); |
|
3613 |
|
3614 ev = jt->_SleepEvent; |
|
3615 if (ev != NULL) ev->unpark(); |
|
3616 } |
|
3617 |
|
3618 |
|
3619 bool os::is_interrupted(Thread* thread, bool clear_interrupted) { |
|
3620 debug_only(Thread::check_for_dangling_thread_pointer(thread);) |
|
3621 |
|
3622 OSThread* osthread = thread->osthread(); |
|
3623 // There is no synchronization between the setting of the interrupt |
|
3624 // and it being cleared here. It is critical - see 6535709 - that |
|
3625 // we only clear the interrupt state, and reset the interrupt event, |
|
3626 // if we are going to report that we were indeed interrupted - else |
|
3627 // an interrupt can be "lost", leading to spurious wakeups or lost wakeups |
|
3628 // depending on the timing. By checking thread interrupt event to see |
|
3629 // if the thread gets real interrupt thus prevent spurious wakeup. |
|
3630 bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0); |
|
3631 if (interrupted && clear_interrupted) { |
|
3632 osthread->set_interrupted(false); |
|
3633 ResetEvent(osthread->interrupt_event()); |
|
3634 } // Otherwise leave the interrupted state alone |
|
3635 |
|
3636 return interrupted; |
|
3637 } |
3593 } |
3638 |
3594 |
3639 // GetCurrentThreadId() returns DWORD |
3595 // GetCurrentThreadId() returns DWORD |
3640 intx os::current_thread_id() { return GetCurrentThreadId(); } |
3596 intx os::current_thread_id() { return GetCurrentThreadId(); } |
3641 |
3597 |
5344 } |
5300 } |
5345 |
5301 |
5346 JavaThread* thread = JavaThread::current(); |
5302 JavaThread* thread = JavaThread::current(); |
5347 |
5303 |
5348 // Don't wait if interrupted or already triggered |
5304 // Don't wait if interrupted or already triggered |
5349 if (Thread::is_interrupted(thread, false) || |
5305 if (thread->is_interrupted(false) || |
5350 WaitForSingleObject(_ParkEvent, 0) == WAIT_OBJECT_0) { |
5306 WaitForSingleObject(_ParkEvent, 0) == WAIT_OBJECT_0) { |
5351 ResetEvent(_ParkEvent); |
5307 ResetEvent(_ParkEvent); |
5352 return; |
5308 return; |
5353 } else { |
5309 } else { |
5354 ThreadBlockInVM tbivm(thread); |
5310 ThreadBlockInVM tbivm(thread); |