zoukankan      html  css  js  c++  java
  • 源码 链表 连接池


    vendor/go.mongodb.org/mongo-driver/x/mongo/driver/session/session_pool.go:17


    // Node represents a server session in a linked list
    type Node struct {
    *Server
    next *Node
    prev *Node
    }

    // Pool is a pool of server sessions that can be reused.
    type Pool struct {
    descChan <-chan description.Topology
    head *Node
    tail *Node
    timeout uint32
    mutex sync.Mutex // mutex to protect list and sessionTimeout

    checkedOut int // number of sessions checked out of pool
    }



    vendor/go.mongodb.org/mongo-driver/x/mongo/driver/session/session_pool.go:103



    // ReturnSession returns a session to the pool if it has not expired.
    func (p *Pool) ReturnSession(ss *Server) {
    if ss == nil {
    return
    }

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

    p.checkedOut--
    p.updateTimeout()
    // check sessions at end of queue for expired
    // stop checking after hitting the first valid session
    for p.tail != nil && p.tail.expired(p.timeout) {
    if p.tail.prev != nil {
    p.tail.prev.next = nil
    }
    p.tail = p.tail.prev
    }

    // session expired
    if ss.expired(p.timeout) {
    return
    }

    // session is dirty
    if ss.Dirty {
    return
    }

    newNode := &Node{
    Server: ss,
    next: nil,
    prev: nil,
    }

    // empty list
    if p.tail == nil {
    p.head = newNode
    p.tail = newNode
    return
    }

    // at least 1 valid session in list
    newNode.next = p.head
    p.head.prev = newNode
    p.head = newNode
    }
















  • 相关阅读:
    spring aop
    Linux进程管理命令
    逻辑卷管理-LVM(Logical Volume Manager)
    Linux磁盘与文件系统管理(二)
    Linux磁盘与文件系统管理(一)
    Linux后台运行和关闭、查看后台任务
    Linux用户管理及用户信息查询
    文件备份与压缩
    Liunx信息显示与文件搜索
    文本处理三剑客之 awk
  • 原文地址:https://www.cnblogs.com/rsapaper/p/13930446.html
Copyright © 2011-2022 走看看