mirror of
https://github.com/isar/libmdbx.git
synced 2025-04-24 05:52:25 +08:00
mdbx: Add MDB_USE_ROBUST to control Robust Mutexes.
Backported from origin. Change-Id: I416c1d09fb1f290423f29a84831accdaf4436ab0
This commit is contained in:
parent
372a6d8521
commit
b430c9a22f
13
Makefile
13
Makefile
@ -1,25 +1,22 @@
|
||||
# Makefile for liblmdb (Lightning memory-mapped database library).
|
||||
# Makefile for libmdbx (lightning memory-mapped database library for Linux).
|
||||
|
||||
########################################################################
|
||||
# Configuration. The compiler options must enable threaded compilation.
|
||||
#
|
||||
# Preprocessor macros (for CPPFLAGS) of interest...
|
||||
# Preprocessor macros (for XCFLAGS) of interest...
|
||||
# Note that the defaults should already be correct for most
|
||||
# platforms; you should not need to change any of these.
|
||||
# Read their descriptions in mdb.c if you do:
|
||||
#
|
||||
# - MDB_USE_POSIX_SEM
|
||||
# - MDB_DSYNC
|
||||
# - MDB_FDATASYNC
|
||||
# - MDB_FDATASYNC_WORKS
|
||||
# - MDB_USE_PWRITEV
|
||||
# - MDB_USE_ROBUST
|
||||
#
|
||||
# There may be other macros in mdb.c of interest. You should
|
||||
# read mdb.c before changing any of them.
|
||||
#
|
||||
CC ?= gcc
|
||||
XCFLAGS ?=
|
||||
CFLAGS ?= -O2 -g -Wall -Werror -Wno-unused-parameter
|
||||
CFLAGS += -pthread
|
||||
CFLAGS += -pthread $(XCFLAGS)
|
||||
prefix ?= /usr/local
|
||||
|
||||
########################################################################
|
||||
|
20
mdb.c
20
mdb.c
@ -142,6 +142,18 @@
|
||||
# define mdb_func_ "<mdb_unknown>"
|
||||
#endif
|
||||
|
||||
/** Some platforms define the EOWNERDEAD error code
|
||||
* even though they don't support Robust Mutexes.
|
||||
* Compile with -DMDB_USE_ROBUST=0.
|
||||
*/
|
||||
#ifndef MDB_USE_ROBUST
|
||||
# if defined(EOWNERDEAD) && defined(PTHREAD_MUTEX_ROBUST) && !defined(ANDROID)
|
||||
# define MDB_USE_ROBUST 1
|
||||
# else
|
||||
# define MDB_USE_ROBUST 0
|
||||
# endif
|
||||
#endif /* MDB_USE_ROBUST */
|
||||
|
||||
/* Internal error codes, not exposed outside liblmdb */
|
||||
#define MDB_NO_ROOT (MDB_LAST_ERRCODE + 10)
|
||||
|
||||
@ -4627,9 +4639,9 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
|
||||
|
||||
if ((rc = pthread_mutexattr_init(&mattr))
|
||||
|| (rc = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED))
|
||||
#ifdef EOWNERDEAD
|
||||
#if MDB_USE_ROBUST
|
||||
|| (rc = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST))
|
||||
#endif
|
||||
#endif /* MDB_USE_ROBUST */
|
||||
|| (rc = pthread_mutex_init(&env->me_txns->mti_rmutex, &mattr))
|
||||
|| (rc = pthread_mutex_init(&env->me_txns->mti_wmutex, &mattr)))
|
||||
goto fail;
|
||||
@ -10003,7 +10015,7 @@ mdb_reader_check0(MDB_env *env, int rlocked, int *dead)
|
||||
static int __cold
|
||||
mdb_mutex_failed(MDB_env *env, pthread_mutex_t *mutex, int rc)
|
||||
{
|
||||
#ifdef EOWNERDEAD
|
||||
#if MDB_USE_ROBUST
|
||||
if (unlikely(rc == EOWNERDEAD)) {
|
||||
int rlocked, rc2;
|
||||
|
||||
@ -10038,7 +10050,7 @@ mdb_mutex_failed(MDB_env *env, pthread_mutex_t *mutex, int rc)
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
}
|
||||
#endif /* EOWNERDEAD */
|
||||
#endif /* MDB_USE_ROBUST */
|
||||
if (unlikely(rc)) {
|
||||
mdb_debug("lock mutex failed, %s", mdb_strerror(rc));
|
||||
if (rc != EDEADLK) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user