Repository: kubernetes/kubernetes
File: staging/src/k8s.io/client-go/tools/cache/the_real_fifo.go (Go)

Code before:
	// handling around deleted objects and queue state).
	// Optional, the default is MetaNamespaceKeyFunc.
	KeyFunction KeyFunc

	// KnownObjects is expected to return a list of keys that the consumer of
	// this queue "knows about". It is used to decide which items are missing
	// when Replace() is called; 'Deleted' deltas are produced for the missing items.
	// KnownObjects is required if AtomicEvents is false since it is used to
	// query the state of the internal store for Replace and Resync handling.
	KnownObjects KeyListerGetter

	// If set, will be called for objects before enqueueing them. Please
	// see the comment on TransformFunc for details.
	Transformer TransformFunc

	// AtomicEvents is used to specify whether the RealFIFO will emit events
	// atomically or not. If it is set, a single event will be emitted
	// atomically for Replace and Resync operations.
	// If AtomicEvents is true, KnownObjects must be nil.
	AtomicEvents bool

	// UnlockWhileProcessing is used to specify whether the RealFIFO will unlock
	// the lock while processing events. If it is set, the lock will be unlocked
	// while processing events to allow other goroutines to add items to the queue.
	// If UnlockWhileProcessing is true, AtomicEvents must be true as well.
	UnlockWhileProcessing bool
}

const (
	defaultBatchSize = 1000
)

var _ QueueWithBatch = &RealFIFO{}

// RealFIFO is a Queue in which every notification from the Reflector is passed
// in order to the Queue via Pop.
// This means that it
// 1. delivers notifications for items that have been deleted
// 2. delivers multiple notifications per item instead of simply the most recent value
type RealFIFO struct {
	lock sync.RWMutex
	cond sync.Cond

	items []Delta

	// populated is true if the first batch of items inserted by Replace() has been populated
	// or Delete/Add/Update was called first.
	populated bool
	// initialPopulationCount is the number of items inserted by the first call of Replace()
	initialPopulationCount int


Review comment (suggestion):
update the godoc on Pop to reflect this behavior change as well:

```
// The process function is only guaranteed to be called under lock if UnlockWhileProcessing is false.
// if the process function is updating data structures that need to be in sync with the queue,
// ensure UnlockWhileProcessing is false.
```

Code after:
	// handling around deleted objects and queue state).
	// Optional, the default is MetaNamespaceKeyFunc.
	KeyFunction KeyFunc

	// KnownObjects is expected to return a list of keys that the consumer of
	// this queue "knows about". It is used to decide which items are missing
	// when Replace() is called; 'Deleted' deltas are produced for the missing items.
	// KnownObjects is required if AtomicEvents is false since it is used to
	// query the state of the internal store for Replace and Resync handling.
	KnownObjects KeyListerGetter

	// If set, will be called for objects before enqueueing them. Please
	// see the comment on TransformFunc for details.
	Transformer TransformFunc

	// AtomicEvents is used to specify whether the RealFIFO will emit events
	// atomically or not. If it is set, a single event will be emitted
	// atomically for Replace and Resync operations.
	// If AtomicEvents is true, KnownObjects must be nil.
	AtomicEvents bool

	// UnlockWhileProcessing is used to specify whether the RealFIFO can unlock
	// the lock while processing events. If it is set, the lock can be unlocked
	// while processing events to allow other goroutines to add items to the queue.
	// If UnlockWhileProcessing is true, AtomicEvents must be true as well.
	UnlockWhileProcessing bool
}

const (
	defaultBatchSize = 1000
)

var _ QueueWithBatch = &RealFIFO{}

// RealFIFO is a Queue in which every notification from the Reflector is passed
// in order to the Queue via Pop.
// This means that it
// 1. delivers notifications for items that have been deleted
// 2. delivers multiple notifications per item instead of simply the most recent value
type RealFIFO struct {
	lock sync.RWMutex
	cond sync.Cond

	items []Delta

	// populated is true if the first batch of items inserted by Replace() has been populated
	// or Delete/Add/Update was called first.
	populated bool
	// initialPopulationCount is the number of items inserted by the first call of Replace()
	initialPopulationCount int