[PATCH] D79066: [Support] Class to facilitate file locking

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 28 23:57:38 PDT 2020


sepavloff marked an inline comment as done.
sepavloff added a comment.

This is a replacement of D78897 <https://reviews.llvm.org/D78897>.



================
Comment at: llvm/include/llvm/Support/FileSystem.h:1168
+/// RAII class that facilitates file locking.
+class FileLocker {
+  int FD;             ///< Locked file handle.
----------------
dblaikie wrote:
> Perhaps this type should be boolean testable (for the error), or using a factory function to create one that returns llvm::Error (wrapped around the error_code) on failure:
> 
> ```
> {
> Expected<FileLocker> F = TryLock(FD, Timeout);
> if (!F) {
> }
> ...
> }
> ```
> 
> Hmm - if unlocking can fail, and that failure needs to be handled, this doesn't seem suitable for an RAII type device...
> Perhaps this type should be boolean testable (for the error)

The class has method `locked`, which can be used to check if lock was successfully acquired, and method `error` for those applications that need more information than just the fact of failure.

> Hmm - if unlocking can fail, and that failure needs to be handled, this doesn't seem suitable for an RAII type device...

If the failure to unlock needs to be handled, the user would use method `unlock` provided by this class. In most expected use cases however this failure need not be handled. User defines RAII object and do things that require exclusive access. Upon destruction lock is released and if something goes wrong at that moment, this fact is just ignored.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79066/new/

https://reviews.llvm.org/D79066





More information about the llvm-commits mailing list