mirror of
https://github.com/golang/go
synced 2024-11-22 08:24:41 -07:00
Use defer to unlock mutex in crypto/rand.
R=agl1 CC=golang-dev https://golang.org/cl/3991045
This commit is contained in:
parent
49e2888a96
commit
3921d26300
@ -29,15 +29,14 @@ type devReader struct {
|
|||||||
|
|
||||||
func (r *devReader) Read(b []byte) (n int, err os.Error) {
|
func (r *devReader) Read(b []byte) (n int, err os.Error) {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
if r.f == nil {
|
if r.f == nil {
|
||||||
f, err := os.Open(r.name, os.O_RDONLY, 0)
|
f, err := os.Open(r.name, os.O_RDONLY, 0)
|
||||||
if f == nil {
|
if f == nil {
|
||||||
r.mu.Unlock()
|
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
r.f = f
|
r.f = f
|
||||||
}
|
}
|
||||||
r.mu.Unlock()
|
|
||||||
return r.f.Read(b)
|
return r.f.Read(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user