mirror of https://github.com/golang/go.git
os: fix the race condition on dir_unix
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
This commit is contained in:
parent
eac6fc15cc
commit
1e1f619143
|
|
@ -46,11 +46,19 @@ func (d *dirInfo) close() {
|
|||
|
||||
func (f *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEntry, infos []FileInfo, err error) {
|
||||
// If this file has no dirInfo, create one.
|
||||
d := f.dirinfo.Load()
|
||||
if d == nil {
|
||||
d = new(dirInfo)
|
||||
f.dirinfo.Store(d)
|
||||
var d *dirInfo
|
||||
for {
|
||||
d = f.dirinfo.Load()
|
||||
if d != nil {
|
||||
break
|
||||
}
|
||||
newD := new(dirInfo)
|
||||
if f.dirinfo.CompareAndSwap(nil, newD) {
|
||||
d = newD
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
if d.buf == nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue