Version: SMASH-3.1
filelock.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015,2017-2018,2020,2022
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_FILELOCK_H_
11 #define SRC_INCLUDE_SMASH_FILELOCK_H_
12 
13 #include <filesystem>
14 
15 #include "forwarddeclarations.h"
16 
17 namespace smash {
18 
30 class FileLock {
31  public:
39  explicit FileLock(const std::filesystem::path& path);
41  ~FileLock();
50  bool acquire();
51 
52  private:
54  std::filesystem::path path_;
56  bool acquired_;
57 };
58 
59 } // namespace smash
60 
61 #endif // SRC_INCLUDE_SMASH_FILELOCK_H_
Guard to create a file lock.
Definition: filelock.h:30
bool acquired_
Whether the lock has been acquired.
Definition: filelock.h:56
bool acquire()
Try to acquire the file lock.
Definition: filelock.cc:22
~FileLock()
Delete the lock file when the guard is destroyed.
Definition: filelock.cc:41
FileLock(const std::filesystem::path &path)
Construct a file lock guard with a lock file at the given path.
Definition: filelock.cc:19
std::filesystem::path path_
Path to the file lock.
Definition: filelock.h:54
Definition: action.h:24