ThinSQLite++
A thin, safe and convenient modern C++ wrapper for SQLite API.
Loading...
Searching...
No Matches
lock_adapter Class Reference

A mutex adapter for Lockable concept that works with null and non-null mutexes. More...

Public Member Functions

 lock_adapter (mutex *mutex=nullptr) noexcept
 Adapt a mutex pointer.
 
 lock_adapter (const std::unique_ptr< mutex > &mutex) noexcept
 Adapt a std::unique_ptr<mutex>
 
void lock () noexcept
 Lock the mutex.
 
bool try_lock () noexcept
 Try to lock the mutex.
 
void unlock () noexcept
 Unlock the mutex.
 

Detailed Description

A mutex adapter for Lockable concept that works with null and non-null mutexes.

In many cases SQLite can return nullptr mutexes due to compile-time or runtime disabling of synchronization. This adapter allows you to treat null and non-null mutexes uniformly.

Note that this class stores the passed mutex by reference. If non-null it must remain alive while this class is in use.

Member Function Documentation

◆ lock()

void lock ( )
inlinenoexcept

Lock the mutex.

Equivalent to sqlite3_mutex_enter

◆ try_lock()

bool try_lock ( )
inlinenoexcept

Try to lock the mutex.

Equivalent to sqlite3_mutex_try

◆ unlock()

void unlock ( )
inlinenoexcept

Unlock the mutex.

Equivalent to sqlite3_mutex_leave