sync

package
v0.0.0-...-f9b9731 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RWLock

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

A RWLock is a reader/writer mutual exclusion lock. The lock can be held by an arbitrary number of readers or a single writer. The zero value for a RWLock is an unlocked object.

A RWLock must not be copied after first use.

The behavior of the RWLock is same as sync.RWMutex, but the RWLock could be Closed. The closing of the RWLock means that any attempt to lock it by RLock() or Lock() functions will get an error result. All blocked go routines in the calls RLock() or Lock() will be unblocked with the error result as well.

func (*RWLock) Close

func (rw *RWLock) Close() error

Close causes the RWLock is closed and cannot be used anymore. Locking functions RLock() and Lock() must return an error for a closed RWLock.

func (*RWLock) DowngradeToRead

func (rw *RWLock) DowngradeToRead() bool

DowngradeToRead releases write lock to the read state. Retruns true, if the operation was successful. The rw must be in read state after the operation and it has to be relesed via RUnloc() then. If the write lock was not acquired the method will panic. It returns false if the rw already closed.

func (*RWLock) Lock

func (rw *RWLock) Lock() error

Lock locks rw for writing. If the lock is already locked for reading or writing, Lock blocks until the lock is available or closed.

func (*RWLock) LockWithCtx

func (rw *RWLock) LockWithCtx(ctx context.Context) error

Lock locks rw for writing using context provided. If the lock is already locked for reading or writing, Lock blocks until the lock is available, closed or provided context is closed. ctx could be nil, then no difference with Lock() behavior

func (*RWLock) RLock

func (rw *RWLock) RLock() error

RLock locks rw for reading. The read lock is reentrant, so may be used multiple readers from many go-routines or from a one as well. If the lock is already locked for writing, RLock blocks until the lock is available or closed.

func (*RWLock) RLockWithCtx

func (rw *RWLock) RLockWithCtx(ctx context.Context) error

RLockWithCtx same as RLock, but can be interrupted by ctx provided if blocked ctx could be nil, then no difference with RLock() behavior

func (*RWLock) RUnlock

func (rw *RWLock) RUnlock()

RUnlock undoes a single RLock call; it does not affect other simultaneous readers.

func (*RWLock) String

func (rw *RWLock) String() string

func (*RWLock) TryLock

func (rw *RWLock) TryLock() bool

TryLock tries to acquire write lock for the object

func (*RWLock) TryRLock

func (rw *RWLock) TryRLock() bool

TryRLock tries to acquire the read lock and returns whether it was successful or not

func (*RWLock) Unlock

func (rw *RWLock) Unlock()

Unlock unlocks rw for writing. if there are other goroutiens expecting the rw be locked for writing one of them will be able to lock. If there is no writers, then readers, if there are some, will be able to lock rw for reading.

func (*RWLock) UpgradeToWrite

func (rw *RWLock) UpgradeToWrite() bool

UpgradeToWrite changes the read mode to write if possible. The function must be called holding the read lock. If it returns true, the lock must be freed by Unlock() function. If it returns false then RUnlock must be used instead.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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