Documentation
¶
Index ¶
- type Entry
- type RWLockPool
- func (p *RWLockPool[K]) Acquire(key K) *Entry[K]
- func (p *RWLockPool[K]) Close()
- func (p *RWLockPool[K]) Len() int
- func (p *RWLockPool[K]) WithLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, ...) error
- func (p *RWLockPool[K]) WithRLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, ...) error
- func (p *RWLockPool[K]) WithTryLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, ...) (result bool, err error)
- func (p *RWLockPool[K]) WithTryRLock(ctx context.Context, key K, fn func(ctx context.Context, dest any) error, ...) (result bool, err error)
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 }
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]) Len ¶
func (p *RWLockPool[K]) Len() int
func (*RWLockPool[K]) WithTryLock ¶
Click to show internal directories.
Click to hide internal directories.