decoderhandle

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package decoderhandle provides a small fixed-size pool of long-lived decoder.Decoder instances. Replaces the fac.New() / dec.Close() per-tile pattern with Borrow/Return, eliminating per-tile tjInit + tjDestroy churn (~290 µs/call dominated by tjDestroy).

Concurrency: Borrow blocks when all pool members are in use; Return is non-blocking. Pool members are not concurrent-safe (libjpeg-turbo tjhandle is single-threaded), so Borrow grants exclusive access for the lifetime of the borrow.

Lifetime: members are lazy-initialised on first Borrow. Close drains the pool and tears down every member. After Close, Borrow returns ErrClosed; Return on a closed pool tears the member down directly.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("decoderhandle: pool closed")

ErrClosed is returned by Borrow if Close has been called.

View Source
var ErrFactoryReturnedNil = errors.New("decoderhandle: factory.New() returned nil")

ErrFactoryReturnedNil is returned by Borrow if factory.New() returned nil. Surfaces what would otherwise be a nil-decoder panic in Decode.

Functions

This section is empty.

Types

type Pool

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

Pool is a fixed-size pool of decoder.Decoder instances.

func New

func New(fac decoder.Factory, capacity int) *Pool

New constructs a pool of capacity members for the given factory. capacity must be > 0; smaller values are clamped to 1. Members are NOT created up-front; the first Borrow that needs to grow the pool invokes factory.New().

func (*Pool) Borrow

func (p *Pool) Borrow() (decoder.Decoder, error)

Borrow acquires a Decoder. Blocks if all members are in use AND the pool is at capacity. Returns ErrClosed if Close has been called. Caller must call Return when done.

func (*Pool) Close

func (p *Pool) Close() error

Close drains and closes every member. Safe to call multiple times. In-flight Borrows blocked on the channel see channel-closed and return ErrClosed. Returns the first Decoder.Close error encountered during drain.

func (*Pool) Return

func (p *Pool) Return(d decoder.Decoder)

Return puts the Decoder back into the pool. Safe after Close (closes the Decoder directly in that case). Safe with d == nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL