commit af0517689263700007cacd14904722421bad73ad
parent 610a478acca2c1ad93ea0996603c35e9cb332732
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 16 Nov 2024 18:05:45 +0900
update diskfs/qid_windows.go
Diffstat:
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/diskfs/qid_windows.go b/diskfs/qid_windows.go
@@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"path/filepath"
+ "sync"
"time"
"git.mtkn.jp/lib9p"
@@ -25,6 +26,7 @@ type qidRec struct {
// QidPool is the list of Qids in the file system.
type QidPool struct {
+ *sync.Mutex
m map[fileID]*qidRec
nextQid uint64
}
@@ -42,7 +44,9 @@ func idFromInfo(path string, info fs.FileInfo) fileID {
// newQidPool allocates a QidPool.
func newQidPool() *QidPool {
return &QidPool{
- m: make(map[fileID]*qidRec),
+ new(sync.Mutex),
+ make(map[fileID]*qidRec),
+ 0,
}
}
@@ -66,6 +70,8 @@ func (pool *QidPool) lookup(f *File) (lib9p.Qid, bool) {
// It also checks if the file is modified after the last access by
// comparing the qidReq.mtime and mtime, and update Qid.Vers if needed.
func (pool *QidPool) lookupID(id fileID, mtime time.Time) (lib9p.Qid, bool) {
+ pool.Lock()
+ defer pool.Unlock()
qrec, ok := pool.m[id]
if !ok {
return lib9p.Qid{}, false
@@ -98,6 +104,8 @@ func (pool *QidPool) addID(id fileID, info fs.FileInfo) (lib9p.Qid, error) {
Path: pool.nextQid,
Type: qtype,
}
+ pool.Lock()
+ defer pool.Unlock()
pool.m[id] = &qidRec{qid: qid, mtime: info.ModTime()}
pool.nextQid++
return *qid, nil
@@ -109,5 +117,13 @@ func (pool *QidPool) delete(f *File) {
if err != nil {
return
}
+ pool.Lock()
+ defer pool.Unlock()
+ delete(pool.m, id)
+}
+
+func (pool *QidPool) deleteID(id fileID) {
+ pool.Lock()
+ defer pool.Unlock()
delete(pool.m, id)
}