summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-03-21 00:07:18 +0000
committergVisor bot <gvisor-bot@google.com>2020-03-21 00:07:18 +0000
commit323ed35eb422aa4b4d830143313a2738861123d2 (patch)
tree9b81ab62e4524687666a7e8b47c6c321154e31b1 /pkg
parent9e8fb9c5b53b2b4c035229e3f4ca1c38da41cca1 (diff)
parent1bf2e52bdb5f366b397cb887d4cbdb91dd5e3213 (diff)
Merge release-20200219.0-213-g1bf2e52 (automated)
Diffstat (limited to 'pkg')
-rw-r--r--pkg/rand/rand_linux.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/pkg/rand/rand_linux.go b/pkg/rand/rand_linux.go
index 0bdad5fad..fa6a21026 100644
--- a/pkg/rand/rand_linux.go
+++ b/pkg/rand/rand_linux.go
@@ -17,6 +17,7 @@
package rand
import (
+ "bufio"
"crypto/rand"
"io"
@@ -45,8 +46,22 @@ func (r *reader) Read(p []byte) (int, error) {
return rand.Read(p)
}
+// bufferedReader implements a threadsafe buffered io.Reader.
+type bufferedReader struct {
+ mu sync.Mutex
+ r *bufio.Reader
+}
+
+// Read implements io.Reader.Read.
+func (b *bufferedReader) Read(p []byte) (int, error) {
+ b.mu.Lock()
+ n, err := b.r.Read(p)
+ b.mu.Unlock()
+ return n, err
+}
+
// Reader is the default reader.
-var Reader io.Reader = &reader{}
+var Reader io.Reader = &bufferedReader{r: bufio.NewReader(&reader{})}
// Read reads from the default reader.
func Read(b []byte) (int, error) {