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

package gmutex

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

Package gmutex implements graceful concurrent-safe mutex with more rich features.

Index

Package Files

gmutex.go

type Mutex Uses

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

The high level Mutex, which implements more rich features for mutex.

func New Uses

func New() *Mutex

New creates and returns a new mutex.

func (*Mutex) IsLocked Uses

func (m *Mutex) IsLocked() bool

IsLocked checks whether the mutex is locked with writing or reading lock. Note that the result might be changed after it's called, so it cannot be the criterion for atomic operations.

func (*Mutex) IsRLocked Uses

func (m *Mutex) IsRLocked() bool

IsRLocked checks whether the mutex is locked by reading lock. Note that the result might be changed after it's called, so it cannot be the criterion for atomic operations.

func (*Mutex) IsWLocked Uses

func (m *Mutex) IsWLocked() bool

IsWLocked checks whether the mutex is locked by writing lock. Note that the result might be changed after it's called, so it cannot be the criterion for atomic operations.

func (*Mutex) Lock Uses

func (m *Mutex) Lock()

Lock locks the mutex for writing purpose. If the mutex is already locked by another goroutine for reading or writing, it blocks until the lock is available.

func (*Mutex) LockFunc Uses

func (m *Mutex) LockFunc(f func())

LockFunc locks the mutex for writing with given callback function <f>. If there's a write/reading lock the mutex, it will blocks until the lock is released.

It releases the lock after <f> is executed.

func (*Mutex) RLock Uses

func (m *Mutex) RLock()

RLock locks mutex for reading purpose purpose. If the mutex is already locked for writing, it blocks until the lock is available.

func (*Mutex) RLockFunc Uses

func (m *Mutex) RLockFunc(f func())

RLockFunc locks the mutex for reading with given callback function <f>. If there's a writing lock the mutex, it will blocks until the lock is released.

It releases the lock after <f> is executed.

func (*Mutex) RUnlock Uses

func (m *Mutex) RUnlock()

RUnlock unlocks the reading lock on the mutex. It is safe to be called multiple times if there's any locks or not.

func (*Mutex) TryLock Uses

func (m *Mutex) TryLock() bool

TryLock tries locking the mutex for writing purpose. It returns true immediately if success, or if there's a write/reading lock on the mutex, it returns false immediately.

func (*Mutex) TryLockFunc Uses

func (m *Mutex) TryLockFunc(f func()) (result bool)

TryLockFunc tries locking the mutex for writing with given callback function <f>. it returns true immediately if success, or if there's a write/reading lock on the mutex, it returns false immediately.

It releases the lock after <f> is executed.

func (*Mutex) TryRLock Uses

func (m *Mutex) TryRLock() bool

TryRLock tries locking the mutex for reading purpose. It returns true immediately if success, or if there's a writing lock on the mutex, it returns false immediately.

func (*Mutex) TryRLockFunc Uses

func (m *Mutex) TryRLockFunc(f func()) (result bool)

TryRLockFunc tries locking the mutex for reading with given callback function <f>. It returns true immediately if success, or if there's a writing lock on the mutex, it returns false immediately.

It releases the lock after <f> is executed.

func (*Mutex) Unlock Uses

func (m *Mutex) Unlock()

Unlock unlocks writing lock on the mutex. It is safe to be called multiple times if there's any locks or not.

Package gmutex imports 3 packages (graph) and is imported by 2 packages. Updated 2019-07-20. Refresh now. Tools for package owners.