Documentation ¶
Index ¶
- type LastWrite
- type LockFile
- func (l *LockFile) AssertLocked()
- func (l *LockFile) AssertLockedForWriting()
- func (l *LockFile) GetLastWrite() (LastWrite, error)
- func (l *LockFile) IsReadWrite() bool
- func (l *LockFile) Lock()
- func (l *LockFile) Modified() (bool, error)deprecated
- func (l *LockFile) ModifiedSince(previous LastWrite) (LastWrite, bool, error)
- func (l *LockFile) RLock()
- func (l *LockFile) RecordWrite() (LastWrite, error)
- func (l *LockFile) Touch() errordeprecated
- func (l *LockFile) TouchedSince(when time.Time) bool
- func (l *LockFile) TryLock() error
- func (l *LockFile) TryRLock() error
- func (l *LockFile) Unlock()
- type Lockerdeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LastWrite ¶ added in v0.46.1
type LastWrite struct {
// contains filtered or unexported fields
}
LastWrite is an opaque identifier of the last write to some *LockFile. It can be used by users of a *LockFile to determine if the lock indicates changes since the last check.
Never construct a LastWrite manually; only accept it from *LockFile methods, and pass it back.
type LockFile ¶ added in v0.46.1
type LockFile struct {
// contains filtered or unexported fields
}
LockFile represents a file lock where the file is used to cache an identifier of the last party that made changes to whatever's being protected by the lock.
It MUST NOT be created manually. Use GetLockFile or GetROLockFile instead.
func GetLockFile ¶ added in v0.46.1
GetLockFile opens a read-write lock file, creating it if necessary. The *LockFile object may already be locked if the path has already been requested by the current process.
func GetROLockFile ¶ added in v0.46.1
GetROLockFile opens a read-only lock file, creating it if necessary. The *LockFile object may already be locked if the path has already been requested by the current process.
func (*LockFile) AssertLocked ¶ added in v0.46.1
func (l *LockFile) AssertLocked()
func (*LockFile) AssertLockedForWriting ¶ added in v0.46.1
func (l *LockFile) AssertLockedForWriting()
func (*LockFile) GetLastWrite ¶ added in v0.46.1
GetLastWrite returns a LastWrite value corresponding to current state of the lock. This is typically called before (_not after_) loading the state when initializing a consumer of the data protected by the lock. During the lifetime of the consumer, the consumer should usually call ModifiedSince instead.
The caller must hold the lock (for reading or writing).
func (*LockFile) IsReadWrite ¶ added in v0.46.1
IsReadWrite indicates if the lock file is a read-write lock.
func (*LockFile) Lock ¶ added in v0.46.1
func (l *LockFile) Lock()
Lock locks the lockfile as a writer. Panic if the lock is a read-only one.
func (*LockFile) Modified
deprecated
added in
v0.46.1
Modified indicates if the lockfile has been updated since the last time it was loaded. NOTE: Unlike ModifiedSince, this returns true the first time it is called on a *LockFile. Callers cannot, in general, rely on this, because that might have happened for some other owner of the same *LockFile who created it previously.
Deprecated: Use *LockFile.ModifiedSince.
func (*LockFile) ModifiedSince ¶ added in v0.46.1
ModifiedSince checks if the lock has been changed since a provided LastWrite value, and returns the one to record instead.
If ModifiedSince reports no modification, the previous LastWrite value is still valid and can continue to be used.
If this function fails, the LastWriter value of the lock is indeterminate; the caller should fail and keep using the previously-recorded LastWrite value, so that it continues failing until the situation is resolved. Similarly, it should only update the recorded LastWrite value after processing the update:
lw2, modified, err := state.lock.ModifiedSince(state.lastWrite) if err != nil { /* fail */ } state.lastWrite = lw2 if modified { if err := reload(); err != nil { /* fail */ } state.lastWrite = lw2 }
The caller must hold the lock (for reading or writing).
func (*LockFile) RLock ¶ added in v0.46.1
func (l *LockFile) RLock()
RLock locks the lockfile as a reader.
func (*LockFile) RecordWrite ¶ added in v0.46.1
RecordWrite updates the lock with a new LastWrite value, and returns the new value.
If this function fails, the LastWriter value of the lock is indeterminate; the caller should keep using the previously-recorded LastWrite value, and possibly detecting its own modification as an external one:
lw, err := state.lock.RecordWrite() if err != nil { /* fail */ } state.lastWrite = lw
The caller must hold the lock for writing.
func (*LockFile) TouchedSince ¶ added in v0.46.1
TouchedSince indicates if the lock file has been touched since the specified time
func (*LockFile) TryLock ¶ added in v1.54.0
TryLock attempts to lock the lockfile as a writer. Panic if the lock is a read-only one.
type Locker
deprecated
type Locker interface { // Acquire a writer lock. // The default unix implementation panics if: // - opening the lockfile failed // - tried to lock a read-only lock-file Lock() // Unlock the lock. // The default unix implementation panics if: // - unlocking an unlocked lock // - if the lock counter is corrupted Unlock() // Acquire a reader lock. RLock() // Touch records, for others sharing the lock, that the caller was the // last writer. It should only be called with the lock held. // // Deprecated: Use *LockFile.RecordWrite. Touch() error // Modified() checks if the most recent writer was a party other than the // last recorded writer. It should only be called with the lock held. // Deprecated: Use *LockFile.ModifiedSince. Modified() (bool, error) // TouchedSince() checks if the most recent writer modified the file (likely using Touch()) after the specified time. TouchedSince(when time.Time) bool // IsReadWrite() checks if the lock file is read-write IsReadWrite() bool // AssertLocked() can be used by callers that _know_ that they hold the lock (for reading or writing), for sanity checking. // It might do nothing at all, or it may panic if the caller is not the owner of this lock. AssertLocked() // AssertLockedForWriting() can be used by callers that _know_ that they hold the lock locked for writing, for sanity checking. // It might do nothing at all, or it may panic if the caller is not the owner of this lock for writing. AssertLockedForWriting() }
A Locker represents a file lock where the file is used to cache an identifier of the last party that made changes to whatever's being protected by the lock.
Deprecated: Refer directly to *LockFile, the provided implementation, instead.