...

Source file src/github.com/letsencrypt/boulder/cmd/rocsp-tool/inflight.go

Documentation: github.com/letsencrypt/boulder/cmd/rocsp-tool

     1  package notmain
     2  
     3  import "sync"
     4  
     5  type inflight struct {
     6  	sync.RWMutex
     7  	items map[uint64]struct{}
     8  }
     9  
    10  func newInflight() *inflight {
    11  	return &inflight{
    12  		items: make(map[uint64]struct{}),
    13  	}
    14  }
    15  
    16  func (i *inflight) add(n uint64) {
    17  	i.Lock()
    18  	defer i.Unlock()
    19  	i.items[n] = struct{}{}
    20  }
    21  
    22  func (i *inflight) remove(n uint64) {
    23  	i.Lock()
    24  	defer i.Unlock()
    25  	delete(i.items, n)
    26  }
    27  
    28  func (i *inflight) len() int {
    29  	i.RLock()
    30  	defer i.RUnlock()
    31  	return len(i.items)
    32  }
    33  
    34  // min returns the numerically smallest key inflight. If nothing is inflight,
    35  // it returns 0. Note: this takes O(n) time in the number of keys and should
    36  // be called rarely.
    37  func (i *inflight) min() uint64 {
    38  	i.RLock()
    39  	defer i.RUnlock()
    40  	if len(i.items) == 0 {
    41  		return 0
    42  	}
    43  	var min uint64
    44  	for k := range i.items {
    45  		if min == 0 {
    46  			min = k
    47  		}
    48  		if k < min {
    49  			min = k
    50  		}
    51  	}
    52  	return min
    53  }
    54  

View as plain text