summaryrefslogtreecommitdiff
path: root/src/dbinc/mutex_int.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbinc/mutex_int.h')
-rw-r--r--src/dbinc/mutex_int.h67
1 files changed, 45 insertions, 22 deletions
diff --git a/src/dbinc/mutex_int.h b/src/dbinc/mutex_int.h
index b9bccdf7..4a4468af 100644
--- a/src/dbinc/mutex_int.h
+++ b/src/dbinc/mutex_int.h
@@ -1,7 +1,7 @@
/*
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -73,6 +73,14 @@ extern "C" {
else \
RET_SET((pthread_mutex_lock(&(mutexp)->u.m.mutex)), ret); \
} while (0)
+#define RET_SET_PTHREAD_TIMEDLOCK(mutexp, timespec, ret) do { \
+ if (F_ISSET(mutexp, DB_MUTEX_SHARED)) \
+ RET_SET(pthread_rwlock_timedwrlock(&(mutexp)->u.rwlock, \
+ (timespec)), ret); \
+ else \
+ RET_SET(pthread_mutex_timedlock(&(mutexp)->u.m.mutex, \
+ (timespec)), ret); \
+} while (0)
#define RET_SET_PTHREAD_TRYLOCK(mutexp, ret) do { \
if (F_ISSET(mutexp, DB_MUTEX_SHARED)) \
RET_SET((pthread_rwlock_trywrlock(&(mutexp)->u.rwlock)), \
@@ -84,6 +92,9 @@ extern "C" {
#else
#define RET_SET_PTHREAD_LOCK(mutexp, ret) \
RET_SET(pthread_mutex_lock(&(mutexp)->u.m.mutex), ret);
+#define RET_SET_PTHREAD_TIMEDLOCK(mutexp, timespec, ret) \
+ RET_SET(pthread_mutex_timedlock(&(mutexp)->u.m.mutex, \
+ (timespec)), ret);
#define RET_SET_PTHREAD_TRYLOCK(mutexp, ret) \
RET_SET(pthread_mutex_trylock(&(mutexp)->u.m.mutex), ret);
#endif
@@ -267,6 +278,11 @@ typedef abilock_t tsl_t;
#include <sys/machlock.h>
typedef lock_t tsl_t;
+/*
+ * Solaris requires 8 byte alignment for pthread_mutex_t values.
+ */
+#define MUTEX_ALIGN 8
+
/*
* The functions are declared in <sys/machlock.h>, but under #ifdef KERNEL.
* Re-declare them here to avoid warnings.
@@ -778,6 +794,7 @@ MUTEX_SET(tsl_t *tsl) {
static inline void
MUTEX_UNSET(tsl_t *tsl) {
__asm__ volatile(
+ " .set mips2 \n"
" .set noreorder \n"
" sync \n"
" sw $0, %0 \n"
@@ -892,15 +909,22 @@ struct __db_mutexmgr {
REGINFO reginfo; /* Region information */
void *mutex_array; /* Base of the mutex array */
+#ifdef HAVE_FAILCHK_BROADCAST
+ /*
+ * The mutex lock functions wait for at most this long between checks
+ * for DB_MUTEX_OWNER_DEAD. This field needs no mutex protection.
+ */
+ db_timeout_t failchk_polltime;
+#endif
};
/* Macros to lock/unlock the mutex region as a whole. */
-#define MUTEX_SYSTEM_LOCK(dbenv) \
- MUTEX_LOCK(dbenv, ((DB_MUTEXREGION *) \
- (dbenv)->mutex_handle->reginfo.primary)->mtx_region)
-#define MUTEX_SYSTEM_UNLOCK(dbenv) \
- MUTEX_UNLOCK(dbenv, ((DB_MUTEXREGION *) \
- (dbenv)->mutex_handle->reginfo.primary)->mtx_region)
+#define MUTEX_SYSTEM_LOCK(env) \
+ MUTEX_LOCK(env, ((DB_MUTEXREGION *) \
+ (env)->mutex_handle->reginfo.primary)->mtx_region)
+#define MUTEX_SYSTEM_UNLOCK(env) \
+ MUTEX_UNLOCK(env, ((DB_MUTEXREGION *) \
+ (env)->mutex_handle->reginfo.primary)->mtx_region)
/*
* DB_MUTEXREGION --
@@ -927,6 +951,16 @@ typedef struct __db_mutexregion { /* SHARED */
} DB_MUTEXREGION;
#ifdef HAVE_MUTEX_SUPPORT
+/*
+ * MTX_DIAG turns on the recording of when and where a mutex was locked. It has
+ * a large impact, and should only be turned on when debugging mutexes.
+ */
+#define MUTEX_STACK_TEXT_SIZE 600
+typedef struct __mutex_history { /* SHARED */
+ db_timespec when;
+ char stacktext[MUTEX_STACK_TEXT_SIZE];
+} MUTEX_HISTORY;
+
struct __db_mutex_t { /* SHARED */ /* Mutex. */
#ifdef MUTEX_FIELDS
MUTEX_FIELDS /* Opaque thread mutex structures. */
@@ -959,9 +993,9 @@ struct __db_mutex_t { /* SHARED */ /* Mutex. */
db_mutex_t mutex_next_link; /* Linked list of free mutexes. */
-#ifdef HAVE_STATISTICS
int alloc_id; /* Allocation ID. */
+#ifdef HAVE_STATISTICS
u_int32_t mutex_set_wait; /* Granted after wait. */
u_int32_t mutex_set_nowait; /* Granted without waiting. */
#ifdef HAVE_SHARED_LATCHES
@@ -973,7 +1007,9 @@ struct __db_mutex_t { /* SHARED */ /* Mutex. */
u_int32_t hybrid_wakeup; /* for counting spurious wakeups */
#endif
#endif
-
+#ifdef MUTEX_DIAG
+ MUTEX_HISTORY mutex_history;
+#endif
/*
* A subset of the flag arguments for __mutex_alloc().
*
@@ -992,19 +1028,6 @@ struct __db_mutex_t { /* SHARED */ /* Mutex. */
(indx) * \
((DB_MUTEXREGION *)env->mutex_handle->reginfo.primary)->mutex_size))
-/*
- * Check that a particular mutex is exclusively held at least by someone, not
- * necessarily the current thread.
- */
-#ifdef HAVE_MUTEX_SUPPORT
-#define MUTEX_IS_OWNED(env, mutex) \
- (mutex == MUTEX_INVALID || !MUTEX_ON(env) || \
- F_ISSET(env->dbenv, DB_ENV_NOLOCKING) || \
- F_ISSET(MUTEXP_SET(env, mutex), DB_MUTEX_LOCKED))
-#else
-#define MUTEX_IS_OWNED(env, mutex) 0
-#endif
-
#if defined(HAVE_MUTEX_HYBRID) || defined(DB_WIN32) || \
(defined(HAVE_SHARED_LATCHES) && !defined(HAVE_MUTEX_PTHREADS))
#define MUTEXP_IS_BUSY(mutexp) \