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
    }
















  • 相关阅读:
    pgpoolII3.1 的内存泄漏(二)
    iOS 开发的一些网址
    ios开发必备第三方库
    iOS截屏方法
    ios开发第三方库cocoapods安装
    iOS开发知识点总结
    iOS开发文件夹Copy items if needed
    iOS开源库最全的整理
    iOS图标抖动效果
    iOS 加密的3种方法
  • 原文地址:https://www.cnblogs.com/rsapaper/p/13930446.html
Copyright © 2011-2022 走看看