mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
16 lines
206 B
Go
16 lines
206 B
Go
package semaphore
|
|
|
|
type Semaphore chan struct{}
|
|
|
|
func MakeSemaphore(n int) Semaphore {
|
|
return make(Semaphore, n)
|
|
}
|
|
|
|
func (s Semaphore) Acquire() {
|
|
s <- struct{}{}
|
|
}
|
|
|
|
func (s Semaphore) Release() {
|
|
<-s
|
|
}
|