This function is available as
OS\flock() in Facebook's www repository.
Acquire or remove an advisory lock on a file descriptor
namespace HH\Lib\OS; function flock( FileDescriptor $fd, int $flags, ): void;
man 2 flock for details. On error, an
ErrnoException will be thrown.
A shared lock can also be 'upgraded' to an exclusive lock, however this operation is not guaranteed to be atomic: systems may implement this by releasing the shared lock, then attempting to acquire an exclusive lock. This may lead to an upgrade attempt meaning that a lock is lost entirely, without a replacement, as another process may potentially acquire a lock between these operations.
int $flagsa bitmask of
LOCK_flags; one out of
LOCK_UNmust be specified.