< prev index next >

src/hotspot/os/posix/os_posix.cpp

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


 461         // time moving backwards, should only happen if no monotonic clock
 462         // not a guarantee() because JVM should not abort on kernel/glibc bugs
 463         assert(!os::supports_monotonic_clock(), "unexpected time moving backwards detected on os::sleep(!interruptible)");
 464       } else {
 465         millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
 466       }
 467 
 468       if (millis <= 0) break ;
 469 
 470       prevtime = newtime;
 471       slp->park(millis);
 472     }
 473     return OS_OK ;
 474   }
 475 }
 476 
 477 ////////////////////////////////////////////////////////////////////////////////
 478 // interrupt support
 479 
 480 void os::interrupt(Thread* thread) {
 481   assert(Thread::current() == thread || Threads_lock->owned_by_self(),
 482     "possibility of dangling Thread pointer");
 483 
 484   OSThread* osthread = thread->osthread();
 485 
 486   if (!osthread->interrupted()) {
 487     osthread->set_interrupted(true);
 488     // More than one thread can get here with the same value of osthread,
 489     // resulting in multiple notifications.  We do, however, want the store
 490     // to interrupted() to be visible to other threads before we execute unpark().
 491     OrderAccess::fence();
 492     ParkEvent * const slp = thread->_SleepEvent ;
 493     if (slp != NULL) slp->unpark() ;
 494   }
 495 
 496   // For JSR166. Unpark even if interrupt status already was set
 497   if (thread->is_Java_thread())
 498     ((JavaThread*)thread)->parker()->unpark();
 499 
 500   ParkEvent * ev = thread->_ParkEvent ;
 501   if (ev != NULL) ev->unpark() ;
 502 
 503 }
 504 
 505 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
 506   assert(Thread::current() == thread || Threads_lock->owned_by_self(),
 507     "possibility of dangling Thread pointer");
 508 
 509   OSThread* osthread = thread->osthread();
 510 
 511   bool interrupted = osthread->interrupted();
 512 
 513   // NOTE that since there is no "lock" around the interrupt and
 514   // is_interrupted operations, there is the possibility that the
 515   // interrupted flag (in osThread) will be "false" but that the
 516   // low-level events will be in the signaled state. This is
 517   // intentional. The effect of this is that Object.wait() and
 518   // LockSupport.park() will appear to have a spurious wakeup, which
 519   // is allowed and not harmful, and the possibility is so rare that
 520   // it is not worth the added complexity to add yet another lock.
 521   // For the sleep event an explicit reset is performed on entry
 522   // to os::sleep, so there is no early return. It has also been
 523   // recommended not to put the interrupted flag into the "event"
 524   // structure because it hides the issue.
 525   if (interrupted && clear_interrupted) {
 526     osthread->set_interrupted(false);
 527     // consider thread->_SleepEvent->reset() ... optional optimization




 461         // time moving backwards, should only happen if no monotonic clock
 462         // not a guarantee() because JVM should not abort on kernel/glibc bugs
 463         assert(!os::supports_monotonic_clock(), "unexpected time moving backwards detected on os::sleep(!interruptible)");
 464       } else {
 465         millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
 466       }
 467 
 468       if (millis <= 0) break ;
 469 
 470       prevtime = newtime;
 471       slp->park(millis);
 472     }
 473     return OS_OK ;
 474   }
 475 }
 476 
 477 ////////////////////////////////////////////////////////////////////////////////
 478 // interrupt support
 479 
 480 void os::interrupt(Thread* thread) {
 481   debug_only(Thread::check_for_dangling_thread_pointer(thread);)

 482 
 483   OSThread* osthread = thread->osthread();
 484 
 485   if (!osthread->interrupted()) {
 486     osthread->set_interrupted(true);
 487     // More than one thread can get here with the same value of osthread,
 488     // resulting in multiple notifications.  We do, however, want the store
 489     // to interrupted() to be visible to other threads before we execute unpark().
 490     OrderAccess::fence();
 491     ParkEvent * const slp = thread->_SleepEvent ;
 492     if (slp != NULL) slp->unpark() ;
 493   }
 494 
 495   // For JSR166. Unpark even if interrupt status already was set
 496   if (thread->is_Java_thread())
 497     ((JavaThread*)thread)->parker()->unpark();
 498 
 499   ParkEvent * ev = thread->_ParkEvent ;
 500   if (ev != NULL) ev->unpark() ;

 501 }
 502 
 503 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
 504   debug_only(Thread::check_for_dangling_thread_pointer(thread);)

 505 
 506   OSThread* osthread = thread->osthread();
 507 
 508   bool interrupted = osthread->interrupted();
 509 
 510   // NOTE that since there is no "lock" around the interrupt and
 511   // is_interrupted operations, there is the possibility that the
 512   // interrupted flag (in osThread) will be "false" but that the
 513   // low-level events will be in the signaled state. This is
 514   // intentional. The effect of this is that Object.wait() and
 515   // LockSupport.park() will appear to have a spurious wakeup, which
 516   // is allowed and not harmful, and the possibility is so rare that
 517   // it is not worth the added complexity to add yet another lock.
 518   // For the sleep event an explicit reset is performed on entry
 519   // to os::sleep, so there is no early return. It has also been
 520   // recommended not to put the interrupted flag into the "event"
 521   // structure because it hides the issue.
 522   if (interrupted && clear_interrupted) {
 523     osthread->set_interrupted(false);
 524     // consider thread->_SleepEvent->reset() ... optional optimization


< prev index next >