diff options
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/internal/sdkrand/locked_source.go')
-rw-r--r-- | vendor/github.com/aws/aws-sdk-go/internal/sdkrand/locked_source.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/internal/sdkrand/locked_source.go b/vendor/github.com/aws/aws-sdk-go/internal/sdkrand/locked_source.go new file mode 100644 index 0000000..0c9802d --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/internal/sdkrand/locked_source.go | |||
@@ -0,0 +1,29 @@ | |||
1 | package sdkrand | ||
2 | |||
3 | import ( | ||
4 | "math/rand" | ||
5 | "sync" | ||
6 | "time" | ||
7 | ) | ||
8 | |||
9 | // lockedSource is a thread-safe implementation of rand.Source | ||
10 | type lockedSource struct { | ||
11 | lk sync.Mutex | ||
12 | src rand.Source | ||
13 | } | ||
14 | |||
15 | func (r *lockedSource) Int63() (n int64) { | ||
16 | r.lk.Lock() | ||
17 | n = r.src.Int63() | ||
18 | r.lk.Unlock() | ||
19 | return | ||
20 | } | ||
21 | |||
22 | func (r *lockedSource) Seed(seed int64) { | ||
23 | r.lk.Lock() | ||
24 | r.src.Seed(seed) | ||
25 | r.lk.Unlock() | ||
26 | } | ||
27 | |||
28 | // SeededRand is a new RNG using a thread safe implementation of rand.Source | ||
29 | var SeededRand = rand.New(&lockedSource{src: rand.NewSource(time.Now().UnixNano())}) | ||