diff options
author | halst <liu-song@users.noreply.github.com> | 2021-11-04 20:01:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-04 13:01:58 +0100 |
commit | d61350291204992c600c6bf944cae02f406d2c20 (patch) | |
tree | 68a942e79f256bad09634fe238966d62fdf692df /fs.go | |
parent | Don't run all race tests on windows (#1143) (diff) | |
download | fasthttp-d61350291204992c600c6bf944cae02f406d2c20.tar.gz fasthttp-d61350291204992c600c6bf944cae02f406d2c20.tar.bz2 fasthttp-d61350291204992c600c6bf944cae02f406d2c20.zip |
use sync.map is better (#1145)
* use sync.map is better
* Use LoadOrStore
Diffstat (limited to 'fs.go')
-rw-r--r-- | fs.go | 16 |
1 files changed, 4 insertions, 12 deletions
@@ -1370,18 +1370,10 @@ func fsModTime(t time.Time) time.Time { return t.In(time.UTC).Truncate(time.Second) } -var ( - filesLockMap = make(map[string]*sync.Mutex) - filesLockMapLock sync.Mutex -) +var filesLockMap sync.Map func getFileLock(absPath string) *sync.Mutex { - filesLockMapLock.Lock() - flock := filesLockMap[absPath] - if flock == nil { - flock = &sync.Mutex{} - filesLockMap[absPath] = flock - } - filesLockMapLock.Unlock() - return flock + v, _ := filesLockMap.LoadOrStore(absPath,&sync.Mutex{}) + filelock:=v.(*sync.Mutex) + return filelock } |