mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 18:17:52 -05:00
24 lines
342 B
Go
24 lines
342 B
Go
package signal
|
|
|
|
type Semaphore struct {
|
|
token chan struct{}
|
|
}
|
|
|
|
func NewSemaphore(n int) *Semaphore {
|
|
s := &Semaphore{
|
|
token: make(chan struct{}, n),
|
|
}
|
|
for i := 0; i < n; i++ {
|
|
s.token <- struct{}{}
|
|
}
|
|
return s
|
|
}
|
|
|
|
func (s *Semaphore) Wait() <-chan struct{} {
|
|
return s.token
|
|
}
|
|
|
|
func (s *Semaphore) Signal() {
|
|
s.token <- struct{}{}
|
|
}
|