|
BuildCache
|
A scoped exclusive global lock class. More...
#include <file_lock.hpp>
Public Member Functions | |
| file_lock_t () | |
| Create an empty (unlocked) lock object. | |
| file_lock_t (const std::string &path, const bool remote_lock) | |
| Acquire a lock for the specified file path. More... | |
| file_lock_t (file_lock_t &&other) noexcept | |
| file_lock_t & | operator= (file_lock_t &&other) noexcept |
| file_lock_t (const file_lock_t &other)=delete | |
| file_lock_t & | operator= (const file_lock_t &other)=delete |
| ~file_lock_t () | |
| Release the lock. More... | |
| bool | has_lock () const |
Private Types | |
| using | file_handle_t = int |
| using | mutex_handle_t = void * |
Static Private Member Functions | |
| static file_handle_t | invalid_file_handle () |
| static mutex_handle_t | invalid_mutex_handle () |
Private Attributes | |
| std::string | m_path |
| file_handle_t | m_file_handle = invalid_file_handle() |
| mutex_handle_t | m_mutex_handle = invalid_mutex_handle() |
| bool | m_has_lock = false |
A scoped exclusive global lock class.
This lock class is intended to be used for granular synchronization of multiple processes that need to access a specific part of a file system, such as a single file or a folder. Locks are expected to be held for a very short time period (typically only for a fraction of a second), during operations such as file renames or writes.
When the lock is created, a global named system object is created (if necessary) and acquired. Once the lock goes out of scope, the system object is released.
After a lock is no longer used by any process, the named system object may or may not be left on the system (depending on the underlying implementation). It is thus up to the user of the lock to guarantee that the necessary cleanup is performed.
Two system object types are supported:
|
explicit |
Acquire a lock for the specified file path.
| path | The full path to the lock file (will be created). The path should be a location on the file system to which the process requires access synchronization. |
| remote_lock | Require the implementation to use a locking mechanism that can synchronize file system access across several OS instances (e.g. use this for network shares). |
| bcache::file::file_lock_t::~file_lock_t | ( | ) |
Release the lock.
This releases the lock that was held.
|
inline |
1.8.17