fix access logger high cpu usage, simplify some code

This commit is contained in:
yusing
2025-01-02 12:19:00 +08:00
parent 320e29ba84
commit a587ada170
5 changed files with 367 additions and 30 deletions

View File

@@ -1,15 +1,12 @@
package utils
import (
"sync"
"sync/atomic"
)
type RefCount struct {
_ NoCopy
mu sync.Mutex
cond *sync.Cond
refCount uint32
zeroCh chan struct{}
}
@@ -19,7 +16,6 @@ func NewRefCounter() *RefCount {
refCount: 1,
zeroCh: make(chan struct{}),
}
rc.cond = sync.NewCond(&rc.mu)
return rc
}
@@ -33,9 +29,6 @@ func (rc *RefCount) Add() {
func (rc *RefCount) Sub() {
if atomic.AddUint32(&rc.refCount, ^uint32(0)) == 0 {
rc.mu.Lock()
close(rc.zeroCh)
rc.cond.Broadcast()
rc.mu.Unlock()
}
}