// advance moves the versionQueue forward to the next available version,
// recording the failure that eliminated the current version.
181016
func (vq *versionQueue) advance(fail error) error {
	// Nothing in the queue means...nothing in the queue, nicely enough
	if vq.adverr != nil || len(vq.pi) == 0 { // should be a redundant check, but just in case
		return vq.adverr
	}

	// Record the fail reason and pop the queue
	vq.fails = append(vq.fails, failedVersion{
		v: vq.pi[0],
		f: fail,
	})
	vq.pi = vq.pi[1:]

	// *now*, if the queue is empty, ensure all versions have been loaded
	if len(vq.pi) == 0 {
		if vq.allLoaded {
			// This branch gets hit when the queue is first fully exhausted,
			// after a previous advance() already called ListVersions().
			return nil
		}
		vq.allLoaded = true

		var vltmp []Version
		vltmp, vq.adverr = vq.b.listVersions(vq.id)
		if vq.adverr != nil {
			return vq.adverr
		}
		// defensive copy - calling listVersions here means slice contents may
		// be modified when removing prefv/lockv.
		vq.pi = make([]Version, len(vltmp))
		copy(vq.pi, vltmp)

		// search for and remove lockv and prefv, in a pointer GC-safe manner
		//
		// could use the version comparator for binary search here to avoid
		// O(n) each time...if it matters
		var delkeys []int
		for k, pi := range vq.pi {
			if pi == vq.lockv || pi == vq.prefv {
				delkeys = append(delkeys, k)
			}
		}

		for k, dk := range delkeys {
			dk -= k
			copy(vq.pi[dk:], vq.pi[dk+1:])
			// write nil to final position for GC safety
			vq.pi[len(vq.pi)-1] = nil
			vq.pi = vq.pi[:len(vq.pi)-1]
		}

		if len(vq.pi) == 0 {
			// If listing versions added nothing (new), then return now
			return nil
		}
	}

	// We're finally sure that there's something in the queue. Remove the
	// failure marker, as the current version may have failed, but the next one
	// hasn't yet
	vq.failed = false

	// If all have been loaded and the queue is empty, we're definitely out
	// of things to try. Return empty, though, because vq semantics dictate
	// that we don't explicitly indicate the end of the queue here.
	return nil
}
800852
func (pq *PQueue) Push(value interface{}, priority int) {
	item := newItem(value, priority)

	pq.Lock()
	pq.items = append(pq.items, item)
	pq.elemsCount += 1
	pq.swim(pq.size())
	pq.Unlock()
}
937921
func (p *Parser) advance() bool {
	r := p.next()
	if r == '\\' {
		p.next()
	} else if isTerminator(r) {
		p.backup()
		return false
	}
	return true
}
350108
func (u *upgrader) PerformUpgrade() error {
	if err := u.populateAgents(); err != nil {
		return errors.Trace(err)
	}

	if err := u.ensureSystemdFiles(); err != nil {
		return errors.Trace(err)
	}

	return errors.Trace(u.ensureAgentBinaries())
}
600316
func (ts *TermScorer) Advance(target int) (int, error) {
	return ts.docsEnum.Advance(target)
}
995997
func advance_scope(s *scope) (*scope, *scope) {
	if len(s.entities) == 0 {
		return s, s.parent
	}
	return new_scope(s), s
}
100257
func (m *MockUpgrader) PerformUpgrade() error {
	ret := m.ctrl.Call(m, "PerformUpgrade")
	ret0, _ := ret[0].(error)
	return ret0
}
1147016
func (pq *BlockPriorityQueue) Push(blockData interface{}) {
	data, ok := blockData.(*cachedBlockData)
	if !ok || data == nil {
		fmt.Printf("Failed to push a cachedBlockData: %v", data)
		return
	}

	b := newCachedBlock(data.blockSummary, data.stakeInfo)
	b.Access()
	b.heapIdx = len(pq.bh)

	pq.updateMinMax(b.height)
	pq.bh = append(pq.bh, b)
	pq.lastAccess = time.Unix(0, b.accessTime)
}
1036304
func (c *MockClock) advanceTo(end time.Time) {
	for {
		t := c.nextWakeupTime()
		if t == (time.Time{}) || t.After(end) {
			break
		}
		c.advanceToNextWakeup()
	}
	c.now = end
}
891025
func (deque *keyedDeque) Push(key interface{}, val interface{}) {
	deque.Lock()
	defer deque.Unlock()

	if e, ok := deque.index[key]; ok {
		deque.syncedList.Remove(e)
	}
	deque.index[key] = deque.syncedList.PushBack(val)
	deque.invertedIndex[deque.index[key]] = key
}
110196
func (p *PriorityQueue) UpdatePriority(x interface{}, newPriority float64) {
	item, ok := p.lookup[x]
	if !ok {
		return
	}

	item.priority = newPriority
	heap.Fix(p.itemHeap, item.index)
}
1280917
func (c *MockClock) Advance(delta time.Duration) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	end := c.now.Add(delta)
	c.advanceTo(end)
}
727050
func (pq *waitForPriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*waitFor)
	item.index = n
	*pq = append(*pq, item)
}
1231542
func Version() *go_version.Version {
	cached.mutex.RLock()
	c := cached.version
	cached.mutex.RUnlock()
	return c
}
810698
func advanceAndConsume(buf []byte, expected byte) ([]byte, error) {
	var err error
	if buf, err = advanceToNonWhitespace(buf); err != nil {
		return nil, err
	}
	if actual := buf[0]; actual != expected {
		return nil, fmt.Errorf("expected: %q; actual: %q", expected, actual)
	}
	return buf[1:], nil
}
152984
func (s *Store) Advance(duration time.Duration, stop <-chan struct{}) error {
	s.prevTimeMu.Lock()
	defer s.prevTimeMu.Unlock()
	newTime := s.prevTime.Add(duration)
	err := s.runOnLeader(&Command{
		Version:   CommandVersion,
		Operation: OperationSetTime,
		OldTime:   s.prevTime,
		NewTime:   newTime,
	}, stop)
	if globalclock.IsConcurrentUpdate(err) {
		// Someone else updated before us - get the new time.
		s.prevTime = s.fsm.GlobalTime()
	} else if lease.IsTimeout(err) {
		// Convert this to a globalclock timeout to match the Updater
		// interface.
		err = globalclock.ErrTimeout
	} else if err == nil {
		s.prevTime = newTime
	}
	return errors.Trace(err)
}
571802
func (iter *dbCacheIterator) skipPendingUpdates(forwards bool) {
	for iter.dbIter.Valid() {
		var skip bool
		key := iter.dbIter.Key()
		if iter.cacheSnapshot.pendingRemove.Has(key) {
			skip = true
		} else if iter.cacheSnapshot.pendingKeys.Has(key) {
			skip = true
		}
		if !skip {
			break
		}

		if forwards {
			iter.dbIter.Next()
		} else {
			iter.dbIter.Prev()
		}
	}
}