localpool

package
v2.1.46 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry[K comparable] struct {
	// contains filtered or unexported fields
}

func (*Entry[K]) Done

func (e *Entry[K]) Done()

func (*Entry[K]) Lock

func (e *Entry[K]) Lock()

func (*Entry[K]) RLock

func (e *Entry[K]) RLock()

func (*Entry[K]) RUnlock

func (e *Entry[K]) RUnlock()

func (*Entry[K]) TryLock

func (e *Entry[K]) TryLock() bool

func (*Entry[K]) TryRLock

func (e *Entry[K]) TryRLock() bool

func (*Entry[K]) Unlock

func (e *Entry[K]) Unlock()

type RWLockPool

type RWLockPool[K comparable] struct {
	// contains filtered or unexported fields
}

RWLockPool 维护按 Key 分配的 *sync.RWMutex,并在空闲超过 ttl 后回收。

func NewRWLockPool

func NewRWLockPool[K comparable](ttl, sweep time.Duration) *RWLockPool[K]

NewRWLockPool 创建带定期清理的锁池。 ttl: 锁在 无人持有(refs=0) 状态下允许存活的时间 sweep: 清理周期;建议为 ttl 的 1/2~1/5

func (*RWLockPool[K]) Acquire

func (p *RWLockPool[K]) Acquire(key K) *Entry[K]

func (*RWLockPool[K]) Close

func (p *RWLockPool[K]) Close()

Close 停止清理器并清空池子(不会强制打断正在持有的锁)。

func (*RWLockPool[K]) Len

func (p *RWLockPool[K]) Len() int

func (*RWLockPool[K]) WithLock

func (p *RWLockPool[K]) WithLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, dest any) error

func (*RWLockPool[K]) WithRLock

func (p *RWLockPool[K]) WithRLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, dest any) error

func (*RWLockPool[K]) WithTryLock

func (p *RWLockPool[K]) WithTryLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, dest any) (result bool, err error)

func (*RWLockPool[K]) WithTryRLock

func (p *RWLockPool[K]) WithTryRLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, dest any) (result bool, err error)

Jump to

Keyboard shortcuts

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