lock

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: BSD-3-Clause Imports: 9 Imported by: 3 modules, 9 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Await

type Await[T any] struct {
	// contains filtered or unexported fields
}

Await is a generic wait group implementation that allows setting channels for different keys.

func NewAwait

func NewAwait[T any](muxlimit int) *Await[T]

NewAwait initializes and returns a new Await instance.

func (*Await[T]) Close added in v0.1.9

func (at *Await[T]) Close(idx int64) (err error)

Close deletes and closes the channel associated with the given index.

func (*Await[T]) CloseAndPut added in v0.1.9

func (at *Await[T]) CloseAndPut(idx int64, v T) (err error)

CloseAndPut sends a value to the channel and deletes it from the map.

func (*Await[T]) Get

func (at *Await[T]) Get(idx int64) (ch chan T)

Get retrieves or creates a channel associated with the given index.

func (*Await[T]) Has

func (at *Await[T]) Has(idx int64) bool

Has checks if a channel exists for the given index.

func (*Await[T]) SyncWait added in v0.2.0

func (at *Await[T]) SyncWait(wg *sync.WaitGroup, idx int64, timeout time.Duration) (r T, err error)

SyncWait wait for the channel data to return or close, and set the timeout period

func (*Await[T]) Wait added in v0.1.9

func (at *Await[T]) Wait(idx int64, timeout time.Duration) (r T, err error)

Wait wait for the channel data to return or close, and set the timeout period

func (*Await[T]) WaitWithCancel added in v0.1.9

func (at *Await[T]) WaitWithCancel(ctx context.Context, idx int64, timeout time.Duration) (r T, isCancel bool, err error)

WaitWithCancel wait for the channel data to return or close, and set the timeout period

type FastAwait added in v0.2.0

type FastAwait[T any] struct {
	// contains filtered or unexported fields
}

func NewFastAwait added in v0.2.0

func NewFastAwait[T any]() *FastAwait[T]

func NewFastAwait2 added in v0.2.0

func NewFastAwait2[T any](expectedItems uint64) *FastAwait[T]

func (*FastAwait[T]) Close added in v0.2.0

func (fa *FastAwait[T]) Close(syncId int64) (err error)

func (*FastAwait[T]) CloseAndPut added in v0.2.0

func (fa *FastAwait[T]) CloseAndPut(syncId int64, v T) (err error)

func (*FastAwait[T]) Wait added in v0.2.0

func (fa *FastAwait[T]) Wait(syncId int64, timeout time.Duration) (r T, err error)

func (*FastAwait[T]) WaitWithCancel added in v0.2.0

func (fa *FastAwait[T]) WaitWithCancel(ctx context.Context, syncId int64, timeout time.Duration) (r T, cancel bool, err error)

type LimitLock

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

LimitLock limits the number of concurrent operations and can enforce timeouts.

func NewLimitLock

func NewLimitLock(limit int, timeout time.Duration) *LimitLock

NewLimitLock initializes and returns a new LimitLock instance.

func (*LimitLock) Cc

func (ll *LimitLock) Cc() int64

Cc returns the current concurrency count.

func (*LimitLock) Lock

func (ll *LimitLock) Lock() (err error)

Lock acquires a lock with a timeout.

func (*LimitLock) LockCount

func (ll *LimitLock) LockCount() int64

LockCount returns the total number of lock acquisitions.

func (*LimitLock) Unlock

func (ll *LimitLock) Unlock()

Unlock releases a lock.

type Numlock

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

Numlock provides a set of mutex locks based on integer keys.

func NewNumLock

func NewNumLock(muxNum int) *Numlock

NewNumLock initializes and returns a new Numlock instance.

func (*Numlock) Lock

func (nl *Numlock) Lock(key int64) *sync.Mutex

Lock acquires the lock associated with the given key.

func (*Numlock) TryLock added in v0.2.1

func (nl *Numlock) TryLock(key int64) (*sync.Mutex, bool)

TryLock try to acquire the lock associated with the given key.

func (*Numlock) Unlock

func (nl *Numlock) Unlock(key int64)

Unlock releases the lock associated with the given key.

type Strlock

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

Strlock provides a set of read-write mutex locks based on string keys.

func NewStrlock

func NewStrlock(muxNum int) *Strlock

NewStrlock initializes and returns a new Strlock instance.

func (*Strlock) Lock

func (sl *Strlock) Lock(key string) *sync.RWMutex

Lock acquires the write lock associated with the given key.

func (*Strlock) RLock

func (sl *Strlock) RLock(key string) *sync.RWMutex

RLock acquires the read lock associated with the given key.

func (*Strlock) RUnlock

func (sl *Strlock) RUnlock(key string)

RUnlock releases the read lock associated with the given key.

func (*Strlock) TryLock added in v0.2.1

func (sl *Strlock) TryLock(key string) (*sync.RWMutex, bool)

TryLock try to acquire the write lock associated with the given key.

func (*Strlock) TryRLock added in v0.2.1

func (sl *Strlock) TryRLock(key string) (*sync.RWMutex, bool)

TryRLock try to acquire the read lock associated with the given key.

func (*Strlock) Unlock

func (sl *Strlock) Unlock(key string)

Unlock releases the write lock associated with the given key.

Jump to

Keyboard shortcuts

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