Acquire a lock for the file with descriptor if it is available.

Synopsis

Declared in <bdls_filesystemutil.h>

static
int
tryLock(
    FileDescriptor descriptor,
    bool lockWriteFlag);

Description

Acquire a lock for the file with the specified descriptor if it is currently available. If the specified lockWriteFlag is true, acquire an exclusive write lock unless another process has any type of lock on the file. If lockWriteFlag is false, acquire a shared read lock unless a process has a write lock. This method will not block. Return 0 on success, k_ERROR_LOCKING_CONFLICT if the platform reports the lock could not be acquired because another process holds a conflicting lock, and a negative value for any other kind of error. Note that this operation locks the indicated file for the current process, but the behavior is unspecified (and platform‐dependent) when either attempting to lock descriptor multiple times, or attempting to lock another descriptor referring to the same file, within a single process.

Return Value

0 on success, k_ERROR_LOCKING_CONFLICT on a conflicting lock, and a negative value for any other error

Parameters

Name

Description

descriptor

file descriptor of the file to lock

lockWriteFlag

true for an exclusive write lock; false for a shared read lock

Created with MrDocs