diff options
| author | Dmitriy Vyukov <dvyukov@google.com> | 2011-07-12 01:23:58 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-07-12 01:23:58 -0400 |
| commit | 909f31872a0e5e5b8ec5cc49b22ae661777a2fbc (patch) | |
| tree | 2dd9a44089d0aa91f6da86b81a439c7d007bbe35 /src/pkg/runtime/chan.c | |
| parent | f9f21aa1fb45aaa4eece55f192783bfa46df4909 (diff) | |
| download | go-909f31872a0e5e5b8ec5cc49b22ae661777a2fbc.tar.xz | |
runtime: eliminate false sharing on random number generators
Use machine-local random number generator instead of
racy global ones.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4674049
Diffstat (limited to 'src/pkg/runtime/chan.c')
| -rw-r--r-- | src/pkg/runtime/chan.c | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/src/pkg/runtime/chan.c b/src/pkg/runtime/chan.c index f94c3ef40a..78f67b817c 100644 --- a/src/pkg/runtime/chan.c +++ b/src/pkg/runtime/chan.c @@ -1222,17 +1222,6 @@ freesg(Hchan *c, SudoG *sg) } static uint32 -fastrand1(void) -{ - static uint32 x = 0x49f6428aUL; - - x += x; - if(x & 0x80000000L) - x ^= 0x88888eefUL; - return x; -} - -static uint32 fastrandn(uint32 n) { uint32 max, r; @@ -1240,12 +1229,12 @@ fastrandn(uint32 n) if(n <= 1) return 0; - r = fastrand1(); + r = runtime·fastrand1(); if(r < (1ULL<<31)-n) // avoid computing max in common case return r%n; max = (1ULL<<31)/n * n; while(r >= max) - r = fastrand1(); + r = runtime·fastrand1(); return r%n; } |
