Files
origin/util/semaphore.go
2019-02-28 09:25:13 +08:00

16 lines
201 B
Go

package util
type Semaphore chan struct{}
func MakeSemaphore(n int) Semaphore {
return make(Semaphore, n)
}
func (s Semaphore) Acquire() {
s <- struct{}{}
}
func (s Semaphore) Release() {
<-s
}