From 20bb7a20ad5f102863bdcabc19abd0906e7bb919 Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 10 Aug 2024 10:33:50 +0200 Subject: [PATCH] [FIX/WIP] Fix mutex issues around LMDB Currently doing a test run on another project of mine to find out how stable it is. Next up(more long-termed): Faster JSON parsing than just plaintext! --- src/Db/LMDB.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Db/LMDB.c b/src/Db/LMDB.c index edee68f..3e35695 100644 --- a/src/Db/LMDB.c +++ b/src/Db/LMDB.c @@ -159,7 +159,6 @@ LMDBLock(Db *d, Array *k) "%s: could not begin transaction: %s", __func__, mdb_strerror(code) ); - pthread_mutex_unlock(&d->lock); goto end; } /* apparently you need to give it a dbi */ @@ -169,9 +168,7 @@ LMDBLock(Db *d, Array *k) "%s: could not get transaction dbi: %s", __func__, mdb_strerror(code) ); - pthread_mutex_unlock(&d->lock); goto end; - } empty_json.mv_size = 0; @@ -180,10 +177,7 @@ LMDBLock(Db *d, Array *k) code = mdb_get(transaction, dbi, &key, &empty_json); if (code == MDB_NOTFOUND) { - Log(LOG_ERR, - "%s: mdb_get failure: %s", - __func__, mdb_strerror(code) - ); + /* No use logging it, as that is just locking behaviour */ mdb_txn_abort(transaction); mdb_dbi_close(db->environ, dbi); goto end; @@ -215,6 +209,10 @@ LMDBLock(Db *d, Array *k) ret->transaction = transaction; ret->dbi = dbi; end: + if (!ret) + { + pthread_mutex_unlock(&d->lock); + } LMDBKillKey(key); return (DbRef *) ret; } @@ -351,7 +349,10 @@ LMDBUnlock(Db *d, DbRef *r) { free(val.mv_data); } - pthread_mutex_unlock(&d->lock); + if (ret) + { + pthread_mutex_unlock(&d->lock); + } return ret; } static DbRef * @@ -379,7 +380,6 @@ LMDBCreate(Db *d, Array *k) "%s: could not begin transaction: %s", __func__, mdb_strerror(code) ); - pthread_mutex_unlock(&d->lock); goto end; } /* apparently you need to give it a dbi */ @@ -389,7 +389,6 @@ LMDBCreate(Db *d, Array *k) "%s: could not get transaction dbi: %s", __func__, mdb_strerror(code) ); - pthread_mutex_unlock(&d->lock); goto end; } @@ -435,6 +434,10 @@ LMDBCreate(Db *d, Array *k) ret->transaction = transaction; ret->dbi = dbi; end: + if (!ret) + { + pthread_mutex_unlock(&d->lock); + } LMDBKillKey(key); return (DbRef *) ret; }