using rwlock
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <isc/lmdb.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/rwlock.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
@@ -47,6 +48,7 @@ typedef struct {
|
||||
bool readonly;
|
||||
} context_t;
|
||||
|
||||
static isc_rwlock_t isc__cfgmgr_lock;
|
||||
static isc_mem_t *isc__cfgmgr_mctx = NULL;
|
||||
static MDB_env *isc__cfgmgr_env = NULL;
|
||||
static thread_local context_t isc__cfgmgr_ctx =
|
||||
@@ -113,6 +115,8 @@ isc_cfgmgr_init(isc_mem_t *mctx, const char *dbpath) {
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(dbpath != NULL);
|
||||
|
||||
isc_rwlock_init(&isc__cfgmgr_lock);
|
||||
|
||||
isc_mem_attach(mctx, &isc__cfgmgr_mctx);
|
||||
INSIST(isc__cfgmgr_mctx != NULL);
|
||||
|
||||
@@ -143,7 +147,7 @@ isc_cfgmgr_init(isc_mem_t *mctx, const char *dbpath) {
|
||||
* the disk data is dead as well)
|
||||
*/
|
||||
result = mdb_env_open(isc__cfgmgr_env, dbname,
|
||||
MDB_NOSYNC | MDB_NOSUBDIR, 0600);
|
||||
MDB_NOSYNC | MDB_NOSUBDIR | MDB_NOLOCK, 0600);
|
||||
if (result != 0) {
|
||||
result = ISC_R_FAILURE;
|
||||
goto cleanup;
|
||||
@@ -304,6 +308,9 @@ static isc_result_t
|
||||
isc__cfgmgr_starttransaction(bool readonly) {
|
||||
MDB_dbi dbi;
|
||||
|
||||
isc_rwlock_lock(&isc__cfgmgr_lock,
|
||||
readonly ? isc_rwlocktype_read : isc_rwlocktype_write);
|
||||
|
||||
if (mdb_txn_begin(isc__cfgmgr_env, NULL, readonly ? MDB_RDONLY : 0,
|
||||
&isc__cfgmgr_ctx.txn) != 0)
|
||||
{
|
||||
@@ -333,6 +340,10 @@ failure:
|
||||
if (isc__cfgmgr_ctx.txn) {
|
||||
mdb_txn_abort(isc__cfgmgr_ctx.txn);
|
||||
isc__cfgmgr_freectx();
|
||||
isc_rwlock_unlock(&isc__cfgmgr_lock,
|
||||
isc__cfgmgr_ctx.readonly
|
||||
? isc_rwlocktype_read
|
||||
: isc_rwlocktype_write);
|
||||
}
|
||||
ENSURE(isc__cfgmgr_ctx.buffer == NULL &&
|
||||
isc__cfgmgr_ctx.prefix == NULL);
|
||||
@@ -382,6 +393,10 @@ cleanup:
|
||||
mdb_cursor_close(isc__cfgmgr_ctx.cursor);
|
||||
mdb_txn_abort(isc__cfgmgr_ctx.txn);
|
||||
isc__cfgmgr_freectx();
|
||||
isc_rwlock_unlock(&isc__cfgmgr_lock,
|
||||
isc__cfgmgr_ctx.readonly
|
||||
? isc_rwlocktype_read
|
||||
: isc_rwlocktype_write);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -450,10 +465,16 @@ isc_cfgmgr_close(void) {
|
||||
popclause();
|
||||
if (ISC_LIST_EMPTY(isc__cfgmgr_ctx.openedclauses)) {
|
||||
mdb_cursor_close(isc__cfgmgr_ctx.cursor);
|
||||
|
||||
if (mdb_txn_commit(isc__cfgmgr_ctx.txn) != 0) {
|
||||
result = ISC_R_FAILURE;
|
||||
}
|
||||
|
||||
isc__cfgmgr_freectx();
|
||||
isc_rwlock_unlock(&isc__cfgmgr_lock,
|
||||
isc__cfgmgr_ctx.readonly
|
||||
? isc_rwlocktype_read
|
||||
: isc_rwlocktype_write);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -724,6 +745,7 @@ isc__cfgmgr_setval(const char *name, const isc_cfgmgr_val_t *value, bool list) {
|
||||
}
|
||||
|
||||
REQUIRE(mdb_cursor_put(isc__cfgmgr_ctx.cursor, &dbkey, &dbval, 0) == 0);
|
||||
|
||||
if (value->type == ISC_CFGMGR_STRING) {
|
||||
isc_mem_free(isc__cfgmgr_mctx, dbval.mv_data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user