Documentation
¶
Index ¶
- type RWLock
- func (rw *RWLock) Close() error
- func (rw *RWLock) DowngradeToRead() bool
- func (rw *RWLock) Lock() error
- func (rw *RWLock) LockWithCtx(ctx context.Context) error
- func (rw *RWLock) RLock() error
- func (rw *RWLock) RLockWithCtx(ctx context.Context) error
- func (rw *RWLock) RUnlock()
- func (rw *RWLock) String() string
- func (rw *RWLock) TryLock() bool
- func (rw *RWLock) TryRLock() bool
- func (rw *RWLock) Unlock()
- func (rw *RWLock) UpgradeToWrite() bool
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) TryRLock ¶
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 ¶
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.