mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:14:12 +08:00
mdbx: portability - support for musl libc.
Change-Id: Ida8a3bd9da896bc6c00bef931ddf3dce65bef8eb
This commit is contained in:
parent
f2c3fcb6a4
commit
97e4f66d16
@ -22,7 +22,8 @@
|
|||||||
#if defined(EOWNERDEAD) && \
|
#if defined(EOWNERDEAD) && \
|
||||||
!defined(__ANDROID__) /* LY: glibc before 2.10 has a troubles \
|
!defined(__ANDROID__) /* LY: glibc before 2.10 has a troubles \
|
||||||
with Robust Mutex too. */ \
|
with Robust Mutex too. */ \
|
||||||
&& __GLIBC_PREREQ(2, 10)
|
&& (!defined(__GLIBC__) || __GLIBC_PREREQ(2, 10) || \
|
||||||
|
_POSIX_C_SOURCE >= 200809L)
|
||||||
#define MDBX_USE_ROBUST 1
|
#define MDBX_USE_ROBUST 1
|
||||||
#else
|
#else
|
||||||
#define MDBX_USE_ROBUST 0
|
#define MDBX_USE_ROBUST 0
|
||||||
@ -141,10 +142,11 @@ int __cold mdbx_lck_init(MDBX_env *env) {
|
|||||||
goto bailout;
|
goto bailout;
|
||||||
|
|
||||||
#if MDBX_USE_ROBUST
|
#if MDBX_USE_ROBUST
|
||||||
#if __GLIBC_PREREQ(2, 12)
|
#if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 12) && \
|
||||||
rc = pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);
|
!defined(pthread_mutex_consistent) && _POSIX_C_SOURCE < 200809L
|
||||||
#else
|
|
||||||
rc = pthread_mutexattr_setrobust_np(&ma, PTHREAD_MUTEX_ROBUST_NP);
|
rc = pthread_mutexattr_setrobust_np(&ma, PTHREAD_MUTEX_ROBUST_NP);
|
||||||
|
#else
|
||||||
|
rc = pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);
|
||||||
#endif
|
#endif
|
||||||
if (rc)
|
if (rc)
|
||||||
goto bailout;
|
goto bailout;
|
||||||
@ -294,10 +296,6 @@ int __cold mdbx_lck_seize(MDBX_env *env) {
|
|||||||
return internal_seize_lck(env->me_lfd);
|
return internal_seize_lck(env->me_lfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !__GLIBC_PREREQ(2, 12) && !defined(pthread_mutex_consistent)
|
|
||||||
#define pthread_mutex_consistent(mutex) pthread_mutex_consistent_np(mutex)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int __cold mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex,
|
static int __cold mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex,
|
||||||
const int err) {
|
const int err) {
|
||||||
int rc = err;
|
int rc = err;
|
||||||
@ -321,7 +319,12 @@ static int __cold mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex,
|
|||||||
int check_rc = mdbx_reader_check0(env, rlocked, NULL);
|
int check_rc = mdbx_reader_check0(env, rlocked, NULL);
|
||||||
check_rc = (check_rc == MDBX_SUCCESS) ? MDBX_RESULT_TRUE : check_rc;
|
check_rc = (check_rc == MDBX_SUCCESS) ? MDBX_RESULT_TRUE : check_rc;
|
||||||
|
|
||||||
|
#if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 12) && \
|
||||||
|
!defined(pthread_mutex_consistent) && _POSIX_C_SOURCE < 200809L
|
||||||
|
int mreco_rc = pthread_mutex_consistent_np(mutex);
|
||||||
|
#else
|
||||||
int mreco_rc = pthread_mutex_consistent(mutex);
|
int mreco_rc = pthread_mutex_consistent(mutex);
|
||||||
|
#endif
|
||||||
check_rc = (mreco_rc == 0) ? check_rc : mreco_rc;
|
check_rc = (mreco_rc == 0) ? check_rc : mreco_rc;
|
||||||
|
|
||||||
if (unlikely(mreco_rc))
|
if (unlikely(mreco_rc))
|
||||||
@ -332,6 +335,8 @@ static int __cold mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex,
|
|||||||
pthread_mutex_unlock(mutex);
|
pthread_mutex_unlock(mutex);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void)mutex;
|
||||||
#endif /* MDBX_USE_ROBUST */
|
#endif /* MDBX_USE_ROBUST */
|
||||||
|
|
||||||
mdbx_error("mutex (un)lock failed, %s", mdbx_strerror(err));
|
mdbx_error("mutex (un)lock failed, %s", mdbx_strerror(err));
|
||||||
|
@ -1331,7 +1331,7 @@ const char *__cold mdbx_strerror_r(int errnum, char *buf, size_t buflen) {
|
|||||||
errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (DWORD)buflen,
|
errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (DWORD)buflen,
|
||||||
NULL);
|
NULL);
|
||||||
return size ? buf : NULL;
|
return size ? buf : NULL;
|
||||||
#elif defined(_GNU_SOURCE)
|
#elif defined(_GNU_SOURCE) && defined(__GLIBC__)
|
||||||
/* GNU-specific */
|
/* GNU-specific */
|
||||||
msg = strerror_r(errnum, buf, buflen);
|
msg = strerror_r(errnum, buf, buflen);
|
||||||
#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
|
#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user