lock

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

type Locker interface {
	// Lock try locking object, return err if fails.
	Lock() error
	// Unlock unlock object lock, if fail return err
	Unlock() error
	// TryLock will try to lock object and return whether it succeed or not without blocking.
	TryLock() bool
}

func NewFileLock

func NewFileLock(fileName string) (Locker, error)

NewFileLock create new file lock instance

func NewMemoryLock

func NewMemoryLock() (Locker, error)

NewMemoryLock create new memory lock instance

type MemoryLock

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

MemoryLock implements sync/Locker, default 0 indicates an unlocked memory.

func (*MemoryLock) Lock

func (sl *MemoryLock) Lock() error

Lock locks memory. If the lock is locked before, the caller will be blocked until unlocked.

func (*MemoryLock) TryLock

func (sl *MemoryLock) TryLock() bool

TryLock will try to lock memory and return whether it succeed or not without blocking.

func (*MemoryLock) Unlock

func (sl *MemoryLock) Unlock() error

Unlock unlocks memory, this operation is reentrant。

Jump to

Keyboard shortcuts

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