NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
named_mutex.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_ASYNC_NAMED_MUTEX_HPP__
2#define NEFORCE_CORE_ASYNC_NAMED_MUTEX_HPP__
3
10
13NEFORCE_BEGIN_NAMESPACE__
14
20
26
33class NEFORCE_API named_mutex : public mutex_base {
34public:
35 using native_handle_type = _NEFORCE native_handle_type;
36
37private:
38#ifdef NEFORCE_PLATFORM_WINDOWS
39 native_handle_type handle_{nullptr};
40#else
41 int shm_fd_{-1};
42 void* mapped_addr_{nullptr};
43 string shm_name_;
44 bool owner_{false};
45#endif
46 string name_;
47
48public:
52 named_mutex() noexcept = default;
53
60 explicit named_mutex(const string& name, bool create = false);
61
62 ~named_mutex();
63
64 named_mutex(const named_mutex&) = delete;
65 named_mutex& operator=(const named_mutex&) = delete;
66
70 named_mutex(named_mutex&& other) noexcept;
71
75 named_mutex& operator=(named_mutex&& other) noexcept;
76
82 void lock();
83
88 bool try_lock();
89
93 void unlock();
94
99 NEFORCE_NODISCARD const string& name() const noexcept { return name_; }
100
105 NEFORCE_NODISCARD bool is_valid() const noexcept;
106
112 static bool remove(const string& name);
113};
114 // Mutex
116 // AsyncComponents
118
119NEFORCE_END_NAMESPACE__
120#endif // NEFORCE_CORE_ASYNC_NAMED_MUTEX_HPP__
const string & name() const noexcept
获取互斥锁名称
bool try_lock()
尝试获取互斥锁
void unlock()
释放互斥锁
named_mutex() noexcept=default
默认构造函数
bool is_valid() const noexcept
检查是否有效
static bool remove(const string &name)
删除命名互斥锁
void lock()
获取互斥锁
互斥锁
字符串类型别名和实用函数