BloombergLP::bdls::FilesystemUtil::lock

Acquire a lock for the file with the specified descriptor.

Synopsis

Declared in <bdls_filesystemutil.h>

static
int
lock(
    FileDescriptor descriptor,
    bool lockWriteFlag);

Description

If lockWriteFlag is true, acquire an exclusive write lock; otherwise acquire a (possibly) shared read lock. The calling thread will block until the lock is acquired. Return 0 on success, and a non-zero value otherwise. Note that this operation locks the indicated file for use by 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, and a non-zero value otherwise

Parameters

NameDescription
descriptorfile descriptor of the file to lock
lockWriteFlagtrue for an exclusive write lock; false for a shared read lock