1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-24 14:39:10 -04:00

signal.semaphore

This commit is contained in:
Darien Raymond
2017-02-13 23:29:34 +01:00
parent 90200fbecb
commit 520e3ea9e6
2 changed files with 29 additions and 7 deletions

View File

@@ -0,0 +1,23 @@
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
}