sjef
Locker.h
Go to the documentation of this file.
1#ifndef SJEF_LIB_LOCKER_H_
2#define SJEF_LIB_LOCKER_H_
3#include <filesystem>
4#include <map>
5#include <mutex>
6#include <string>
7#include <thread>
8namespace fs = std::filesystem;
9
11class file_lock;
12}
13
14namespace sjef::util {
28class Locker {
29public:
30 explicit Locker(fs::path path);
31 virtual ~Locker();
32 const fs::path& path() const { return m_path; }
33
34 void add_bolt();
36
37private:
38 const fs::path m_path;
39 std::unique_ptr<std::scoped_lock<std::mutex>> m_lock;
40 std::mutex m_mutex;
41 int m_bolts = 0;
42 const std::unique_ptr<boost::interprocess::file_lock> m_file_lock;
43 std::thread::id m_owning_thread;
44
45public:
46 // RAII
47 struct Bolt {
48 explicit Bolt(Locker& locker);
50 Bolt() = delete;
51 Bolt(const Bolt&) = delete;
52 Bolt& operator=(const Bolt&) = delete;
53
54 private:
55 Locker& m_locker;
56 };
58};
59
60} // namespace sjef::util
61#endif // SJEF_LIB_LOCKER_H_
A thread-safe class for an inter-thread/inter-process lock. The lock mechanism is based on a locked f...
Definition: Locker.h:28
const fs::path & path() const
Definition: Locker.h:32
Locker(fs::path path)
Definition: Locker.h:10
Definition: sjef.h:26
Definition: Locker.h:47
Bolt(const Bolt &)=delete
Bolt & operator=(const Bolt &)=delete
Bolt(Locker &locker)