upgrademu

package
v0.48.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RWMutex

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

RWMutex is an enhanced version of the standard sync.RWMutex. It has the all methods sync.RWMutex with exact same semantics. It gives more methods to give upgradable-read feature.

The new semantics for upgradable-read are as follows: Multiple goroutines can get read-lock together with a single upgradable-read-lock. Only one goroutine can have a write-lock and no read-lock/upgradable-read-lock can be acquired in this state. There can be only a single goroutine keeping the upgrade-read-lock. RWMutex is not reentrant.

Usage of the RWMutex:

mutex.UpgradableRLock()
defer mutex.UpgradableRUnlock()
// read-lock acquired section. We can return here safely if an error occurs
mutex.UpgradeWLock()
// critical section with exclusive right access

func (*RWMutex) Lock

func (rw *RWMutex) Lock()

Lock is same as sync.RWMutex

func (*RWMutex) RLock

func (rw *RWMutex) RLock()

RLock is same as sync.RWMutex.RLock

func (*RWMutex) RUnlock

func (rw *RWMutex) RUnlock()

RUnlock is same as sync.RWMutex

func (*RWMutex) TryLock

func (rw *RWMutex) TryLock() bool

TryLock is same as sync.RWMutex

func (*RWMutex) TryRLock

func (rw *RWMutex) TryRLock() bool

TryRLock is same as sync.RWMutex

func (*RWMutex) Unlock

func (rw *RWMutex) Unlock()

Unlock is same as sync.RWMutex

func (*RWMutex) UpgradableRLock

func (rw *RWMutex) UpgradableRLock()

UpgradableRLock acquires an upgradable-read-lock which can be later upgraded to write-lock, Example usage:

mutex.UpgradableRLock()
defer mutex.UpgradableRUnlock()
// read-lock acquired section. We can return here safely if an error occurs
mutex.UpgradeWLock()
// critical section with exclusive right access

func (*RWMutex) UpgradableRUnlock

func (rw *RWMutex) UpgradableRUnlock()

UpgradableRUnlock unlocks either the write-lock if it is upgraded or unlock just the upgradeableRead-lock if not upgraded

func (*RWMutex) UpgradeWLock

func (rw *RWMutex) UpgradeWLock()

UpgradeWLock upgrade the read lock to the write lock

Jump to

Keyboard shortcuts

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