Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
inter_process_lock.hpp
Go to the documentation of this file.
1#pragma once
2
3// Inter-process file lock — prevents multiple processes from accessing
4// the same resource simultaneously.
5
6#include <cstdint>
7#include <string>
8#include <string_view>
9
10namespace pulp::runtime {
11
13
14 public:
16 explicit InterProcessLock(std::string_view name);
18
20 bool try_lock();
21
24
26 void unlock();
27
29 bool is_locked() const {
30 return mode_ != Mode::Unlocked;
31 }
32
33 // No copy or move
36
37 private:
38 std::string lock_path_;
39 enum class Mode : std::uint8_t { Unlocked, Shared, Exclusive };
40 Mode mode_ = Mode::Unlocked;
41#ifdef _WIN32
42 void* handle_ = nullptr;
43#else
44 int fd_ = -1;
45#endif
46};
47
48} // namespace pulp::runtime
bool is_locked() const
Whether this instance holds the lock.
Definition inter_process_lock.hpp:29
void unlock()
Release the lock.
bool try_lock_shared()
Try to acquire a shared/read lock. Multiple shared holders may coexist.
bool try_lock()
Try to acquire the lock. Returns true if acquired.
InterProcessLock & operator=(const InterProcessLock &)=delete
InterProcessLock(const InterProcessLock &)=delete
InterProcessLock(std::string_view name)
Create a lock with the given name (used to derive the lock file path).
Definition generated_event_source.hpp:33