LLFIO
v2.00
|
Many entity exclusive compatibility file system based lock. More...
#include "lock_files.hpp"
Public Types | |
using | entity_type = shared_fs_mutex::entity_type |
The type of an entity id. | |
using | entities_type = shared_fs_mutex::entities_type |
The type of a sequence of entities. | |
Public Member Functions | |
lock_files (const lock_files &)=delete | |
No copy construction. | |
lock_files & | operator= (const lock_files &)=delete |
No copy assignment. | |
lock_files (lock_files &&o) noexcept | |
Move constructor. | |
lock_files & | operator= (lock_files &&o) noexcept |
Move assign. | |
const path_handle & | path () const noexcept |
Return the path to the directory being used for this lock. | |
virtual void | unlock (entities_type, unsigned long long) noexcept final |
Unlock a previously locked sequence of entities. | |
entity_type | entity_from_buffer (const char *buffer, size_t bytes, bool exclusive=true) noexcept |
Generates an entity id from a sequence of bytes. | |
template<typename T > | |
entity_type | entity_from_string (const std::basic_string< T > &str, bool exclusive=true) noexcept |
Generates an entity id from a string. | |
entity_type | random_entity (bool exclusive=true) noexcept |
Generates a cryptographically random entity id. | |
void | fill_random_entities (span< entity_type > seq, bool exclusive=true) noexcept |
Fills a sequence of entity ids with cryptographic randomness. Much faster than calling random_entity() individually. | |
result< entities_guard > | lock (entities_type entities, deadline d=deadline(), bool spin_not_sleep=false) noexcept |
Lock all of a sequence of entities for exclusive or shared access. | |
result< entities_guard > | lock (entity_type entity, deadline d=deadline(), bool spin_not_sleep=false) noexcept |
Lock a single entity for exclusive or shared access. | |
result< entities_guard > | try_lock (entities_type entities) noexcept |
Try to lock all of a sequence of entities for exclusive or shared access. | |
result< entities_guard > | try_lock (entity_type entity) noexcept |
Try to lock a single entity for exclusive or shared access. | |
Static Public Member Functions | |
static result< lock_files > | fs_mutex_lock_files (const path_handle &lockdir) noexcept |
Initialises a shared filing system mutex using the directory at lockdir which MUST stay valid for the duration of this lock. | |
Protected Member Functions | |
virtual result< void > | _lock (entities_guard &out, deadline d, bool spin_not_sleep) noexcept final |
Many entity exclusive compatibility file system based lock.
This is a very simple many entity shared mutex likely to work almost anywhere without surprises. It works by trying to exclusively create a file called the hex of the entity id. If it fails to exclusively create any file, it deletes all previously created files, randomises the order and tries locking them again until success. The only real reason to use this implementation is its excellent compatibility with almost everything, most users will want byte_ranges instead.
Caveats:
Fixing the stale lock file problem could be quite trivial - simply byte range lock the first byte in the lock file to detect when a lock file is stale. However in this situation using the byte_ranges algorithm would be far superior, so implementing stale lock file clean up is left up to the user.