mdbx: fix race-with-close for lck-posix.

Change-Id: Ie601ebbec8cc47d26935e12a57abe991aec1cb41
This commit is contained in:
Leonid Yuriev 2019-08-11 00:07:21 +03:00
parent 673f867e3c
commit bdc77df921

View File

@ -151,7 +151,7 @@ int __cold mdbx_lck_seize(MDBX_env *env) {
OFF_T_MAX); OFF_T_MAX);
if (rc == 0) { if (rc == 0) {
/* got dxb-exclusive, try lck-exclusive */ /* got dxb-exclusive, try lck-exclusive */
rc = mdbx_lck_op(env->me_lfd, OP_SETLK, F_WRLCK, 0, OFF_T_MAX); rc = mdbx_lck_op(env->me_lfd, OP_SETLKW, F_WRLCK, 0, OFF_T_MAX);
if (rc == 0) { if (rc == 0) {
/* got both exclusive */ /* got both exclusive */
return MDBX_RESULT_TRUE; return MDBX_RESULT_TRUE;
@ -256,7 +256,7 @@ void __cold mdbx_lck_destroy(MDBX_env *env) {
if (mdbx_lck_op(env->me_fd, OP_SETLK, if (mdbx_lck_op(env->me_fd, OP_SETLK,
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0,
OFF_T_MAX) == 0 && OFF_T_MAX) == 0 &&
mdbx_lck_op(env->me_lfd, OP_SETLK, F_WRLCK, 0, OFF_T_MAX) == 0) { mdbx_lck_op(env->me_lfd, OP_SETLKW, F_WRLCK, 0, OFF_T_MAX) == 0) {
mdbx_info("%s: got exclusive, drown mutexes", mdbx_func_); mdbx_info("%s: got exclusive, drown mutexes", mdbx_func_);
int rc = pthread_mutex_destroy(&env->me_lck->mti_rmutex); int rc = pthread_mutex_destroy(&env->me_lck->mti_rmutex);
if (rc == 0) if (rc == 0)