1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-06 10:20:44 -05:00
v2fly/common/signal/semaphore.go

24 lines
318 B
Go
Raw Normal View History

2017-02-13 17:29:34 -05:00
package signal
type Semaphore struct {
token chan bool
}
func NewSemaphore(n int) *Semaphore {
s := &Semaphore{
token: make(chan bool, n),
}
for i := 0; i < n; i++ {
s.token <- true
}
return s
}
func (s *Semaphore) Wait() <-chan bool {
return s.token
}
func (s *Semaphore) Signal() {
s.token <- true
}