mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-27 09:14:44 +08:00
新增工具库
This commit is contained in:
15
util/semaphore.go
Normal file
15
util/semaphore.go
Normal file
@@ -0,0 +1,15 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user