diff options
author | Luke Chen <luke.chen@mongodb.com> | 2019-08-21 05:23:37 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-08-21 05:23:37 +0000 |
commit | ac41c65f6355f83aac70136324c98561ac79daa1 (patch) | |
tree | a7c3f7ef090b59c6a06838a02c96bd1d49e1c729 /src/third_party/wiredtiger/src/include/mutex.h | |
parent | f54709196711c63a429b71f47c584661286d675f (diff) | |
download | mongo-ac41c65f6355f83aac70136324c98561ac79daa1.tar.gz |
Import wiredtiger: 7dfd9391862bc9a6d84868c4dc51689c45a3aacf from branch mongodb-4.4
ref: c809757d8b..7dfd939186
for: 4.3.1
WT-4658 Apply Clang Format
WT-4810 Adding WT_ERR_ASSERT and WT_RET_ASSERT macros
WT-5046 Prepared transactions aren't properly cleared from global table with WT_CONN_LOG_DEBUG_MODE enabled
Diffstat (limited to 'src/third_party/wiredtiger/src/include/mutex.h')
-rw-r--r-- | src/third_party/wiredtiger/src/include/mutex.h | 138 |
1 files changed, 68 insertions, 70 deletions
diff --git a/src/third_party/wiredtiger/src/include/mutex.h b/src/third_party/wiredtiger/src/include/mutex.h index c7382fc94dc..63283c92633 100644 --- a/src/third_party/wiredtiger/src/include/mutex.h +++ b/src/third_party/wiredtiger/src/include/mutex.h @@ -13,20 +13,19 @@ * locking operations that are expected to block. */ struct __wt_condvar { - const char *name; /* Mutex name for debugging */ + const char *name; /* Mutex name for debugging */ - wt_mutex_t mtx; /* Mutex */ - wt_cond_t cond; /* Condition variable */ + wt_mutex_t mtx; /* Mutex */ + wt_cond_t cond; /* Condition variable */ - int waiters; /* Numbers of waiters, or - -1 if signalled with no waiters. */ - /* - * The following fields are used for automatically adjusting condition - * variable wait times. - */ - uint64_t min_wait; /* Minimum wait duration */ - uint64_t max_wait; /* Maximum wait duration */ - uint64_t prev_wait; /* Wait duration used last time */ + int waiters; /* Numbers of waiters, or + -1 if signalled with no waiters. */ + /* + * The following fields are used for automatically adjusting condition variable wait times. + */ + uint64_t min_wait; /* Minimum wait duration */ + uint64_t max_wait; /* Maximum wait duration */ + uint64_t prev_wait; /* Wait duration used last time */ }; /* @@ -37,26 +36,26 @@ struct __wt_condvar { * Don't modify this structure without understanding the read/write locking * functions. */ -struct __wt_rwlock { /* Read/write lock */ - volatile union { - uint64_t v; /* Full 64-bit value */ - struct { - uint8_t current; /* Current ticket */ - uint8_t next; /* Next available ticket */ - uint8_t reader; /* Read queue ticket */ - uint8_t readers_queued; /* Count of queued readers */ - uint32_t readers_active;/* Count of active readers */ - } s; - } u; +struct __wt_rwlock { /* Read/write lock */ + volatile union { + uint64_t v; /* Full 64-bit value */ + struct { + uint8_t current; /* Current ticket */ + uint8_t next; /* Next available ticket */ + uint8_t reader; /* Read queue ticket */ + uint8_t readers_queued; /* Count of queued readers */ + uint32_t readers_active; /* Count of active readers */ + } s; + } u; - int16_t stat_read_count_off; /* read acquisitions offset */ - int16_t stat_write_count_off; /* write acquisitions offset */ - int16_t stat_app_usecs_off; /* waiting application threads offset */ - int16_t stat_int_usecs_off; /* waiting server threads offset */ - int16_t stat_session_usecs_off; /* waiting session offset */ + int16_t stat_read_count_off; /* read acquisitions offset */ + int16_t stat_write_count_off; /* write acquisitions offset */ + int16_t stat_app_usecs_off; /* waiting application threads offset */ + int16_t stat_int_usecs_off; /* waiting server threads offset */ + int16_t stat_session_usecs_off; /* waiting session offset */ - WT_CONDVAR *cond_readers; /* Blocking readers */ - WT_CONDVAR *cond_writers; /* Blocking writers */ + WT_CONDVAR *cond_readers; /* Blocking readers */ + WT_CONDVAR *cond_writers; /* Blocking writers */ }; /* @@ -66,24 +65,25 @@ struct __wt_rwlock { /* Read/write lock */ * Implemented as a macro so we can pass in a statistics field and convert * it into a statistics structure array offset. */ -#define WT_RWLOCK_INIT_TRACKED(session, l, name) do { \ - WT_RET(__wt_rwlock_init(session, l)); \ - (l)->stat_read_count_off = (int16_t)WT_STATS_FIELD_TO_OFFSET( \ - S2C(session)->stats, lock_##name##_read_count); \ - (l)->stat_write_count_off = (int16_t)WT_STATS_FIELD_TO_OFFSET( \ - S2C(session)->stats, lock_##name##_write_count); \ - (l)->stat_app_usecs_off = (int16_t)WT_STATS_FIELD_TO_OFFSET( \ - S2C(session)->stats, lock_##name##_wait_application); \ - (l)->stat_int_usecs_off = (int16_t)WT_STATS_FIELD_TO_OFFSET( \ - S2C(session)->stats, lock_##name##_wait_internal); \ -} while (0) +#define WT_RWLOCK_INIT_TRACKED(session, l, name) \ + do { \ + WT_RET(__wt_rwlock_init(session, l)); \ + (l)->stat_read_count_off = \ + (int16_t)WT_STATS_FIELD_TO_OFFSET(S2C(session)->stats, lock_##name##_read_count); \ + (l)->stat_write_count_off = \ + (int16_t)WT_STATS_FIELD_TO_OFFSET(S2C(session)->stats, lock_##name##_write_count); \ + (l)->stat_app_usecs_off = \ + (int16_t)WT_STATS_FIELD_TO_OFFSET(S2C(session)->stats, lock_##name##_wait_application); \ + (l)->stat_int_usecs_off = \ + (int16_t)WT_STATS_FIELD_TO_OFFSET(S2C(session)->stats, lock_##name##_wait_internal); \ + } while (0) -#define WT_RWLOCK_INIT_SESSION_TRACKED(session, l, name) do { \ - WT_RWLOCK_INIT_TRACKED(session, l, name); \ - (l)->stat_session_usecs_off = \ - (int16_t)WT_SESSION_STATS_FIELD_TO_OFFSET( \ - &(session)->stats, lock_##name##_wait); \ -} while (0) +#define WT_RWLOCK_INIT_SESSION_TRACKED(session, l, name) \ + do { \ + WT_RWLOCK_INIT_TRACKED(session, l, name); \ + (l)->stat_session_usecs_off = \ + (int16_t)WT_SESSION_STATS_FIELD_TO_OFFSET(&(session)->stats, lock_##name##_wait); \ + } while (0) /* * Spin locks: @@ -92,39 +92,37 @@ struct __wt_rwlock { /* Read/write lock */ * while holding the spin lock are expected to complete in a small number of * instructions). */ -#define SPINLOCK_GCC 0 -#define SPINLOCK_MSVC 1 -#define SPINLOCK_PTHREAD_MUTEX 2 -#define SPINLOCK_PTHREAD_MUTEX_ADAPTIVE 3 +#define SPINLOCK_GCC 0 +#define SPINLOCK_MSVC 1 +#define SPINLOCK_PTHREAD_MUTEX 2 +#define SPINLOCK_PTHREAD_MUTEX_ADAPTIVE 3 struct __wt_spinlock { #if SPINLOCK_TYPE == SPINLOCK_GCC - WT_CACHE_LINE_PAD_BEGIN - volatile int lock; -#elif SPINLOCK_TYPE == SPINLOCK_PTHREAD_MUTEX || \ - SPINLOCK_TYPE == SPINLOCK_PTHREAD_MUTEX_ADAPTIVE || \ - SPINLOCK_TYPE == SPINLOCK_MSVC - wt_mutex_t lock; + WT_CACHE_LINE_PAD_BEGIN + volatile int lock; +#elif SPINLOCK_TYPE == SPINLOCK_PTHREAD_MUTEX || \ + SPINLOCK_TYPE == SPINLOCK_PTHREAD_MUTEX_ADAPTIVE || SPINLOCK_TYPE == SPINLOCK_MSVC + wt_mutex_t lock; #else #error Unknown spinlock type #endif - const char *name; /* Mutex name */ + const char *name; /* Mutex name */ - /* - * We track acquisitions and time spent waiting for some locks. For - * performance reasons and to make it possible to write generic code - * that tracks statistics for different locks, we store the offset - * of the statistics fields to be updated during lock acquisition. - */ - int16_t stat_count_off; /* acquisitions offset */ - int16_t stat_app_usecs_off; /* waiting application threads offset */ - int16_t stat_int_usecs_off; /* waiting server threads offset */ - int16_t stat_session_usecs_off; /* waiting session offset */ + /* + * We track acquisitions and time spent waiting for some locks. For performance reasons and to + * make it possible to write generic code that tracks statistics for different locks, we store + * the offset of the statistics fields to be updated during lock acquisition. + */ + int16_t stat_count_off; /* acquisitions offset */ + int16_t stat_app_usecs_off; /* waiting application threads offset */ + int16_t stat_int_usecs_off; /* waiting server threads offset */ + int16_t stat_session_usecs_off; /* waiting session offset */ - int8_t initialized; /* Lock initialized, for cleanup */ + int8_t initialized; /* Lock initialized, for cleanup */ #if SPINLOCK_TYPE == SPINLOCK_GCC - WT_CACHE_LINE_PAD_END + WT_CACHE_LINE_PAD_END #endif }; |