pool

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextPool

type ContextPool struct {
	// Pool of context objects
	*Pool
	// contains filtered or unexported fields
}

ContextPool is a pool of context objects

func NewContextPool

func NewContextPool(path string, max int, gpu int) *ContextPool

Create a new context pool of context objects, up to 'max' items Set the path for the model storage If GPU is -1 then disable, if 0 then use default, if >0 then enable and use the specified device

func (*ContextPool) Close

func (m *ContextPool) Close() error

Close the pool and release all resources

func (*ContextPool) Drain

func (m *ContextPool) Drain(model *schema.Model) error

Drain the pool of all contexts for a model, freeing resources

func (*ContextPool) Get

func (m *ContextPool) Get(model *schema.Model) (*task.Context, error)

Get a context from the pool, for a model

func (*ContextPool) MarshalJSON

func (m *ContextPool) MarshalJSON() ([]byte, error)

func (*ContextPool) Put

func (m *ContextPool) Put(ctx *task.Context)

Put a context back into the pool

func (*ContextPool) String

func (m *ContextPool) String() string

type NewFunc

type NewFunc func() any

Create a new object to place in the pool

type Pool

type Pool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Pool is a pool of context objects, up to a maximum number This acts as a cache so we don't need to reload models If the pool is full, then Get will return nil

func NewPool

func NewPool(max int, fn NewFunc) *Pool

Create a new pool of context objects, up to 'max' objects

func (*Pool) Close

func (m *Pool) Close() error

func (*Pool) Get

func (m *Pool) Get() any

Returns an item, or nil if the maximum number of contexts has been reached

func (*Pool) N

func (m *Pool) N() int

Return the number of contexts in the pool

func (*Pool) Put

func (m *Pool) Put(ctx any)

Puts the context back in the pool

Jump to

Keyboard shortcuts

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