CppCommon
1.0.4.1
C++ Common Library
|
File-lock synchronization primitive. More...
#include <file_lock.h>
Public Member Functions | |
FileLock () | |
FileLock (const Path &path) | |
FileLock (const FileLock &)=delete | |
FileLock (FileLock &&lock)=delete | |
~FileLock () | |
FileLock & | operator= (const Path &path) |
FileLock & | operator= (const FileLock &)=delete |
FileLock & | operator= (FileLock &&lock)=delete |
const Path & | path () const noexcept |
Get the file-lock path. More... | |
void | Assign (const Path &path) |
Assign a new file-lock path. More... | |
void | Reset () |
Reset file-lock. More... | |
bool | TryLockRead () |
Try to acquire read lock without block. More... | |
bool | TryLockWrite () |
Try to acquire write lock without block. More... | |
bool | TryLockReadFor (const Timespan ×pan) |
Try to acquire read lock for the given timespan. More... | |
bool | TryLockWriteFor (const Timespan ×pan) |
Try to acquire write lock for the given timespan. More... | |
bool | TryLockReadUntil (const UtcTimestamp ×tamp) |
Try to acquire read lock until the given timestamp. More... | |
bool | TryLockWriteUntil (const UtcTimestamp ×tamp) |
Try to acquire write lock until the given timestamp. More... | |
void | LockRead () |
Acquire read lock with block. More... | |
void | LockWrite () |
Acquire write lock with block. More... | |
void | UnlockRead () |
Release read lock. More... | |
void | UnlockWrite () |
Release write lock. More... | |
File-lock synchronization primitive.
A file-lock provide shared and exclusive access to some resource based on the file locking functionality provided by OS. This means that multiple threads or processes can read the data in parallel but an exclusive lock is needed for writing or modifying data. When a writer is writing the data, all other writers or readers will be blocked until the writer is finished writing.
Thread-safe.
https://en.wikipedia.org/wiki/File_locking
Definition at line 33 of file file_lock.h.
CppCommon::FileLock::FileLock | ( | ) |
Definition at line 288 of file file_lock.cpp.
|
explicit |
Definition at line 299 of file file_lock.cpp.
|
delete |
|
delete |
CppCommon::FileLock::~FileLock | ( | ) |
Definition at line 312 of file file_lock.cpp.
void CppCommon::FileLock::Assign | ( | const Path & | path | ) |
Assign a new file-lock path.
path | - File-lock path |
Definition at line 326 of file file_lock.cpp.
void CppCommon::FileLock::LockRead | ( | ) |
void CppCommon::FileLock::LockWrite | ( | ) |
Definition at line 318 of file file_lock.cpp.
|
noexcept |
Get the file-lock path.
Definition at line 324 of file file_lock.cpp.
void CppCommon::FileLock::Reset | ( | ) |
Reset file-lock.
Definition at line 327 of file file_lock.cpp.
bool CppCommon::FileLock::TryLockRead | ( | ) |
Try to acquire read lock without block.
Will not block.
Definition at line 329 of file file_lock.cpp.
bool CppCommon::FileLock::TryLockReadFor | ( | const Timespan & | timespan | ) |
Try to acquire read lock for the given timespan.
Will block for the given timespan in the worst case.
timespan | - Timespan to wait for the read lock |
Definition at line 332 of file file_lock.cpp.
|
inline |
Try to acquire read lock until the given timestamp.
Will block until the given timestamp in the worst case.
timestamp | - Timestamp to stop wait for the read lock |
Definition at line 96 of file file_lock.h.
bool CppCommon::FileLock::TryLockWrite | ( | ) |
Try to acquire write lock without block.
Will not block.
Definition at line 330 of file file_lock.cpp.
bool CppCommon::FileLock::TryLockWriteFor | ( | const Timespan & | timespan | ) |
Try to acquire write lock for the given timespan.
Will block for the given timespan in the worst case.
timespan | - Timespan to wait for the write lock |
Definition at line 356 of file file_lock.cpp.
|
inline |
Try to acquire write lock until the given timestamp.
Will block until the given timestamp in the worst case.
timestamp | - Timestamp to stop wait for the write lock |
Definition at line 105 of file file_lock.h.
void CppCommon::FileLock::UnlockRead | ( | ) |
void CppCommon::FileLock::UnlockWrite | ( | ) |