LLFIO
v2.00
|
Many entity shared/exclusive file system based lock. More...
#include "byte_ranges.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 | |
byte_ranges (const byte_ranges &)=delete | |
No copy construction. | |
byte_ranges & | operator= (const byte_ranges &)=delete |
No copy assignment. | |
byte_ranges (byte_ranges &&o) noexcept | |
Move constructor. | |
byte_ranges & | operator= (byte_ranges &&o) noexcept |
Move assign. | |
const file_handle & | handle () const noexcept |
Return the handle to file being used for this lock. | |
virtual void | unlock (entities_type entities, 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< byte_ranges > | fs_mutex_byte_ranges (const path_handle &base, path_view lockfile) noexcept |
Initialises a shared filing system mutex using the file at lockfile. | |
Protected Member Functions | |
virtual result< void > | _lock (entities_guard &out, deadline d, bool spin_not_sleep) noexcept final |
Many entity shared/exclusive file system based lock.
This is a simple many entity shared mutex. It works by locking in the same file the byte at the offset of the entity id. If it fails to lock a byte, it backs out all preceding locks, randomises the order and tries locking them again until success. Needless to say this algorithm puts a lot of strain on your byte range locking implementation, some NFS implementations have been known to fail to cope.
safe_byte_ranges
instead of this class directly.Caveats: