NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
file_locker.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_FILE_FILE_LOCKER_HPP__
2#define NEFORCE_CORE_FILE_FILE_LOCKER_HPP__
3
18
21NEFORCE_BEGIN_NAMESPACE__
22
28
41class NEFORCE_API file_locker {
42public:
45
46private:
47 native_handle_type handle_;
48
49public:
57
58 file_locker(const file_locker&) = delete;
59 file_locker& operator=(const file_locker&) = delete;
60
71 bool lock(difference_type offset, difference_type length, file_lock mode = file_lock::EXCLUSIVE) const noexcept;
72
81 bool unlock(difference_type offset, difference_type length) const noexcept;
82
92 bool try_lock(difference_type offset, difference_type length, file_lock mode) const noexcept;
93
105 NEFORCE_NODISCARD bool is_locked(difference_type offset, difference_type length,
106 file_lock* lock_out = nullptr) const noexcept;
107
115 bool lock_whole(file_lock mode = file_lock::EXCLUSIVE) const noexcept;
116
123 bool unlock_whole() const noexcept;
124};
125
126
134class NEFORCE_API file_lock_guard {
135public:
137
138private:
139 file_locker& locker_;
140 difference_type offset_;
141 difference_type length_;
142 bool locked_ = false;
143
144public:
155
162
163 file_lock_guard(const file_lock_guard&) = delete;
164 file_lock_guard& operator=(const file_lock_guard&) = delete;
165
170 NEFORCE_NODISCARD bool is_locked() const noexcept { return locked_; }
171
179 bool unlock() noexcept;
180};
181 // File
183
184NEFORCE_END_NAMESPACE__
185#endif // NEFORCE_CORE_FILE_FILE_LOCKER_HPP__
file_lock_guard(file_locker &locker, difference_type offset, difference_type length, file_lock mode)
构造函数,立即获取锁
file_locker::difference_type difference_type
偏移量类型
NEFORCE_NODISCARD bool is_locked() const noexcept
检查是否持有锁
bool unlock() noexcept
手动释放锁
~file_lock_guard()
析构函数,自动释放锁
文件区域锁管理类
_NEFORCE native_handle_type native_handle_type
原生文件句柄类型
int64_t difference_type
偏移量类型
bool unlock(difference_type offset, difference_type length) const noexcept
解锁文件区域
file_locker(native_handle_type handle) noexcept
构造函数
bool lock_whole(file_lock mode=file_lock::EXCLUSIVE) const noexcept
锁定整个文件
bool try_lock(difference_type offset, difference_type length, file_lock mode) const noexcept
尝试锁定
bool unlock_whole() const noexcept
解锁整个文件
bool lock(difference_type offset, difference_type length, file_lock mode=file_lock::EXCLUSIVE) const noexcept
锁定文件区域
NEFORCE_NODISCARD bool is_locked(difference_type offset, difference_type length, file_lock *lock_out=nullptr) const noexcept
查询区域是否被锁定
文件操作常量定义
long long int64_t
64位有符号整数类型
file_lock
文件锁类型枚举
NEFORCE_ALWAYS_INLINE_INLINE thread::native_handle_type handle() noexcept
获取当前线程句柄
基本类型别名