mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-24 18:11:19 +01:00
fix access logger high cpu usage, simplify some code
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user