mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 02:44:14 +08:00
mdbx-posix: rework LCK seize/destroy.
This commit is contained in:
parent
2536dc47ac
commit
5eb3b77efe
@ -152,7 +152,8 @@ int __cold mdbx_lck_seize(MDBX_env *env) {
|
|||||||
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0,
|
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0,
|
||||||
OFF_T_MAX);
|
OFF_T_MAX);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
/* got dxb-exclusive, try lck-exclusive */
|
continue_exclusive:
|
||||||
|
/* got dxb-exclusive, continue lck-exclusive */
|
||||||
rc = mdbx_lck_op(env->me_lfd, OP_SETLKW, 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 */
|
||||||
@ -169,7 +170,14 @@ int __cold mdbx_lck_seize(MDBX_env *env) {
|
|||||||
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK,
|
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK,
|
||||||
env->me_pid, 1);
|
env->me_pid, 1);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
/* got dxb-shared, try lck-shared */
|
/* got dxb-shared, try again dxb-exclusive */
|
||||||
|
rc = mdbx_lck_op(env->me_fd, OP_SETLK,
|
||||||
|
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0,
|
||||||
|
OFF_T_MAX);
|
||||||
|
if (rc == 0)
|
||||||
|
goto continue_exclusive;
|
||||||
|
|
||||||
|
/* continue lck-shared */
|
||||||
rc = mdbx_lck_op(env->me_lfd, OP_SETLKW, F_RDLCK, 0, 1);
|
rc = mdbx_lck_op(env->me_lfd, OP_SETLKW, F_RDLCK, 0, 1);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
/* got both dxb and lck shared lock */
|
/* got both dxb and lck shared lock */
|
||||||
@ -266,6 +274,9 @@ void __cold mdbx_lck_destroy(MDBX_env *env) {
|
|||||||
if (env->me_lfd != INVALID_HANDLE_VALUE) {
|
if (env->me_lfd != INVALID_HANDLE_VALUE) {
|
||||||
/* try get exclusive access */
|
/* try get exclusive access */
|
||||||
if (env->me_lck &&
|
if (env->me_lck &&
|
||||||
|
mdbx_lck_op(env->me_fd, OP_SETLK,
|
||||||
|
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 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_SETLK, 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);
|
||||||
@ -273,6 +284,7 @@ void __cold mdbx_lck_destroy(MDBX_env *env) {
|
|||||||
rc = pthread_mutex_destroy(&env->me_lck->mti_wmutex);
|
rc = pthread_mutex_destroy(&env->me_lck->mti_wmutex);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
(void)rc;
|
(void)rc;
|
||||||
|
msync(env->me_lck, env->me_os_psize, MS_ASYNC);
|
||||||
}
|
}
|
||||||
(void)mdbx_lck_op(env->me_lfd, OP_SETLK, F_UNLCK, 0, OFF_T_MAX);
|
(void)mdbx_lck_op(env->me_lfd, OP_SETLK, F_UNLCK, 0, OFF_T_MAX);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user