< prev index next >

src/share/vm/runtime/os.cpp

Print this page
rev 13430 : imported patch fix_calls


 738 
 739   // if q overflowed, ignore the overflow and increment q
 740   if (lo > m) {
 741     lo &= m;
 742     ++lo;
 743   }
 744   lo += hi >> 15;
 745 
 746   // if (p+q) overflowed, ignore the overflow and increment (p+q)
 747   if (lo > m) {
 748     lo &= m;
 749     ++lo;
 750   }
 751   return lo;
 752 }
 753 
 754 int os::random() {
 755   // Make updating the random seed thread safe.
 756   while (true) {
 757     unsigned int seed = _rand_seed;
 758     int rand = random_helper(seed);
 759     if (Atomic::cmpxchg(rand, &_rand_seed, seed) == seed) {
 760       return rand;
 761     }
 762   }
 763 }
 764 
 765 // The INITIALIZED state is distinguished from the SUSPENDED state because the
 766 // conditions in which a thread is first started are different from those in which
 767 // a suspension is resumed.  These differences make it hard for us to apply the
 768 // tougher checks when starting threads that we want to do when resuming them.
 769 // However, when start_thread is called as a result of Thread.start, on a Java
 770 // thread, the operation is synchronized on the Java Thread object.  So there
 771 // cannot be a race to start the thread and hence for the thread to exit while
 772 // we are working on it.  Non-Java threads that start Java threads either have
 773 // to do so in a context in which races are impossible, or should do appropriate
 774 // locking.
 775 
 776 void os::start_thread(Thread* thread) {
 777   // guard suspend/resume
 778   MutexLockerEx ml(thread->SR_lock(), Mutex::_no_safepoint_check_flag);
 779   OSThread* osthread = thread->osthread();
 780   osthread->set_state(RUNNABLE);




 738 
 739   // if q overflowed, ignore the overflow and increment q
 740   if (lo > m) {
 741     lo &= m;
 742     ++lo;
 743   }
 744   lo += hi >> 15;
 745 
 746   // if (p+q) overflowed, ignore the overflow and increment (p+q)
 747   if (lo > m) {
 748     lo &= m;
 749     ++lo;
 750   }
 751   return lo;
 752 }
 753 
 754 int os::random() {
 755   // Make updating the random seed thread safe.
 756   while (true) {
 757     unsigned int seed = _rand_seed;
 758     unsigned int rand = random_helper(seed);
 759     if (Atomic::cmpxchg(rand, &_rand_seed, seed) == seed) {
 760       return static_cast<int>(rand);
 761     }
 762   }
 763 }
 764 
 765 // The INITIALIZED state is distinguished from the SUSPENDED state because the
 766 // conditions in which a thread is first started are different from those in which
 767 // a suspension is resumed.  These differences make it hard for us to apply the
 768 // tougher checks when starting threads that we want to do when resuming them.
 769 // However, when start_thread is called as a result of Thread.start, on a Java
 770 // thread, the operation is synchronized on the Java Thread object.  So there
 771 // cannot be a race to start the thread and hence for the thread to exit while
 772 // we are working on it.  Non-Java threads that start Java threads either have
 773 // to do so in a context in which races are impossible, or should do appropriate
 774 // locking.
 775 
 776 void os::start_thread(Thread* thread) {
 777   // guard suspend/resume
 778   MutexLockerEx ml(thread->SR_lock(), Mutex::_no_safepoint_check_flag);
 779   OSThread* osthread = thread->osthread();
 780   osthread->set_state(RUNNABLE);


< prev index next >