Table of Contents

Class LinksFileLock

Namespace
Foundation.Data.Doublets.Cli
Assembly
Foundation.Data.Doublets.Cli.dll

Advisory lock over a links database, for consumers that open the same database file from more than one process.

public sealed class LinksFileLock : IDisposable
Inheritance
LinksFileLock
Implements
Inherited Members

Remarks

The lock is taken on a dedicated sidecar *.lock file rather than on the database itself, so it survives operations that rewrite or remap the database file.

Sharing is expressed through FileShare, which the runtime maps onto the platform's own advisory locking (flock on Unix, share modes on Windows). It is therefore honoured across processes, but — like every advisory lock — only between participants that take it. The operating system releases the lock when the holding process exits, so a crashed writer never leaves a database permanently locked.

Properties

Mode

The sharing mode this guard was acquired with.

public LockMode Mode { get; }

Property Value

LockMode

Path

The sidecar lock file this guard holds.

public string Path { get; }

Property Value

string

Methods

Acquire(string, LockMode, TimeSpan?)

Acquires the lock, waiting until it becomes available or timeout elapses.

public static LinksFileLock Acquire(string lockPath, LockMode mode, TimeSpan? timeout = null)

Parameters

lockPath string
mode LockMode
timeout TimeSpan?

Returns

LinksFileLock

Exceptions

TimeoutException

The lock was still held when timeout elapsed.

Dispose()

Releases the lock.

public void Dispose()

LockFilePath(string)

Conventional sidecar lock filename for a links database.

public static string LockFilePath(string databaseFilename)

Parameters

databaseFilename string

Returns

string

TryAcquire(string, LockMode)

Tries to acquire the lock, returning null when another holder currently owns a conflicting lock.

public static LinksFileLock? TryAcquire(string lockPath, LockMode mode)

Parameters

lockPath string
mode LockMode

Returns

LinksFileLock