You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/signal/semaphore.go

24 lines
342 B

8 years ago
package signal
type Semaphore struct {
token chan struct{}
8 years ago
}
func NewSemaphore(n int) *Semaphore {
s := &Semaphore{
token: make(chan struct{}, n),
8 years ago
}
for i := 0; i < n; i++ {
s.token <- struct{}{}
8 years ago
}
return s
}
func (s *Semaphore) Wait() <-chan struct{} {
8 years ago
return s.token
}
func (s *Semaphore) Signal() {
s.token <- struct{}{}
8 years ago
}