mirror of
https://github.com/mudler/luet.git
synced 2025-09-03 00:06:36 +00:00
Update gomod and vendor
This commit is contained in:
40
vendor/github.com/moby/buildkit/util/cond/cond.go
generated
vendored
Normal file
40
vendor/github.com/moby/buildkit/util/cond/cond.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package cond
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// NewStatefulCond returns a stateful version of sync.Cond . This cond will
|
||||
// never block on `Wait()` if `Signal()` has been called after the `Wait()` last
|
||||
// returned. This is useful for avoiding to take a lock on `cond.Locker` for
|
||||
// signalling.
|
||||
func NewStatefulCond(l sync.Locker) *StatefulCond {
|
||||
sc := &StatefulCond{main: l}
|
||||
sc.c = sync.NewCond(&sc.mu)
|
||||
return sc
|
||||
}
|
||||
|
||||
type StatefulCond struct {
|
||||
main sync.Locker
|
||||
mu sync.Mutex
|
||||
c *sync.Cond
|
||||
signalled bool
|
||||
}
|
||||
|
||||
func (s *StatefulCond) Wait() {
|
||||
s.main.Unlock()
|
||||
s.mu.Lock()
|
||||
if !s.signalled {
|
||||
s.c.Wait()
|
||||
}
|
||||
s.signalled = false
|
||||
s.mu.Unlock()
|
||||
s.main.Lock()
|
||||
}
|
||||
|
||||
func (s *StatefulCond) Signal() {
|
||||
s.mu.Lock()
|
||||
s.signalled = true
|
||||
s.c.Signal()
|
||||
s.mu.Unlock()
|
||||
}
|
Reference in New Issue
Block a user