styx: aqwari.net/net/styx/internal/pool Index | Files

package pool

import "aqwari.net/net/styx/internal/pool"

Package pool manages pools of integer identifiers.

The pool package provides a thread-safe allocator for unique 32-bit integers. It is used to manage fid and tag pools for 9P clients.

Index

Package Files

pool.go

Constants

const (
    FidPoolCeiling = 1<<32 - 1
    TagPoolCeiling = 1<<16 - 1
)

type FidPool Uses

type FidPool struct {
    // contains filtered or unexported fields
}

A FidPool maintains a pool of free identifiers. It is safe for concurrent use. The zero value of a FidPool is an empty pool that will provide identifiers in the range [0, DefaultFidPoolSize).

func (*FidPool) Free Uses

func (p *FidPool) Free(old uint32)

Free releases a fid. After Free returns, it is valid for subsequent calls to Get on the same pool to return old. Free may only be called once for any given fid.

func (*FidPool) Get Uses

func (p *FidPool) Get() (fid uint32, ok bool)

Get retrieves a free identifier from a FidPool. If the pool is full, the second return value of Get will be false. Once an identifier is no longer needed, it must be released using the Free method. The return value is guaranteed to be less than FidPoolCeiling.

func (*FidPool) MustGet Uses

func (p *FidPool) MustGet() uint32

MustGet is like Get, but panics if the pool is full.

type TagPool Uses

type TagPool struct {
    // contains filtered or unexported fields
}

A TagPool is suitable for allocating tags for 9P messages.

func (*TagPool) Free Uses

func (p *TagPool) Free(old uint16)

Free releases a tag. After Free returns, it is valid for subsequent calls to Get on the same pool to return old. Free may only be called once for any given tag.

func (*TagPool) Get Uses

func (p *TagPool) Get() (tag uint16, ok bool)

Get retrieves a free identifier from a TagPool. If the pool is full, the second return value of Get will be false. Once an identifier is no longer needed, it must be released using the Free method. The return value is guaranteed to be less than TagPoolCeiling.

func (*TagPool) MustGet Uses

func (p *TagPool) MustGet() uint16

MustGet is like Get, but panics if the pool is full.

Bugs

The pool implementation allocates numbers in a contiguous sequence from [0, max). When a number X is Free'd, but is not at the end of the sequence, the FidPool implementation cannot use it until all allocated numbers greater than X have also been freed. While this can result in FidPools becoming full prematurely for certain pathological workloads, this tradeoff allows a FidPool to be simple, and small, and allows the Get implementation to be lock-free. Because clients are responsible for managing their own pools of identifiers, it cannot exploit this implementation to harm a server.

Package pool imports 3 packages (graph). Updated 2018-04-27. Refresh now. Tools for package owners.