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