mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 18:14:12 +08:00
mdbx: drop mdbx_txn_trylock().
This commit is contained in:
parent
5e1721efdd
commit
0a7a290d06
@ -213,16 +213,10 @@ void mdbx_rdt_unlock(MDBX_env *env) {
|
|||||||
mdbx_panic("%s() failed: errcode %d\n", mdbx_func_, rc);
|
mdbx_panic("%s() failed: errcode %d\n", mdbx_func_, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mdbx_txn_lock(MDBX_env *env) {
|
int mdbx_txn_lock(MDBX_env *env, bool dontwait) {
|
||||||
mdbx_trace(">>");
|
mdbx_trace(">>");
|
||||||
int rc = mdbx_robust_lock(env, &env->me_lck->mti_wmutex);
|
int rc = dontwait ? mdbx_robust_trylock(env, &env->me_lck->mti_wmutex)
|
||||||
mdbx_trace("<< rc %d", rc);
|
: mdbx_robust_lock(env, &env->me_lck->mti_wmutex);
|
||||||
return MDBX_IS_ERROR(rc) ? rc : MDBX_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mdbx_txn_trylock(MDBX_env *env) {
|
|
||||||
mdbx_trace(">>");
|
|
||||||
int rc = mdbx_robust_trylock(env, &env->me_lck->mti_wmutex);
|
|
||||||
mdbx_trace("<< rc %d", rc);
|
mdbx_trace("<< rc %d", rc);
|
||||||
return MDBX_IS_ERROR(rc) ? rc : MDBX_SUCCESS;
|
return MDBX_IS_ERROR(rc) ? rc : MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
|
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
|
||||||
* and other libmdbx authors: please see AUTHORS file.
|
* and other libmdbx authors: please see AUTHORS file.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -126,20 +126,13 @@ static __inline BOOL funlock(mdbx_filehandle_t fd, uint64_t offset,
|
|||||||
#define LCK_BODY LCK_BODY_OFFSET, LCK_BODY_LEN
|
#define LCK_BODY LCK_BODY_OFFSET, LCK_BODY_LEN
|
||||||
#define LCK_WHOLE 0, LCK_MAXLEN
|
#define LCK_WHOLE 0, LCK_MAXLEN
|
||||||
|
|
||||||
int mdbx_txn_lock(MDBX_env *env) {
|
int mdbx_txn_lock(MDBX_env *env, bool dontwait) {
|
||||||
if (flock(env->me_fd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_BODY))
|
if (flock(env->me_fd, dontwait ? (LCK_EXCLUSIVE | LCK_DONTWAIT)
|
||||||
return MDBX_SUCCESS;
|
: (LCK_EXCLUSIVE | LCK_WAITFOR),
|
||||||
return GetLastError();
|
LCK_BODY))
|
||||||
}
|
|
||||||
|
|
||||||
int mdbx_txn_trylock(MDBX_env *env) {
|
|
||||||
if (flock(env->me_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY))
|
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
int rc = GetLastError();
|
int rc = GetLastError();
|
||||||
if (rc == ERROR_LOCK_VIOLATION) {
|
return (!dontwait || rc != ERROR_LOCK_VIOLATION) ? rc : MDBX_BUSY;
|
||||||
rc = MDBX_BUSY;
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mdbx_txn_unlock(MDBX_env *env) {
|
void mdbx_txn_unlock(MDBX_env *env) {
|
||||||
|
13
src/mdbx.c
13
src/mdbx.c
@ -2288,7 +2288,7 @@ int mdbx_env_sync(MDBX_env *env, int force) {
|
|||||||
(!env->me_txn0 || env->me_txn0->mt_owner != mdbx_thread_self());
|
(!env->me_txn0 || env->me_txn0->mt_owner != mdbx_thread_self());
|
||||||
|
|
||||||
if (outside_txn) {
|
if (outside_txn) {
|
||||||
int rc = mdbx_txn_lock(env);
|
int rc = mdbx_txn_lock(env, false);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -2317,7 +2317,7 @@ int mdbx_env_sync(MDBX_env *env, int force) {
|
|||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
rc = mdbx_txn_lock(env);
|
rc = mdbx_txn_lock(env, false);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@ -2563,8 +2563,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
|
|||||||
} else {
|
} else {
|
||||||
/* Not yet touching txn == env->me_txn0, it may be active */
|
/* Not yet touching txn == env->me_txn0, it may be active */
|
||||||
mdbx_jitter4testing(false);
|
mdbx_jitter4testing(false);
|
||||||
rc = F_ISSET(flags, MDBX_TRYTXN) ? mdbx_txn_trylock(env)
|
rc = mdbx_txn_lock(env, F_ISSET(flags, MDBX_TRYTXN));
|
||||||
: mdbx_txn_lock(env);
|
|
||||||
if (unlikely(rc))
|
if (unlikely(rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@ -4444,7 +4443,7 @@ LIBMDBX_API int mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower,
|
|||||||
return MDBX_EACCESS;
|
return MDBX_EACCESS;
|
||||||
|
|
||||||
if (outside_txn) {
|
if (outside_txn) {
|
||||||
int err = mdbx_txn_lock(env);
|
int err = mdbx_txn_lock(env, false);
|
||||||
if (unlikely(err != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -9772,7 +9771,7 @@ static int __cold mdbx_env_copy_asis(MDBX_env *env, mdbx_filehandle_t fd) {
|
|||||||
goto bailout; /* FIXME: or just return? */
|
goto bailout; /* FIXME: or just return? */
|
||||||
|
|
||||||
/* Temporarily block writers until we snapshot the meta pages */
|
/* Temporarily block writers until we snapshot the meta pages */
|
||||||
rc = mdbx_txn_lock(env);
|
rc = mdbx_txn_lock(env, false);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
goto bailout;
|
goto bailout;
|
||||||
|
|
||||||
@ -9857,7 +9856,7 @@ int __cold mdbx_env_set_flags(MDBX_env *env, unsigned flags, int onoff) {
|
|||||||
if (unlikely(flags & ~CHANGEABLE))
|
if (unlikely(flags & ~CHANGEABLE))
|
||||||
return MDBX_EINVAL;
|
return MDBX_EINVAL;
|
||||||
|
|
||||||
int rc = mdbx_txn_lock(env);
|
int rc = mdbx_txn_lock(env, false);
|
||||||
if (unlikely(rc))
|
if (unlikely(rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
@ -505,8 +505,7 @@ void mdbx_lck_destroy(MDBX_env *env);
|
|||||||
int mdbx_rdt_lock(MDBX_env *env);
|
int mdbx_rdt_lock(MDBX_env *env);
|
||||||
void mdbx_rdt_unlock(MDBX_env *env);
|
void mdbx_rdt_unlock(MDBX_env *env);
|
||||||
|
|
||||||
int mdbx_txn_lock(MDBX_env *env);
|
int mdbx_txn_lock(MDBX_env *env, bool dontwait);
|
||||||
int mdbx_txn_trylock(MDBX_env *env);
|
|
||||||
void mdbx_txn_unlock(MDBX_env *env);
|
void mdbx_txn_unlock(MDBX_env *env);
|
||||||
|
|
||||||
int mdbx_rpid_set(MDBX_env *env);
|
int mdbx_rpid_set(MDBX_env *env);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user