// MarkIdle marks the given connection as being idle, and therefore eligible for
// closing at any time. The passed connection must have been returned by a call
// to Accept from this listener.
337824
func MarkIdle(c net.Conn) error {
	if cn, ok := c.(*conn); ok {
		cn.markIdle()
		return nil
	}
	return errNotManaged
}
60771
func (c *ChatPostMessageCall) Markdown(markdown bool) *ChatPostMessageCall {
	c.markdown = markdown
	return c
}
1221792
func (c *Conn) Close() (err error) {
	c.mux.Lock()
	defer c.mux.Unlock()

	if c.status < connStatusIdle {
		return nil
	}
	c.status = connStatusClosed

	defer func() {
		c.conn.Close()
		c.causeOfDeath = errors.New("Closed")
		if c.shouldLog(LogLevelInfo) {
			c.log(LogLevelInfo, "closed connection", nil)
		}
	}()

	err = c.conn.SetDeadline(time.Time{})
	if err != nil && c.shouldLog(LogLevelWarn) {
		c.log(LogLevelWarn, "failed to clear deadlines to send close message", map[string]interface{}{"err": err})
		return err
	}

	_, err = c.conn.Write([]byte{'X', 0, 0, 0, 4})
	if err != nil && c.shouldLog(LogLevelWarn) {
		c.log(LogLevelWarn, "failed to send terminate message", map[string]interface{}{"err": err})
		return err
	}

	err = c.conn.SetReadDeadline(time.Now().Add(5 * time.Second))
	if err != nil && c.shouldLog(LogLevelWarn) {
		c.log(LogLevelWarn, "failed to set read deadline to finish closing", map[string]interface{}{"err": err})
		return err
	}

	_, err = c.conn.Read(make([]byte, 1))
	if err != io.EOF {
		return err
	}

	return nil
}
544356
func (p *prober) markIPsLocked() {
	for ip, node := range p.nodes {
		node.deletionMark = true
		p.nodes[ip] = node
	}
}
1012857
func (t *templateHandler) MarkReady() error {
	if err := t.postTransform(); err != nil {
		return err
	}

	if t.html.clone == nil {
		t.html.clone = template.Must(t.html.t.Clone())
		t.html.cloneClone = template.Must(t.html.clone.Clone())
	}
	if t.text.clone == nil {
		t.text.clone = texttemplate.Must(t.text.t.Clone())
		t.text.cloneClone = texttemplate.Must(t.text.clone.Clone())
	}

	return nil
}
626074
func (c *cluster) markDown(endpoint string) {
	c.Lock()
	defer c.Unlock()
	for _, n := range c.members {
		// step: check if this is the node and it's marked as up - The double  checking on the
		// nodes status ensures the multiple calls don't create multiple checks
		if n.status == memberStatusUp && n.endpoint == endpoint {
			n.status = memberStatusDown
			go c.healthCheckNode(n)
			break
		}
	}
}
696114
func (lb *LogBroker) markDone(sub *subscription, nodeID string, err error) {
	lb.mu.Lock()
	defer lb.mu.Unlock()

	// remove the subscription from the node's subscription list, if it exists
	if _, ok := lb.subscriptionsByNode[nodeID]; ok {
		delete(lb.subscriptionsByNode[nodeID], sub)
	}

	// mark the sub as done
	sub.Done(nodeID, err)
}
117169
func (e *Engine) IsIdle() bool {
	cacheEmpty := e.Cache.Size() == 0
	return cacheEmpty && e.compactionTracker.AllActive() == 0 && e.CompactionPlan.FullyCompacted()
}
1188012
func (c *conn) MarkAsDead() {
	c.Lock()
	c.dead = true
	if c.deadSince == nil {
		utcNow := time.Now().UTC()
		c.deadSince = &utcNow
	}
	c.failures += 1
	c.Unlock()
}
1190007
func (p *simpleResourcePool) queueIdleHandles(handle interface{}) {
	var toClose []*idleHandle
	defer func() {
		// NOTE: Must keep the closure around to late bind the toClose slice.
		p.closeHandles(toClose)
	}()

	now := p.options.getCurrentTime()
	var keepUntil *time.Time
	if p.options.MaxIdleTime != nil {
		// NOTE: Assign to temp variable first to work around compiler bug
		x := now.Add(*p.options.MaxIdleTime)
		keepUntil = &x
	}

	p.mutex.Lock()
	defer p.mutex.Unlock()

	if p.isLameDuck {
		toClose = []*idleHandle{
			{handle: handle},
		}
		return
	}

	p.idleHandles = append(
		p.idleHandles,
		&idleHandle{
			handle:    handle,
			keepUntil: keepUntil,
		})

	nIdleHandles := uint32(len(p.idleHandles))
	if nIdleHandles > p.options.MaxIdleHandles {
		handlesToClose := nIdleHandles - p.options.MaxIdleHandles
		toClose = p.idleHandles[0:handlesToClose]
		p.idleHandles = p.idleHandles[handlesToClose:nIdleHandles]
	}
}
84053
func (h *singleConnectionHeap) DropIdleTail() bool {
	h.mutex.Lock()
	defer h.mutex.Unlock()

	// if heap is not empty
	if h.full || (h.tail != h.head) {
		conn := h.data[(h.tail+1)%h.size]

		if conn.IsConnected() && !conn.isIdle() {
			return false
		}

		h.tail = (h.tail + 1) % h.size
		h.data[h.tail] = nil
		h.full = false
		conn.Close()

		return true
	}

	return false
}
886771
func (s *channelStates) markEnabled(outpoint wire.OutPoint) {
	(*s)[outpoint] = ChannelState{
		Status: ChanStatusEnabled,
	}
}
401464
func (c *conn) MarkAsAlive() {
	c.Lock()
	c.dead = false
	c.Unlock()
}
1009106
func (ps *peerSet) BodyIdlePeers() ([]*peerConnection, int) {
	idle := func(p *peerConnection) bool {
		return atomic.LoadInt32(&p.blockIdle) == 0
	}
	throughput := func(p *peerConnection) float64 {
		p.lock.RLock()
		defer p.lock.RUnlock()
		return p.blockThroughput
	}
	return ps.idlePeers(62, 64, idle, throughput)
}
361072
func (p *peerConnection) MarkLacking(hash common.Hash) {
	p.lock.Lock()
	defer p.lock.Unlock()

	for len(p.lacking) >= maxLackingHashes {
		for drop := range p.lacking {
			delete(p.lacking, drop)
			break
		}
	}
	p.lacking[hash] = struct{}{}
}
203740
func (c *OpenChannel) MarkAsOpen(openLoc lnwire.ShortChannelID) error {
	c.Lock()
	defer c.Unlock()

	if err := c.Db.Update(func(tx *bbolt.Tx) error {
		chanBucket, err := fetchChanBucket(
			tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
		)
		if err != nil {
			return err
		}

		channel, err := fetchOpenChannel(chanBucket, &c.FundingOutpoint)
		if err != nil {
			return err
		}

		channel.IsPending = false
		channel.ShortChannelID = openLoc

		return putOpenChannel(chanBucket, channel)
	}); err != nil {
		return err
	}

	c.IsPending = false
	c.ShortChannelID = openLoc
	c.Packager = NewChannelPackager(openLoc)

	return nil
}
364165
func (m *collection) idleMergerWaker() {
	idleTimeout := m.options.MergerIdleRunTimeoutMS
	if idleTimeout == 0 {
		idleTimeout = DefaultCollectionOptions.MergerIdleRunTimeoutMS
	}
	if idleTimeout <= 0 { // -1 will disable idle compactions.
		return
	}
	var prevRunID uint64 // Helps run idle merger IFF new data has come in.
	for {
		if atomic.LoadUint64(&m.stats.TotCloseBeg) > 0 {
			return
		}
		atomic.AddUint64(&m.stats.TotMergerIdleSleeps, 1)
		napIDBefore := atomic.LoadUint64(&m.stats.TotMergerWaitIncomingEnd)

		time.Sleep(time.Duration(idleTimeout) * time.Millisecond)

		napIDAfter := atomic.LoadUint64(&m.stats.TotMergerWaitIncomingEnd)
		napID := atomic.LoadUint64(&m.stats.TotMergerWaitIncomingBeg)
		if napID == napIDAfter+1 && // Merger is indeed asleep.
			napIDBefore == napIDAfter && // Nap only while merger naps.
			atomic.LoadUint64(&m.stats.TotMergerInternalEnd) > prevRunID { // New data.
			m.NotifyMerger("from-idle-merger", false)
			prevRunID = atomic.LoadUint64(&m.stats.TotMergerInternalEnd)
		}
	}
}