lock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const SlashSeparator = "/"

SlashSeparator - slash separator.

Variables

This section is empty.

Functions

func PathJoin

func PathJoin(elem ...string) string

PathJoin - like path.Join() but retains trailing SlashSeparator of the last element

Types

type LockContext

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

LockContext lock context holds the lock backed context and canceler for the context.

func (LockContext) Cancel

func (l LockContext) Cancel()

Cancel function calls cancel() function

func (LockContext) Context

func (l LockContext) Context() context.Context

Context returns lock context

type NsLockMap

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

NsLockMap - namespace lock map, provides primitives to Lock, Unlock, RLock and RUnlock.

func NewNSLock

func NewNSLock() *NsLockMap

NewNSLock - return a new name space lock map.

func (*NsLockMap) NewNSLock

func (n *NsLockMap) NewNSLock(volume string, paths ...string) RWLocker

NewNSLock - returns a lock instance for a given volume and path. The returned lockInstance object encapsulates the nsLockMap, volume, path and operation ID.

type OperationTimedOut

type OperationTimedOut struct{}

OperationTimedOut - a timeout occurred.

func (OperationTimedOut) Error

func (e OperationTimedOut) Error() string

type RWLocker

type RWLocker interface {
	GetLock(ctx context.Context, timeout time.Duration) (lkCtx LockContext, timedOutErr error)
	Unlock(cancel context.CancelFunc)
	GetRLock(ctx context.Context, timeout time.Duration) (lkCtx LockContext, timedOutErr error)
	RUnlock(cancel context.CancelFunc)
}

RWLocker - locker interface to introduce GetRLock, RUnlock.

type TRWMutex

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

A TRWMutex is a mutual exclusion lock with timeouts.

func NewTRWMutex

func NewTRWMutex() *TRWMutex

NewTRWMutex - initializes a new lsync RW mutex.

func (*TRWMutex) ForceUnlock

func (m *TRWMutex) ForceUnlock()

ForceUnlock will forcefully clear a write or read lock.

func (*TRWMutex) GetLock

func (m *TRWMutex) GetLock(ctx context.Context, timeout time.Duration) (locked bool)

GetLock tries to get a write lock on lm before the timeout occurs.

func (*TRWMutex) GetRLock

func (m *TRWMutex) GetRLock(ctx context.Context, timeout time.Duration) (locked bool)

GetRLock tries to get a read lock on lm before the timeout occurs.

func (*TRWMutex) Lock

func (m *TRWMutex) Lock()

Lock holds a write lock on lm.

If the lock is already in use, the calling go routine blocks until the mutex is available.

func (*TRWMutex) RLock

func (m *TRWMutex) RLock()

RLock holds a read lock on lm.

If one or more read lock are already in use, it will grant another lock. Otherwise the calling go routine blocks until the mutex is available.

func (*TRWMutex) RUnlock

func (m *TRWMutex) RUnlock()

RUnlock releases a read lock held on lm.

It is a run-time error if lm is not locked on entry to RUnlock.

func (*TRWMutex) Unlock

func (m *TRWMutex) Unlock()

Unlock unlocks the write lock.

It is a run-time error if lm is not locked on entry to Unlock.

Jump to

Keyboard shortcuts

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