summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorchappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2012-09-18 02:47:24 +0000
committerchappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2012-09-18 02:47:24 +0000
commit3e296c28c3c2b67df624d372b75650ae65c87b04 (patch)
tree82ff322bce6743c61ba922a3bbb68d7a03fe575d /src/base
parent1f59bb34d3ce03df51c8356dd44fcb0b15de4769 (diff)
downloadgperftools-3e296c28c3c2b67df624d372b75650ae65c87b04.tar.gz
issue-442: Fixes an issue encountered on PPC with undefined conversions from 'base::subtle::Atomic64*' to 'const volatile Atomic32*'
git-svn-id: http://gperftools.googlecode.com/svn/trunk@160 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/base')
-rw-r--r--src/base/spinlock_internal.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/base/spinlock_internal.cc b/src/base/spinlock_internal.cc
index b9fadde..172a637 100644
--- a/src/base/spinlock_internal.cc
+++ b/src/base/spinlock_internal.cc
@@ -80,6 +80,7 @@ int32 SpinLockWait(volatile Atomic32 *w, int n,
static int SuggestedDelayNS(int loop) {
// Weak pseudo-random number generator to get some spread between threads
// when many are spinning.
+#ifdef BASE_HAS_ATOMIC64
static base::subtle::Atomic64 rand;
uint64 r = base::subtle::NoBarrier_Load(&rand);
r = 0x5deece66dLL * r + 0xb; // numbers from nrand48()
@@ -96,6 +97,24 @@ static int SuggestedDelayNS(int loop) {
// The futex path multiplies this by 16, since we expect explicit wakeups
// almost always on that path.
return r >> (44 - (loop >> 3));
+#else
+ static Atomic32 rand;
+ uint32 r = base::subtle::NoBarrier_Load(&rand);
+ r = 0x343fd * r + 0x269ec3; // numbers from MSVC++
+ base::subtle::NoBarrier_Store(&rand, r);
+
+ r <<= 1; // 31-bit random number now in top 31-bits.
+ if (loop < 0 || loop > 32) { // limit loop to 0..32
+ loop = 32;
+ }
+ // loop>>3 cannot exceed 4 because loop cannot exceed 32.
+ // Select top 20..24 bits of lower 31 bits,
+ // giving approximately 0ms to 16ms.
+ // Mean is exponential in loop for first 32 iterations, then 8ms.
+ // The futex path multiplies this by 16, since we expect explicit wakeups
+ // almost always on that path.
+ return r >> (12 - (loop >> 3));
+#endif
}
} // namespace internal