[llvm] r325460 - [Support] Replace hand-written scope_exit with make_scope_exit.
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 18 08:05:40 PST 2018
Author: d0k
Date: Sun Feb 18 08:05:40 2018
New Revision: 325460
URL: http://llvm.org/viewvc/llvm-project?rev=325460&view=rev
Log:
[Support] Replace hand-written scope_exit with make_scope_exit.
No functionality change intended.
Modified:
llvm/trunk/lib/Support/LockFileManager.cpp
Modified: llvm/trunk/lib/Support/LockFileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=325460&r1=325459&r2=325460&view=diff
==============================================================================
--- llvm/trunk/lib/Support/LockFileManager.cpp (original)
+++ llvm/trunk/lib/Support/LockFileManager.cpp Sun Feb 18 08:05:40 2018
@@ -9,6 +9,7 @@
#include "llvm/Support/LockFileManager.h"
#include "llvm/ADT/None.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Errc.h"
@@ -121,27 +122,6 @@ bool LockFileManager::processStillExecut
return true;
}
-namespace {
-
-/// An RAII helper object for cleanups.
-class RAIICleanup {
- std::function<void()> Fn;
- bool Canceled = false;
-
-public:
- RAIICleanup(std::function<void()> Fn) : Fn(Fn) {}
-
- ~RAIICleanup() {
- if (Canceled)
- return;
- Fn();
- }
-
- void cancel() { Canceled = true; }
-};
-
-} // end anonymous namespace
-
LockFileManager::LockFileManager(StringRef FileName)
{
this->FileName = FileName;
@@ -172,7 +152,7 @@ LockFileManager::LockFileManager(StringR
UniqueLockFile = std::move(*Temp);
// Make sure we discard the temporary file on exit.
- RAIICleanup RemoveTempFile([&]() {
+ auto RemoveTempFile = llvm::make_scope_exit([&]() {
if (Error E = UniqueLockFile->discard())
setError(errorToErrorCode(std::move(E)));
});
@@ -209,7 +189,7 @@ LockFileManager::LockFileManager(StringR
std::error_code EC =
sys::fs::create_link(UniqueLockFile->TmpName, LockFileName);
if (!EC) {
- RemoveTempFile.cancel();
+ RemoveTempFile.release();
return;
}
More information about the llvm-commits
mailing list