Files
proxy/pkg/utils/sync.go

36 lines
457 B
Go
Raw Normal View History

package utils
import (
"sync"
"sync/atomic"
)
2025-02-27 18:07:00 +08:00
type WaitGroup interface {
2025-02-27 23:11:36 +08:00
Add(delta int)
2025-02-27 18:07:00 +08:00
Done()
Wait()
}
type CountWaitGroup struct {
wg sync.WaitGroup
2025-02-25 15:56:33 +08:00
num atomic.Int64
}
2025-02-27 23:11:36 +08:00
func (c *CountWaitGroup) Add(delta int) {
c.wg.Add(delta)
2025-02-25 15:56:33 +08:00
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 {
2025-02-25 15:56:33 +08:00
return uint64(c.num.Load())
}