LLFIO v2.00
Loading...
Searching...
No Matches
llfio_v2_xxx::unique_file_lock Class Reference

RAII locker matching std::unique_lock for lockable_byte_io_handle, but untemplated. More...

#include "lockable_byte_io_handle.hpp"

Public Member Functions

 unique_file_lock (lockable_byte_io_handle &h, lock_kind kind)
 
 unique_file_lock (unique_file_lock &&o) noexcept
 
 unique_file_lock (const unique_file_lock &)=delete
 
unique_file_lockoperator= (unique_file_lock &&o) noexcept
 
unique_file_lockoperator= (const unique_file_lock &)=delete
 
lockable_byte_io_handlemutex () const noexcept
 Returns the associated mutex.
 
bool owns_lock () const noexcept
 True if the associated mutex is owned by this lock.
 
 operator bool () const noexcept
 True if the associated mutex is owned by this lock.
 
lockable_byte_io_handlerelease () noexcept
 Releases the mutex from management.
 
result< void > lock () noexcept
 Lock the mutex for exclusive access.
 
bool try_lock () noexcept
 Try to lock the mutex for exclusive access.
 
void unlock () noexcept
 Unlock the mutex from exclusive access.
 
result< void > lock_shared () noexcept
 Lock the mutex for shared access.
 
bool try_lock_shared () noexcept
 Try to lock the mutex for shared access.
 
void unlock_shared () noexcept
 Unlock the mutex from shared access.
 

Detailed Description

RAII locker matching std::unique_lock for lockable_byte_io_handle, but untemplated.

Constructor & Destructor Documentation

◆ unique_file_lock() [1/2]

llfio_v2_xxx::unique_file_lock::unique_file_lock ( lockable_byte_io_handle h,
lock_kind  kind 
)
inlineexplicit
320 : _h(&h)
321 {
322 if(kind == lock_kind::exclusive)
323 {
324 lock().value();
325 }
326 else if(kind == lock_kind::shared)
327 {
328 lock_shared().value();
329 }
330 }
result< void > lock() noexcept
Lock the mutex for exclusive access.
Definition lockable_byte_io_handle.hpp:382
result< void > lock_shared() noexcept
Lock the mutex for shared access.
Definition lockable_byte_io_handle.hpp:428
@ shared
Exclude only those requesting an exclusive lock on the same inode.
@ exclusive
Exclude those requesting any kind of lock on the same inode.

◆ unique_file_lock() [2/2]

llfio_v2_xxx::unique_file_lock::unique_file_lock ( unique_file_lock &&  o)
inlinenoexcept
332 : _h(o._h)
333 , _lock_state(o._lock_state)
334 {
335 o._h = nullptr;
336 o._lock_state = lock_kind::unlocked;
337 }
@ unlocked
Exclude none.

◆ ~unique_file_lock()

llfio_v2_xxx::unique_file_lock::~unique_file_lock ( )
inline
351 {
352 if(_h != nullptr)
353 {
354 if(_lock_state == lock_kind::exclusive)
355 {
356 _h->unlock_file();
357 }
358 else if(_lock_state == lock_kind::shared)
359 {
360 _h->unlock_file_shared();
361 }
362 _h = nullptr;
363 }
364 }
virtual void unlock_file() noexcept
Unlocks a previously acquired exclusive lock.
virtual void unlock_file_shared() noexcept
Unlocks a previously acquired shared lock.

Member Function Documentation

◆ lock()

result< void > llfio_v2_xxx::unique_file_lock::lock ( )
inlinenoexcept

Lock the mutex for exclusive access.

383 {
384 if(_h == nullptr)
385 {
386 return errc::operation_not_permitted;
387 }
388 if(_lock_state != lock_kind::unlocked)
389 {
390 return errc::resource_deadlock_would_occur;
391 }
392 OUTCOME_TRY(_h->lock_file());
393 _lock_state = lock_kind::exclusive;
394 return success();
395 }
virtual result< void > lock_file() noexcept
Locks the inode referred to by the open handle for exclusive access.

◆ lock_shared()

result< void > llfio_v2_xxx::unique_file_lock::lock_shared ( )
inlinenoexcept

Lock the mutex for shared access.

429 {
430 if(_h == nullptr)
431 {
432 return errc::operation_not_permitted;
433 }
434 if(_lock_state != lock_kind::unlocked)
435 {
436 return errc::resource_deadlock_would_occur;
437 }
438 OUTCOME_TRY(_h->lock_file_shared());
439 _lock_state = lock_kind::shared;
440 return success();
441 }
virtual result< void > lock_file_shared() noexcept
Locks the inode referred to by the open handle for shared access.

◆ mutex()

lockable_byte_io_handle * llfio_v2_xxx::unique_file_lock::mutex ( ) const
inlinenoexcept

Returns the associated mutex.

367{ return _h; }

◆ operator bool()

llfio_v2_xxx::unique_file_lock::operator bool ( ) const
inlineexplicitnoexcept

True if the associated mutex is owned by this lock.

371{ return owns_lock(); }
bool owns_lock() const noexcept
True if the associated mutex is owned by this lock.
Definition lockable_byte_io_handle.hpp:369

◆ operator=()

unique_file_lock & llfio_v2_xxx::unique_file_lock::operator= ( unique_file_lock &&  o)
inlinenoexcept
340 {
341 if(this == &o)
342 {
343 return *this;
344 }
345 this->~unique_file_lock();
346 new(this) unique_file_lock(std::move(o));
347 return *this;
348 }

◆ owns_lock()

bool llfio_v2_xxx::unique_file_lock::owns_lock ( ) const
inlinenoexcept

True if the associated mutex is owned by this lock.

369{ return (_h != nullptr) && _lock_state != lock_kind::unlocked; }

◆ release()

lockable_byte_io_handle * llfio_v2_xxx::unique_file_lock::release ( )
inlinenoexcept

Releases the mutex from management.

375 {
376 lockable_byte_io_handle *ret = _h;
377 _h = nullptr;
378 return ret;
379 }

◆ try_lock()

bool llfio_v2_xxx::unique_file_lock::try_lock ( )
inlinenoexcept

Try to lock the mutex for exclusive access.

398 {
399 if(_h == nullptr)
400 {
401 return false;
402 }
403 if(_lock_state != lock_kind::unlocked)
404 {
405 return false;
406 }
407 if(_h->try_lock_file())
408 {
409 _lock_state = lock_kind::exclusive;
410 return true;
411 }
412 return false;
413 }
virtual bool try_lock_file() noexcept
Tries to lock the inode referred to by the open handle for exclusive access, returning false if lock ...

◆ try_lock_shared()

bool llfio_v2_xxx::unique_file_lock::try_lock_shared ( )
inlinenoexcept

Try to lock the mutex for shared access.

444 {
445 if(_h == nullptr)
446 {
447 return false;
448 }
449 if(_lock_state != lock_kind::unlocked)
450 {
451 return false;
452 }
453 if(_h->try_lock_file_shared())
454 {
455 _lock_state = lock_kind::shared;
456 return true;
457 }
458 return false;
459 }
virtual bool try_lock_file_shared() noexcept
Tries to lock the inode referred to by the open handle for shared access, returning false if lock is ...

◆ unlock()

void llfio_v2_xxx::unique_file_lock::unlock ( )
inlinenoexcept

Unlock the mutex from exclusive access.

416 {
417 assert(_h != nullptr);
418 assert(_lock_state == lock_kind::exclusive);
419 if(_h == nullptr || _lock_state != lock_kind::exclusive)
420 {
421 return;
422 }
423 _h->unlock_file();
424 _lock_state = lock_kind::unlocked;
425 }

◆ unlock_shared()

void llfio_v2_xxx::unique_file_lock::unlock_shared ( )
inlinenoexcept

Unlock the mutex from shared access.

462 {
463 assert(_h != nullptr);
464 assert(_lock_state == lock_kind::shared);
465 if(_h == nullptr || _lock_state != lock_kind::shared)
466 {
467 return;
468 }
469 _h->unlock_file_shared();
470 _lock_state = lock_kind::unlocked;
471 }

The documentation for this class was generated from the following file: