mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-11 06:29:29 +01:00
simplify semaphore release code
This commit is contained in:
parent
2e9a0d4b2d
commit
549d06bc98
@ -5,8 +5,6 @@ package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -67,15 +65,7 @@ func (semaphore *Semaphore) AcquireWithContext(ctx context.Context) (acquired bo
|
||||
return
|
||||
}
|
||||
|
||||
// Release releases a semaphore. It never blocks. (This is not a license
|
||||
// to program spurious releases.)
|
||||
// Release releases a semaphore.
|
||||
func (semaphore *Semaphore) Release() {
|
||||
select {
|
||||
case <-(*semaphore):
|
||||
// good
|
||||
default:
|
||||
// spurious release
|
||||
log.Printf("spurious semaphore release (full to capacity %d)", cap(*semaphore))
|
||||
debug.PrintStack()
|
||||
}
|
||||
<-(*semaphore)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user