mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
processor listener: fix locking in pop()
This commit is contained in:
parent
5b7e617abf
commit
308201acb0
@ -279,21 +279,30 @@ func (p *processorListener) add(notification interface{}) {
|
|||||||
func (p *processorListener) pop(stopCh <-chan struct{}) {
|
func (p *processorListener) pop(stopCh <-chan struct{}) {
|
||||||
defer utilruntime.HandleCrash()
|
defer utilruntime.HandleCrash()
|
||||||
|
|
||||||
p.lock.Lock()
|
|
||||||
defer p.lock.Unlock()
|
|
||||||
for {
|
for {
|
||||||
for len(p.pendingNotifications) == 0 {
|
blockingGet := func() (interface{}, bool) {
|
||||||
// check if we're shutdown
|
p.lock.Lock()
|
||||||
select {
|
defer p.lock.Unlock()
|
||||||
case <-stopCh:
|
|
||||||
return
|
for len(p.pendingNotifications) == 0 {
|
||||||
default:
|
// check if we're shutdown
|
||||||
|
select {
|
||||||
|
case <-stopCh:
|
||||||
|
return nil, true
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
p.cond.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.cond.Wait()
|
nt := p.pendingNotifications[0]
|
||||||
|
p.pendingNotifications = p.pendingNotifications[1:]
|
||||||
|
return nt, false
|
||||||
|
}
|
||||||
|
|
||||||
|
notification, stopped := blockingGet()
|
||||||
|
if stopped {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
notification := p.pendingNotifications[0]
|
|
||||||
p.pendingNotifications = p.pendingNotifications[1:]
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
|
Loading…
Reference in New Issue
Block a user