github.com/hsfzxjy/dgo/go@v0.2.0/pin/pchan/listener.go (about)

     1  package pchan
     2  
     3  import (
     4  	"sync"
     5  
     6  	dgo "github.com/hsfzxjy/dgo/go"
     7  )
     8  
     9  type listener struct {
    10  	chid uint8
    11  	lid  uint8
    12  	dcb  uint32
    13  	port *dgo.Port
    14  
    15  	next *listener
    16  }
    17  
    18  func (l *listener) free() {
    19  	p := l
    20  	for p != nil {
    21  		q := p.next
    22  		p.recycle()
    23  		p = q
    24  	}
    25  }
    26  
    27  var listenerPool = sync.Pool{
    28  	New: func() any { return new(listener) },
    29  }
    30  
    31  func listenerNew() *listener { return listenerPool.Get().(*listener) }
    32  func (l *listener) recycle() {
    33  	l.next = nil
    34  	l.port = nil
    35  	listenerPool.Put(l)
    36  }