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