github.com/cilium/cilium@v1.16.2/pkg/node/manager/queue.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package manager
     5  
     6  import "github.com/cilium/cilium/pkg/lock"
     7  
     8  type queue[T any] struct {
     9  	mx    lock.RWMutex
    10  	items []*T
    11  }
    12  
    13  func (q *queue[T]) push(t *T) {
    14  	q.mx.Lock()
    15  	defer q.mx.Unlock()
    16  
    17  	q.items = append(q.items, t)
    18  }
    19  
    20  func (q *queue[T]) isEmpty() bool {
    21  	q.mx.RLock()
    22  	defer q.mx.RUnlock()
    23  
    24  	return len(q.items) == 0
    25  }
    26  
    27  func (q *queue[T]) pop() (*T, bool) {
    28  	q.mx.Lock()
    29  	defer q.mx.Unlock()
    30  
    31  	if len(q.items) == 0 {
    32  		return nil, false
    33  	}
    34  	t := q.items[0]
    35  	q.items = q.items[1:]
    36  
    37  	return t, true
    38  }