// FlushDeviceQueueForDevEUI flushes the device-queue for the given DevEUI.
506934
func (n *NetworkServerAPI) FlushDeviceQueueForDevEUI(ctx context.Context, req *ns.FlushDeviceQueueForDevEUIRequest) (*empty.Empty, error) {
	var devEUI lorawan.EUI64
	copy(devEUI[:], req.DevEui)

	err := storage.FlushDeviceQueueForDevEUI(storage.DB(), devEUI)
	if err != nil {
		return nil, errToRPCError(err)
	}

	return &empty.Empty{}, nil
}
26850
func (r *Rx) Flush() {
	if r.head == r.tail {
		return
	}
	r.p.writeAtomic(r.tail, slotFree|slotToPayloadSize(r.head-r.tail))
	r.tail = r.head
}
939480
func (devices *DeviceSet) AddDevice(hash, baseHash string) error {
	logrus.Debugf("devmapper: AddDevice(hash=%s basehash=%s)", hash, baseHash)
	defer logrus.Debugf("devmapper: AddDevice(hash=%s basehash=%s) END", hash, baseHash)

	// If a deleted device exists, return error.
	baseInfo, err := devices.lookupDeviceWithLock(baseHash)
	if err != nil {
		return err
	}

	if baseInfo.Deleted {
		return fmt.Errorf("devmapper: Base device %v has been marked for deferred deletion", baseInfo.Hash)
	}

	baseInfo.lock.Lock()
	defer baseInfo.lock.Unlock()

	devices.Lock()
	defer devices.Unlock()

	// Also include deleted devices in case hash of new device is
	// same as one of the deleted devices.
	if info, _ := devices.lookupDevice(hash); info != nil {
		return fmt.Errorf("devmapper: device %s already exists. Deleted=%v", hash, info.Deleted)
	}

	if err := devices.createRegisterSnapDevice(hash, baseInfo); err != nil {
		return err
	}

	return nil
}
1284994
func (i *Handle) Flush() error {
	_, err := i.doCmdWithoutAttr(ipvsCmdFlush)
	return err
}
869846
func (e *eventDebouncer) flush() {
	if len(e.events) == 0 {
		return
	}

	// if the flush interval is faster than the callback then we will end up calling
	// the callback multiple times, probably a bad idea. In this case we could drop
	// frames?
	go e.callback(e.events)
	e.events = make([]frame, 0, eventBufferSize)
}
754640
func ScheduleDeviceQueueToPingSlotsForDevEUI(db sqlx.Ext, dp storage.DeviceProfile, ds storage.DeviceSession) error {
	queueItems, err := storage.GetDeviceQueueItemsForDevEUI(db, ds.DevEUI)
	if err != nil {
		return errors.Wrap(err, "get device-queue items error")
	}

	scheduleAfterGPSEpochTS := gps.Time(time.Now().Add(scheduleMargin)).TimeSinceGPSEpoch()

	for _, qi := range queueItems {
		if qi.IsPending {
			continue
		}

		gpsEpochTS, err := GetNextPingSlotAfter(scheduleAfterGPSEpochTS, ds.DevAddr, ds.PingSlotNb)
		if err != nil {
			return errors.Wrap(err, "get next ping-slot after error")
		}

		timeoutTime := time.Time(gps.NewFromTimeSinceGPSEpoch(gpsEpochTS)).Add(time.Second * time.Duration(dp.ClassBTimeout))
		qi.EmitAtTimeSinceGPSEpoch = &gpsEpochTS
		qi.TimeoutAfter = &timeoutTime

		if err := storage.UpdateDeviceQueueItem(db, &qi); err != nil {
			return errors.Wrap(err, "update device-queue item error")
		}

		scheduleAfterGPSEpochTS = gpsEpochTS
	}

	log.WithFields(log.Fields{
		"dev_eui": ds.DevEUI,
		"count":   len(queueItems),
	}).Info("device-queue items scheduled to ping-slots")

	return nil
}
150157
func (p *Port) Flush() error {
	_, err := C.tcflush(C.int(p.f.Fd()), C.TCIOFLUSH)
	return err
}
659449
func (p *PriorityQueue) flushBackoffQCompleted() {
	p.lock.Lock()
	defer p.lock.Unlock()

	for {
		rawPodInfo := p.podBackoffQ.Peek()
		if rawPodInfo == nil {
			return
		}
		pod := rawPodInfo.(*podInfo).pod
		boTime, found := p.podBackoff.GetBackoffTime(nsNameForPod(pod))
		if !found {
			klog.Errorf("Unable to find backoff value for pod %v in backoffQ", nsNameForPod(pod))
			p.podBackoffQ.Pop()
			p.activeQ.Add(rawPodInfo)
			defer p.cond.Broadcast()
			continue
		}

		if boTime.After(p.clock.Now()) {
			return
		}
		_, err := p.podBackoffQ.Pop()
		if err != nil {
			klog.Errorf("Unable to pop pod %v from backoffQ despite backoff completion.", nsNameForPod(pod))
			return
		}
		p.activeQ.Add(rawPodInfo)
		defer p.cond.Broadcast()
	}
}
1032337
func (w *IndexWriter) flushFailed(info *SegmentInfo) error {
	w.Lock()
	defer w.Unlock()
	return w.deleter.refresh(info.Name)
}
933545
func (c *sioClient) WaitForDetachedDevice(token string) error {
	if token == "" {
		return fmt.Errorf("invalid detach token")
	}

	// wait for attach.Token to show up in local device list
	ticker := time.NewTicker(time.Second)
	defer ticker.Stop()
	timer := time.NewTimer(30 * time.Second)
	defer timer.Stop()

	for {
		select {
		case <-ticker.C:
			devMap, err := c.Devs()
			if err != nil {
				klog.Error(log("failed while waiting for volume to unmap/detach: %v", err))
				return err
			}
			go func() {
				klog.V(4).Info(log("waiting for volume %s to be unmapped/detached", token))
			}()
			// cant find vol id, then ok.
			if _, ok := devMap[token]; !ok {
				return nil
			}
		case <-timer.C:
			klog.Error(log("timed out while waiting for volume %s to be unmapped/detached", token))
			return fmt.Errorf("volume detach timeout")
		}
	}
}
934978
func (b *Buffer) Dequeue() (interface{}, error) {
	var ln int
	var item interface{}

	b.rw.Lock()
	{
		if ln = len(b.buffer); ln > 0 {
			item = b.buffer[0]
			b.buffer = b.buffer[1:]
		}
	}
	b.rw.Unlock()

	if ln == 0 {
		return nil, ErrBufferEmpty
	}

	return item, nil
}
736303
func FlushEventsToBQ(c context.Context) error {
	_, err := eventsLog.Flush(c)
	return err
}
1257526
func FlushEvents(minType, maxType uint32) {
	C.SDL_FlushEvents(C.Uint32(minType), C.Uint32(maxType))
}
448279
func (n *NetworkServerAPI) GetDeviceQueueItemsForDevEUI(ctx context.Context, req *ns.GetDeviceQueueItemsForDevEUIRequest) (*ns.GetDeviceQueueItemsForDevEUIResponse, error) {
	var devEUI lorawan.EUI64
	copy(devEUI[:], req.DevEui)

	items, err := storage.GetDeviceQueueItemsForDevEUI(storage.DB(), devEUI)
	if err != nil {
		return nil, errToRPCError(err)
	}

	var out ns.GetDeviceQueueItemsForDevEUIResponse
	for i := range items {
		qi := ns.DeviceQueueItem{
			DevAddr:    items[i].DevAddr[:],
			DevEui:     items[i].DevEUI[:],
			FrmPayload: items[i].FRMPayload,
			FCnt:       items[i].FCnt,
			FPort:      uint32(items[i].FPort),
			Confirmed:  items[i].Confirmed,
		}

		out.Items = append(out.Items, &qi)
	}

	return &out, nil
}
201695
func (p *Preemptor) PreemptForDevice(ask *structs.RequestedDevice, devAlloc *deviceAllocator) []*structs.Allocation {

	// Group allocations by device, tracking the number of
	// instances used in each device by alloc id
	deviceToAllocs := make(map[structs.DeviceIdTuple]*deviceGroupAllocs)
	for _, alloc := range p.currentAllocs {
		for _, tr := range alloc.AllocatedResources.Tasks {
			// Ignore allocs that don't use devices
			if len(tr.Devices) == 0 {
				continue
			}

			// Go through each assigned device group
			for _, device := range tr.Devices {
				// Look up the device instance from the device allocator
				deviceIdTuple := *device.ID()
				devInst := devAlloc.Devices[deviceIdTuple]

				// devInst can be nil if the device is no longer healthy
				if devInst == nil {
					continue
				}

				// Ignore if the device doesn't match the ask
				if !nodeDeviceMatches(p.ctx, devInst.Device, ask) {
					continue
				}

				// Store both the alloc and the number of instances used
				// in our tracking map
				allocDeviceGrp := deviceToAllocs[deviceIdTuple]
				if allocDeviceGrp == nil {
					allocDeviceGrp = newAllocDeviceGroup()
					deviceToAllocs[deviceIdTuple] = allocDeviceGrp
				}
				allocDeviceGrp.allocs = append(allocDeviceGrp.allocs, alloc)
				allocDeviceGrp.deviceInstances[alloc.ID] += len(device.DeviceIDs)
			}
		}
	}

	neededCount := ask.Count

	var preemptionOptions []*deviceGroupAllocs
	// Examine matching allocs by device
OUTER:
	for deviceIDTuple, allocsGrp := range deviceToAllocs {
		// First group and sort allocations using this device by priority
		allocsByPriority := filterAndGroupPreemptibleAllocs(p.jobPriority, allocsGrp.allocs)

		// Reset preempted count for this device
		preemptedCount := 0

		// Initialize slice of preempted allocations
		var preemptedAllocs []*structs.Allocation

		for _, grpAllocs := range allocsByPriority {
			for _, alloc := range grpAllocs.allocs {
				// Look up the device instance from the device allocator
				devInst := devAlloc.Devices[deviceIDTuple]

				// Add to preemption list because this device matches
				preemptedCount += allocsGrp.deviceInstances[alloc.ID]
				preemptedAllocs = append(preemptedAllocs, alloc)

				// Check if we met needed count
				if preemptedCount+devInst.FreeCount() >= int(neededCount) {
					preemptionOptions = append(preemptionOptions, &deviceGroupAllocs{
						allocs:          preemptedAllocs,
						deviceInstances: allocsGrp.deviceInstances,
					})
					continue OUTER
				}
			}
		}
	}

	// Find the combination of allocs with lowest net priority
	if len(preemptionOptions) > 0 {
		return selectBestAllocs(preemptionOptions, int(neededCount))
	}

	return nil
}
156349
func (s *LedisStore) Flush() error {
	s.lock.Lock()
	defer s.lock.Unlock()

	s.data = make(map[interface{}]interface{})
	return nil
}
1301544
func (d *driver) NextDevice(
	ctx types.Context,
	opts types.Store) (string, error) {

	var devFileRWL *sync.RWMutex
	func() {
		devFileLocksRWL.RLock()
		defer devFileLocksRWL.RUnlock()
		devFileRWL = devFileLocks[d.devFilePath]
	}()
	devFileRWL.Lock()
	defer devFileRWL.Unlock()

	if !gotil.FileExists(d.devFilePath) {
		return "", goof.New("device file missing")
	}

	f, err := os.Open(d.devFilePath)
	if err != nil {
		return "", err
	}
	defer f.Close()

	scn := bufio.NewScanner(f)
	for {
		if !scn.Scan() {
			break
		}

		m := avaiDevRX.FindSubmatch(scn.Bytes())
		if len(m) == 0 {
			continue
		}

		return string(m[1]), nil
	}

	return "", goof.New("no available devices")
}