aboutsummaryrefslogtreecommitdiff
path: root/fs.go
diff options
context:
space:
mode:
authorGravatar halst <liu-song@users.noreply.github.com> 2021-11-04 20:01:58 +0800
committerGravatar GitHub <noreply@github.com> 2021-11-04 13:01:58 +0100
commitd61350291204992c600c6bf944cae02f406d2c20 (patch)
tree68a942e79f256bad09634fe238966d62fdf692df /fs.go
parentDon't run all race tests on windows (#1143) (diff)
downloadfasthttp-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.go16
1 files changed, 4 insertions, 12 deletions
diff --git a/fs.go b/fs.go
index f8d4add..147f315 100644
--- a/fs.go
+++ b/fs.go
@@ -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
}