// isWaitable returns true if the process has exited false otherwise.
// Its based off blockUntilWaitable in src/os/wait_waitid.go
505235
func isWaitable(pid int) (bool, error) {
	si := &siginfo{}
	_, _, e := unix.Syscall6(unix.SYS_WAITID, _P_PID, uintptr(pid), uintptr(unsafe.Pointer(si)), unix.WEXITED|unix.WNOWAIT|unix.WNOHANG, 0, 0)
	if e != 0 {
		return false, os.NewSyscallError("waitid", e)
	}

	return si.si_pid != 0, nil
}
1331022
func (i *Instance) Wait(ctx context.Context, e Entry, reason string, p priority) (eh *EntryHandle) {
	eh = &EntryHandle{
		reason:   reason,
		e:        e,
		i:        i,
		priority: p,
		created:  time.Now(),
	}
	i.mu.Lock()
	hs, ok := i.entries[eh.e]
	if ok {
		hs[eh] = struct{}{}
		i.mu.Unlock()
		expvars.Add("waits for existing entry", 1)
		return
	}
	if i.noMaxEntries || len(i.entries) < i.maxEntries {
		i.entries[eh.e] = handles{
			eh: struct{}{},
		}
		i.mu.Unlock()
		expvars.Add("waits with space in table", 1)
		return
	}
	// Lock the mutex, so that a following Lock will block until it's unlocked by a wake event.
	eh.wake.Lock()
	i.addWaiter(eh)
	i.mu.Unlock()
	expvars.Add("waits that blocked", 1)
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	go func() {
		<-ctx.Done()
		i.mu.Lock()
		if _, ok := i.waiters[eh]; ok {
			i.deleteWaiter(eh)
			eh.wake.Unlock()
		}
		i.mu.Unlock()
	}()
	// Blocks until woken by an Unlock.
	eh.wake.Lock()
	i.mu.Lock()
	if _, ok := i.entries[eh.e][eh]; !ok {
		eh = nil
	}
	i.mu.Unlock()
	return
}
268290
func (s *DeleteByQueryService) WaitForCompletion(waitForCompletion bool) *DeleteByQueryService {
	s.waitForCompletion = &waitForCompletion
	return s
}
683122
func (p *grpcPeer) monitorLoopWait(ctx context.Context, cancel context.CancelFunc, connectivityState connectivity.State) (connectivity.State, bool) {
	changedC := make(chan bool, 1)
	go func() { changedC <- p.clientConn.WaitForStateChange(ctx, connectivityState) }()

	loop := false
	select {
	case changed := <-changedC:
		if cancel != nil {
			cancel()
		}
		if changed {
			connectivityState = p.clientConn.GetState()
		}
		loop = true
	case <-p.stoppingC:
	case <-p.t.once.Stopping():
		if cancel != nil {
			cancel()
		}
	}
	return connectivityState, loop
}
825923
func NewWaitingProof(isRemote bool, proof *lnwire.AnnounceSignatures) *WaitingProof {
	return &WaitingProof{
		AnnounceSignatures: proof,
		isRemote:           isRemote,
	}
}
83541
func WaitUntil(fn ConditionFn, timeout time.Duration) bool {
	deadline := time.Now().Add(timeout)
	for time.Now().Before(deadline) {
		if fn() {
			return true
		}
		time.Sleep(100 * time.Millisecond)
	}
	return false
}
1188115
func (p *Process) pingWait(addr string, timeout time.Duration) error {
	// Default to local process if addr not specified.
	if addr == "" {
		addr = fmt.Sprintf("localhost:%s", p.Port)
	}

	logger := p.Logger.New("fn", "pingWait", "addr", addr, "timeout", timeout)

	ticker := time.NewTicker(checkInterval)
	defer ticker.Stop()

	timer := time.NewTimer(timeout)
	defer timer.Stop()

	for {
		select {
		case <-timer.C:
			return ErrTimeout
		case <-ticker.C:
		}

		if err := p.ping(addr, timeout); err != nil {
			logger.Error("ping error", "err", err)
			continue
		}

		return nil
	}
}
314599
func (db *Database) IsBlocked(path string) (bool, error) {
	c := db.Pool.Get()
	defer c.Close()
	return redis.Bool(isBlockedScript.Do(c, path))
}
1251316
func (p *Process) StopAndWait() (*os.ProcessState, error) {
	if err := p.stopProcess(); err != nil {
		return nil, err
	}
	state, err := p.waitOnProcess()
	if err != nil {
		return nil, errors.Errorf("process exit with error: %v", err)
	}
	p.log.Debugf("Process %s was stopped (last PID: %d)", p.GetName(), p.GetPid())
	return state, nil
}
1199081
func (e *Element) WaitForReady() error {
	e.lock.RLock()
	ready := e.ready
	e.lock.RUnlock()

	if ready {
		return nil
	}

	timeout := time.NewTimer(e.tab.elementTimeout)
	defer timeout.Stop()

	select {
	case <-e.readyGate:
		return nil
	case <-timeout.C:
		return &ElementNotReadyErr{}
	}
}
566995
func (c *baseFlowController) IsNewlyBlocked() (bool, protocol.ByteCount) {
	if c.sendWindowSize() != 0 || c.sendWindow == c.lastBlockedAt {
		return false, 0
	}
	c.lastBlockedAt = c.sendWindow
	return true, c.sendWindow
}
1047815
func (p *StatusTable) IsRunning(name string) bool {
	p.RLock()
	defer p.RUnlock()

	return p.pool[name]
}
364100
func (h *jsonBasedHyperstart) WaitProcess(container, process string) int {
	h.Lock()
	pk := pKey{c: container, p: process}
	if ps, ok := h.procs[pk]; ok {
		if ps.waitChan == nil {
			ps.waitChan = make(chan int, 1)
			h.handleWaitProcess(pk, ps)
		}
		h.Unlock()
		status := <-ps.waitChan
		ps.waitChan <- status
		return status
	}
	h.Unlock()
	return -1
}
315024
func (opts *FlushOptions) SetWait(value bool) {
	C.rocksdb_flushoptions_set_wait(opts.c, boolToChar(value))
}
1029535
func (qm *QuotaMonitor) IsSynced() bool {
	qm.monitorLock.RLock()
	defer qm.monitorLock.RUnlock()

	if len(qm.monitors) == 0 {
		klog.V(4).Info("quota monitor not synced: no monitors")
		return false
	}

	for resource, monitor := range qm.monitors {
		if !monitor.controller.HasSynced() {
			klog.V(4).Infof("quota monitor not synced: %v", resource)
			return false
		}
	}
	return true
}
703434
func (p *Process) waitOnProcess() (*os.ProcessState, error) {
	if p.command == nil || p.command.Process == nil {
		return &os.ProcessState{}, nil
	}

	return p.command.Process.Wait()
}
564677
func pidWait(pid int) error {
	ticker := time.NewTicker(1 * time.Second)
	defer ticker.Stop()

	for range ticker.C {
		if !pidAlive(pid) {
			break
		}
	}

	return nil
}