sjef
Loading...
Searching...
No Matches
Locker.h
Go to the documentation of this file.
1#ifndef SJEF_LIB_LOCKER_H_
2#define SJEF_LIB_LOCKER_H_
3#define BOOST_ALL_NO_LIB
4#include <filesystem>
5#include <map>
6#include <mutex>
7#include <string>
8#include <thread>
9namespace fs = std::filesystem;
10
12class file_lock;
13}
14
15namespace sjef::util {
29class Locker {
30public:
31 explicit Locker(fs::path path);
32 virtual ~Locker();
33 const fs::path& path() const { return m_path; }
34
35 void add_bolt();
37
38private:
39 const fs::path m_path;
40 std::unique_ptr<std::scoped_lock<std::mutex>> m_lock;
41 std::mutex m_mutex;
42 int m_bolts = 0;
43 const std::unique_ptr<boost::interprocess::file_lock> m_file_lock;
44 std::thread::id m_owning_thread;
45
46public:
47 // RAII
48 struct Bolt {
49 explicit Bolt(Locker& locker);
51 Bolt() = delete;
52 Bolt(const Bolt&) = delete;
53 Bolt& operator=(const Bolt&) = delete;
54
55 private:
56 Locker& m_locker;
57 };
59};
60
61} // namespace sjef::util
62#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:29
const fs::path & path() const
Definition Locker.h:33
Locker(fs::path path)
Definition Locker.h:11
Definition sjef.h:26
Definition Locker.h:48
Bolt(const Bolt &)=delete
Bolt & operator=(const Bolt &)=delete
Bolt(Locker &locker)