mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-18 11:40:24 +08:00
优化代码
This commit is contained in:
@@ -19,7 +19,7 @@ type OpenFileCache struct {
|
|||||||
poolList *linkedlist.List
|
poolList *linkedlist.List
|
||||||
watcher *fsnotify.Watcher
|
watcher *fsnotify.Watcher
|
||||||
|
|
||||||
locker sync.Mutex
|
locker sync.RWMutex
|
||||||
|
|
||||||
maxSize int
|
maxSize int
|
||||||
count int
|
count int
|
||||||
@@ -54,13 +54,15 @@ func NewOpenFileCache(maxSize int) (*OpenFileCache, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *OpenFileCache) Get(filename string) *OpenFile {
|
func (this *OpenFileCache) Get(filename string) *OpenFile {
|
||||||
this.locker.Lock()
|
this.locker.RLock()
|
||||||
defer this.locker.Unlock()
|
|
||||||
pool, ok := this.poolMap[filename]
|
pool, ok := this.poolMap[filename]
|
||||||
|
this.locker.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
file, consumed := pool.Get()
|
file, consumed := pool.Get()
|
||||||
if consumed {
|
if consumed {
|
||||||
|
this.locker.Lock()
|
||||||
this.count--
|
this.count--
|
||||||
|
this.locker.Unlock()
|
||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user