gmutex

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

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

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

func New

func New() *Mutex

New creates and returns a new mutex.

func (*Mutex) IsLocked

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

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

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

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

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

func (m *Mutex) RLock()

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

func (*Mutex) RLockFunc

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

func (m *Mutex) RUnlock()

RUnlock unlocks the reading lock on the mutex. It is safe to be called multiple times even there's no locks.

func (*Mutex) TryLock

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

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

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

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

func (m *Mutex) Unlock()

Unlock unlocks writing lock on the mutex. It is safe to be called multiple times even there's no locks.

Jump to

Keyboard shortcuts

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