Skip to content

Commit 79b12bb

Browse files
committed
Tweak robust mutex detection for glibc
1 parent 4e1ec79 commit 79b12bb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

libraries/liblmdb/mdb.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ typedef SSIZE_T ssize_t;
238238
#define MDB_OWNERDEAD EOWNERDEAD /**< #LOCK_MUTEX0() result if dead owner */
239239
#endif
240240

241-
241+
#ifdef __GLIBC__
242+
#define GLIBC_VER ((__GLIBC__ << 16 )| __GLIBC_MINOR__)
243+
#endif
242244
/** Some platforms define the EOWNERDEAD error code
243245
* even though they don't support Robust Mutexes.
244246
* Compile with -DMDB_USE_ROBUST=0, or use some other
@@ -248,12 +250,19 @@ typedef SSIZE_T ssize_t;
248250
* either.)
249251
*/
250252
#ifndef MDB_USE_ROBUST
251-
/* Android currently lacks Robust Mutex support */
252-
#if defined(ANDROID) && defined(MDB_USE_POSIX_MUTEX) && !defined(MDB_USE_ROBUST)
253-
#define MDB_USE_ROBUST 0
254-
#else
255-
#define MDB_USE_ROBUST 1
256-
#endif
253+
/* Android currently lacks Robust Mutex support. So does glibc < 2.4. */
254+
# if defined(MDB_USE_POSIX_MUTEX) && (defined(ANDROID) || \
255+
(defined(__GLIBC__) && GLIBC_VER < 0x020004))
256+
# define MDB_USE_ROBUST 0
257+
# else
258+
# define MDB_USE_ROBUST 1
259+
/* glibc < 2.10 only provided _np API */
260+
# if defined(__GLIBC__) && GLIBC_VER < 0x02000a
261+
# define PTHREAD_MUTEX_ROBUST PTHREAD_MUTEX_ROBUST_NP
262+
# define pthread_mutexattr_setrobust(attr, flag) pthread_mutexattr_setrobust_np(attr, flag)
263+
# define pthread_mutex_consistent(mutex) pthread_mutex_consistent_np(mutex)
264+
# endif
265+
# endif
257266
#endif /* MDB_USE_ROBUST */
258267

259268
#if defined(MDB_OWNERDEAD) && MDB_USE_ROBUST

0 commit comments

Comments
 (0)