Files
proxy/pkg/utils/sync.go
2025-02-25 16:03:21 +08:00

30 lines
401 B
Go

package utils
import (
"sync"
"sync/atomic"
)
type CountWaitGroup struct {
wg sync.WaitGroup
num atomic.Int64
}
func (c *CountWaitGroup) Add(delta uint) {
c.wg.Add(int(delta))
c.num.Add(int64(delta))
}
func (c *CountWaitGroup) Done() {
c.wg.Done()
c.num.Add(-1)
}
func (c *CountWaitGroup) Wait() {
c.wg.Wait()
}
func (c *CountWaitGroup) Count() uint64 {
return uint64(c.num.Load())
}