summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/clock
diff options
context:
space:
mode:
authorSascha Grunert <sgrunert@suse.com>2019-09-05 16:58:06 +0200
committerSascha Grunert <sgrunert@suse.com>2019-09-05 16:58:08 +0200
commitf66a2069f1b26ff9987b008ba4b0c91ac3b682cc (patch)
tree1219ee0e7b87494eaf2c6ace56d4ecada0dc4a39 /vendor/k8s.io/apimachinery/pkg/util/clock
parentb962b1e3538312f145aea0cf5546ae31f35f635f (diff)
downloadpodman-f66a2069f1b26ff9987b008ba4b0c91ac3b682cc.tar.gz
podman-f66a2069f1b26ff9987b008ba4b0c91ac3b682cc.tar.bz2
podman-f66a2069f1b26ff9987b008ba4b0c91ac3b682cc.zip
Update buildah to v1.11.0
Vendor in the latest changes for buildah to apply the implemented features here as well. Signed-off-by: Sascha Grunert <sgrunert@suse.com>
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/clock')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/clock/clock.go51
1 files changed, 31 insertions, 20 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go b/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
index 9567f9006..0d739d961 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
@@ -80,7 +80,6 @@ type fakeClockWaiter struct {
stepInterval time.Duration
skipIfBlocked bool
destChan chan time.Time
- fired bool
}
func NewFakeClock(t time.Time) *FakeClock {
@@ -175,12 +174,10 @@ func (f *FakeClock) setTimeLocked(t time.Time) {
if w.skipIfBlocked {
select {
case w.destChan <- t:
- w.fired = true
default:
}
} else {
w.destChan <- t
- w.fired = true
}
if w.stepInterval > 0 {
@@ -287,36 +284,50 @@ func (f *fakeTimer) C() <-chan time.Time {
return f.waiter.destChan
}
-// Stop stops the timer and returns true if the timer has not yet fired, or false otherwise.
+// Stop conditionally stops the timer. If the timer has neither fired
+// nor been stopped then this call stops the timer and returns true,
+// otherwise this call returns false. This is like time.Timer::Stop.
func (f *fakeTimer) Stop() bool {
f.fakeClock.lock.Lock()
defer f.fakeClock.lock.Unlock()
-
- newWaiters := make([]fakeClockWaiter, 0, len(f.fakeClock.waiters))
- for i := range f.fakeClock.waiters {
- w := &f.fakeClock.waiters[i]
- if w != &f.waiter {
- newWaiters = append(newWaiters, *w)
+ // The timer has already fired or been stopped, unless it is found
+ // among the clock's waiters.
+ stopped := false
+ oldWaiters := f.fakeClock.waiters
+ newWaiters := make([]fakeClockWaiter, 0, len(oldWaiters))
+ seekChan := f.waiter.destChan
+ for i := range oldWaiters {
+ // Identify the timer's fakeClockWaiter by the identity of the
+ // destination channel, nothing else is necessarily unique and
+ // constant since the timer's creation.
+ if oldWaiters[i].destChan == seekChan {
+ stopped = true
+ } else {
+ newWaiters = append(newWaiters, oldWaiters[i])
}
}
f.fakeClock.waiters = newWaiters
- return !f.waiter.fired
+ return stopped
}
-// Reset resets the timer to the fake clock's "now" + d. It returns true if the timer has not yet
-// fired, or false otherwise.
+// Reset conditionally updates the firing time of the timer. If the
+// timer has neither fired nor been stopped then this call resets the
+// timer to the fake clock's "now" + d and returns true, otherwise
+// this call returns false. This is like time.Timer::Reset.
func (f *fakeTimer) Reset(d time.Duration) bool {
f.fakeClock.lock.Lock()
defer f.fakeClock.lock.Unlock()
-
- active := !f.waiter.fired
-
- f.waiter.fired = false
- f.waiter.targetTime = f.fakeClock.time.Add(d)
-
- return active
+ waiters := f.fakeClock.waiters
+ seekChan := f.waiter.destChan
+ for i := range waiters {
+ if waiters[i].destChan == seekChan {
+ waiters[i].targetTime = f.fakeClock.time.Add(d)
+ return true
+ }
+ }
+ return false
}
type Ticker interface {