mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-16 09:57:49 +02:00
util.Semaphore: initial commit
This commit is contained in:
17
util/semaphore.go
Normal file
17
util/semaphore.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
type Semaphore struct {
|
||||||
|
c chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSemaphore(cap int) Semaphore {
|
||||||
|
return Semaphore{make(chan struct{}, cap)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Semaphore) Down() {
|
||||||
|
s.c <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Semaphore) Up() {
|
||||||
|
<-s.c
|
||||||
|
}
|
Reference in New Issue
Block a user