Documentation ¶
Overview ¶
Package gmutex implements graceful concurrent-safe mutex with more rich features.
Index ¶
- type Mutex
- func (m *Mutex) IsLocked() bool
- func (m *Mutex) IsRLocked() bool
- func (m *Mutex) IsWLocked() bool
- func (m *Mutex) Lock()
- func (m *Mutex) LockFunc(f func())
- func (m *Mutex) RLock()
- func (m *Mutex) RLockFunc(f func())
- func (m *Mutex) RUnlock()
- func (m *Mutex) TryLock() bool
- func (m *Mutex) TryLockFunc(f func()) (result bool)
- func (m *Mutex) TryRLock() bool
- func (m *Mutex) TryRLockFunc(f func()) (result bool)
- func (m *Mutex) Unlock()
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
}
The high level Mutex, which implements more rich features for mutex.
func (*Mutex) IsLocked ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.