database: flip to recursive_mutex to allow nested locks (#1937)

* Fix crash from db locking

* Change db lock to use recursive_mutex
This commit is contained in:
Corey D 2023-03-30 14:03:03 +11:00 committed by GitHub
parent 5ba9816377
commit c5087d7a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 3 deletions

View File

@ -70,7 +70,7 @@ public:
const DatabaseInfo &GetInfo();
private:
MYSQL *m_mysql;
std::mutex m_FullLock;
std::recursive_mutex m_FullLock;
/* ---------- */
DatabaseInfo m_Info;

View File

@ -71,7 +71,7 @@ public:
void SetLastIDAndRows(unsigned int insertID, unsigned int affectedRows);
private:
PGconn *m_pgsql;
std::mutex m_FullLock;
std::recursive_mutex m_FullLock;
unsigned int m_lastInsertID;
unsigned int m_lastAffectedRows;

View File

@ -70,7 +70,7 @@ public:
}
private:
sqlite3 *m_sq3;
std::mutex m_FullLock;
std::recursive_mutex m_FullLock;
bool m_Persistent;
String m_LastError;
int m_LastErrorCode;

View File

@ -959,6 +959,10 @@ native bool SQL_Execute(Handle statement);
* If the lock cannot be acquired, the main thread will pause until the
* threaded operation has concluded.
*
* Care should be taken to not lock an already-locked database. Internally,
* lock calls are nested recursively and must be paired with an equal amount
* of unlocks to be undone. This behaviour should not be relied on.
*
* @param database A database Handle.
* @error Invalid database Handle.
*/