gf: github.com/gogf/gf/g/os/gmlock Index | Files

package gmlock

import "github.com/gogf/gf/g/os/gmlock"

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

Index

Package Files

gmlock.go gmlock_locker.go

func Lock Uses

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 Uses

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 Uses

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 Uses

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 Uses

func RUnlock(key string)

RUnlock unlocks the reading lock of the <key>.

func Remove Uses

func Remove(key string)

Remove removes mutex with given <key>.

func TryLock Uses

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 Uses

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 Uses

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 Uses

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 Uses

func Unlock(key string)

Unlock unlocks the writing lock of the <key>.

type Locker Uses

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

Memory 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 any more.

func New Uses

func New() *Locker

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

func (*Locker) Clear Uses

func (l *Locker) Clear()

Clear removes all mutexes from locker.

func (*Locker) Lock Uses

func (l *Locker) 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 (*Locker) LockFunc Uses

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 blocks until the lock is released.

It releases the lock after <f> is executed.

func (*Locker) RLock Uses

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 Uses

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 blocks until the lock is released.

It releases the lock after <f> is executed.

func (*Locker) RUnlock Uses

func (l *Locker) RUnlock(key string)

RUnlock unlocks the reading lock of the <key>.

func (*Locker) Remove Uses

func (l *Locker) Remove(key string)

Remove removes mutex with given <key> from locker.

func (*Locker) TryLock Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (l *Locker) Unlock(key string)

Unlock unlocks the writing lock of the <key>.

Package gmlock imports 2 packages (graph) and is imported by 3 packages. Updated 2019-06-27. Refresh now. Tools for package owners.