From e23cda59f1b7601974e03334788ec32cd2314561 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 8 Nov 2022 21:37:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/open_file_cache.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/caches/open_file_cache.go b/internal/caches/open_file_cache.go index b5ea71d..11ac41d 100644 --- a/internal/caches/open_file_cache.go +++ b/internal/caches/open_file_cache.go @@ -19,7 +19,7 @@ type OpenFileCache struct { poolList *linkedlist.List watcher *fsnotify.Watcher - locker sync.Mutex + locker sync.RWMutex maxSize int count int @@ -54,13 +54,15 @@ func NewOpenFileCache(maxSize int) (*OpenFileCache, error) { } func (this *OpenFileCache) Get(filename string) *OpenFile { - this.locker.Lock() - defer this.locker.Unlock() + this.locker.RLock() pool, ok := this.poolMap[filename] + this.locker.RUnlock() if ok { file, consumed := pool.Get() if consumed { + this.locker.Lock() this.count-- + this.locker.Unlock() } return file }