Documentation ¶
Overview ¶
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 ¶
Constants ¶
const ( FidPoolCeiling = 1<<32 - 1 TagPoolCeiling = 1<<16 - 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FidPool ¶
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 ¶
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.
type TagPool ¶
type TagPool struct {
// contains filtered or unexported fields
}
A TagPool is suitable for allocating tags for 9P messages.
func (*TagPool) Free ¶
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.
Notes ¶
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.