Fix: add recycleLock preventing recycle FileSystem used by another goroutine

This commit is contained in:
HFO4
2020-11-21 19:32:25 +08:00
parent 11c218eb94
commit d97bc26042
3 changed files with 13 additions and 2 deletions

View File

@@ -97,6 +97,9 @@ type FileSystem struct {
文件系统处理适配器
*/
Handler Handler
// 回收锁
recycleLock sync.Mutex
}
// getEmptyFS 从pool中获取新的FileSystem
@@ -107,6 +110,7 @@ func getEmptyFS() *FileSystem {
// Recycle 回收FileSystem资源
func (fs *FileSystem) Recycle() {
fs.recycleLock.Lock()
fs.reset()
FSPool.Put(fs)
}
@@ -120,6 +124,7 @@ func (fs *FileSystem) reset() {
fs.Handler = nil
fs.Root = nil
fs.Lock = sync.Mutex{}
fs.recycleLock = sync.Mutex{}
}
// NewFileSystem 初始化一个文件系统