Add the ability to not block when opening a write transaction

This commit is contained in:
James Rouzier
2017-10-25 19:41:28 -04:00
parent 4f1c846437
commit 7c466e53f0
6 changed files with 46 additions and 6 deletions

View File

@@ -132,6 +132,16 @@ int mdbx_txn_lock(MDBX_env *env) {
return GetLastError();
}
int mdbx_txn_trylock(MDBX_env *env) {
if (flock(env->me_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY))
return MDBX_SUCCESS;
int rc = GetLastError();
if (rc == ERROR_LOCK_VIOLATION) {
rc = MDBX_BUSY;
}
return rc;
}
void mdbx_txn_unlock(MDBX_env *env) {
if (!funlock(env->me_fd, LCK_BODY))
mdbx_panic("%s failed: errcode %u", mdbx_func_, GetLastError());