Skip to content

Commit

Permalink
processor listener: fix locking in pop()
Browse files Browse the repository at this point in the history
  • Loading branch information
hongchaodeng committed Jun 8, 2016
1 parent 5b7e617 commit 308201a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions pkg/controller/framework/shared_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,30 @@ func (p *processorListener) add(notification interface{}) {
func (p *processorListener) pop(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()

p.lock.Lock()
defer p.lock.Unlock()
for {
for len(p.pendingNotifications) == 0 {
// check if we're shutdown
select {
case <-stopCh:
return
default:
blockingGet := func() (interface{}, bool) {
p.lock.Lock()
defer p.lock.Unlock()

for len(p.pendingNotifications) == 0 {
// 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 {
case <-stopCh:
Expand Down

0 comments on commit 308201a

Please sign in to comment.