ThinSQLite++
A thin, safe and convenient modern C++ wrapper for SQLite API.
|
SQLite Mutex. More...
Public Types | |
enum | type { fast = SQLITE_MUTEX_FAST , recursive = SQLITE_MUTEX_RECURSIVE } |
Type of mutex to allocate for alloc() | |
Public Member Functions | |
void | lock () noexcept |
Lock the mutex. | |
bool | try_lock () noexcept |
Try to lock the mutex. | |
void | unlock () noexcept |
Unlock the mutex. | |
void | operator delete (void *) noexcept |
Operator delete for a fake pointer is no-op. | |
sqlite3_mutex * | c_ptr () const noexcept |
Access the real underlying SQLite type. | |
Static Public Member Functions | |
static std::unique_ptr< mutex > | alloc (type t) noexcept |
Allocate a new mutex. | |
static mutex * | from (sqlite3_mutex *obj) noexcept |
Create fake pointer from the underlying SQLite one. | |
SQLite Mutex.
This is a fake wrapper class for sqlite3_mutex.
Unlike other wrappers in this library the interface of this class does not match the names of SQLite C interface. Instead is made to conform to Lockable C++ standard library concept. This allows you to use it in standard lock related machinery like std::unique_lock
or std::lock_guard
In many cases SQLite can return nullptr mutexes due to compile-time or runtime disabling of synchronization. While calling lock(), try_lock() and unlock() on a nullptr this
pointer should work fine on all compilers (underlying SQLite functions all support null pointers) it is technically an undefined behavior in C++ (sigh). To avoid this and deal with null mutex pointers safely see lock_adapter class
#include <thinsqlitepp/mutex.hpp>
|
inlinestaticnoexcept |
Allocate a new mutex.
Equivalent to sqlite3_mutex_alloc
Note that the interface to this function deliberately disallows access to internal static SQLite mutexes. Accroding to SQLite docs "[s]tatic mutexes are for internal use by SQLite only".
If you do require access to one of the static mutexes you can use from(sqlite3_mutex_alloc(SQLITE_MUTEX_XXX))
manually.
t | type of the mutex to allocate |
nullptr
if the SQLite implementation is unable to allocate a mutex (e.g. if it does not support mutexes).
|
inlinenoexcept |
Lock the mutex.
Equivalent to sqlite3_mutex_enter
|
inlinenoexcept |
Try to lock the mutex.
Equivalent to sqlite3_mutex_try
|
inlinenoexcept |
Unlock the mutex.
Equivalent to sqlite3_mutex_leave