mirror of https://github.com/v2ray/v2ray-core
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.
24 lines
318 B
24 lines
318 B
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
|
|
}
|