gmlock

package
v2.8.6 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package gmlock implements a concurrent-safe memory-based locker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lock

func Lock(key string)

Lock locks the `key` with writing lock. If there's a write/reading lock the `key`, it will blocks until the lock is released.

func LockFunc

func LockFunc(key string, f func())

LockFunc locks the `key` with writing lock and callback function `f`. If there's a write/reading lock the `key`, it will blocks until the lock is released.

It releases the lock after `f` is executed.

func RLock

func RLock(key string)

RLock locks the `key` with reading lock. If there's a writing lock on `key`, it will blocks until the writing lock is released.

func RLockFunc

func RLockFunc(key string, f func())

RLockFunc locks the `key` with reading lock and callback function `f`. If there's a writing lock the `key`, it will blocks until the lock is released.

It releases the lock after `f` is executed.

func RUnlock

func RUnlock(key string)

RUnlock unlocks the reading lock of the `key`.

func Remove

func Remove(key string)

Remove removes mutex with given `key`.

func TryLock

func TryLock(key string) bool

TryLock tries locking the `key` with writing lock, it returns true if success, or if there's a write/reading lock the `key`, it returns false.

func TryLockFunc

func TryLockFunc(key string, f func()) bool

TryLockFunc locks the `key` with writing lock and callback function `f`. It returns true if success, or else if there's a write/reading lock the `key`, it return false.

It releases the lock after `f` is executed.

func TryRLock

func TryRLock(key string) bool

TryRLock tries locking the `key` with reading lock. It returns true if success, or if there's a writing lock on `key`, it returns false.

func TryRLockFunc

func TryRLockFunc(key string, f func()) bool

TryRLockFunc locks the `key` with reading lock and callback function `f`. It returns true if success, or else if there's a writing lock the `key`, it returns false.

It releases the lock after `f` is executed.

func Unlock

func Unlock(key string)

Unlock unlocks the writing lock of the `key`.

Types

type Locker

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

Locker is a memory based locker. Note that there's no cache expire mechanism for mutex in locker. You need remove certain mutex manually when you do not want use it anymore.

func New

func New() *Locker

New creates and returns a new memory locker. A memory locker can lock/unlock with dynamic string key.

func (*Locker) Clear

func (l *Locker) Clear()

Clear removes all mutexes from locker.

func (*Locker) Lock

func (l *Locker) Lock(key string)

Lock locks the `key` with writing lock. If there's a write/reading lock the `key`, it will block until the lock is released.

func (*Locker) LockFunc

func (l *Locker) LockFunc(key string, f func())

LockFunc locks the `key` with writing lock and callback function `f`. If there's a write/reading lock the `key`, it will block until the lock is released.

It releases the lock after `f` is executed.

func (*Locker) RLock

func (l *Locker) RLock(key string)

RLock locks the `key` with reading lock. If there's a writing lock on `key`, it will blocks until the writing lock is released.

func (*Locker) RLockFunc

func (l *Locker) RLockFunc(key string, f func())

RLockFunc locks the `key` with reading lock and callback function `f`. If there's a writing lock the `key`, it will block until the lock is released.

It releases the lock after `f` is executed.

func (*Locker) RUnlock

func (l *Locker) RUnlock(key string)

RUnlock unlocks the reading lock of the `key`.

func (*Locker) Remove

func (l *Locker) Remove(key string)

Remove removes mutex with given `key` from locker.

func (*Locker) TryLock

func (l *Locker) TryLock(key string) bool

TryLock tries locking the `key` with writing lock, it returns true if success, or it returns false if there's a writing/reading lock the `key`.

func (*Locker) TryLockFunc

func (l *Locker) TryLockFunc(key string, f func()) bool

TryLockFunc locks the `key` with writing lock and callback function `f`. It returns true if success, or else if there's a write/reading lock the `key`, it return false.

It releases the lock after `f` is executed.

func (*Locker) TryRLock

func (l *Locker) TryRLock(key string) bool

TryRLock tries locking the `key` with reading lock. It returns true if success, or if there's a writing lock on `key`, it returns false.

func (*Locker) TryRLockFunc

func (l *Locker) TryRLockFunc(key string, f func()) bool

TryRLockFunc locks the `key` with reading lock and callback function `f`. It returns true if success, or else if there's a writing lock the `key`, it returns false.

It releases the lock after `f` is executed.

func (*Locker) Unlock

func (l *Locker) Unlock(key string)

Unlock unlocks the writing lock of the `key`.

Jump to

Keyboard shortcuts

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