"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "storage/tokudb/PerconaFT/portability/toku_pthread.h" between
mariadb-10.2.21.tar.gz and mariadb-10.2.22.tar.gz

About: MariaDB is a relational database management system (a drop-in replacement for MySQL). Stable (GA) release (10.2).

toku_pthread.h  (mariadb-10.2.21):toku_pthread.h  (mariadb-10.2.22)
skipping to change at line 66 skipping to change at line 66
typedef struct timespec toku_timespec_t; typedef struct timespec toku_timespec_t;
// TODO: break this include loop // TODO: break this include loop
#include <pthread.h> #include <pthread.h>
typedef pthread_mutexattr_t toku_pthread_mutexattr_t; typedef pthread_mutexattr_t toku_pthread_mutexattr_t;
struct toku_mutex_t { struct toku_mutex_t {
pthread_mutex_t pmutex; pthread_mutex_t pmutex;
struct PSI_mutex struct PSI_mutex
*psi_mutex; /* The performance schema instrumentation hook */ *psi_mutex; /* The performance schema instrumentation hook */
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
pthread_t owner; // = pthread_self(); // for debugging pthread_t owner; // = pthread_self(); // for debugging
bool locked; bool locked;
bool valid; bool valid;
pfs_key_t instr_key_id; pfs_key_t instr_key_id;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
}; };
struct toku_cond_t { struct toku_cond_t {
pthread_cond_t pcond; pthread_cond_t pcond;
struct PSI_cond *psi_cond; struct PSI_cond *psi_cond;
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
pfs_key_t instr_key_id; pfs_key_t instr_key_id;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
}; };
#ifdef TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
#define TOKU_COND_INITIALIZER \ #define TOKU_COND_INITIALIZER \
{ \ { \
.pcond = PTHREAD_COND_INITIALIZER, .psi_cond = nullptr, \ .pcond = PTHREAD_COND_INITIALIZER, .psi_cond = nullptr, \
.instr_key_id = 0 \ .instr_key_id = 0 \
} }
#else #else
#define TOKU_COND_INITIALIZER \ #define TOKU_COND_INITIALIZER \
{ .pcond = PTHREAD_COND_INITIALIZER, .psi_cond = nullptr } { .pcond = PTHREAD_COND_INITIALIZER, .psi_cond = nullptr }
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
struct toku_pthread_rwlock_t { struct toku_pthread_rwlock_t {
pthread_rwlock_t rwlock; pthread_rwlock_t rwlock;
struct PSI_rwlock *psi_rwlock; struct PSI_rwlock *psi_rwlock;
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
pfs_key_t instr_key_id; pfs_key_t instr_key_id;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
}; };
typedef struct toku_mutex_aligned { typedef struct toku_mutex_aligned {
toku_mutex_t aligned_mutex __attribute__((__aligned__(64))); toku_mutex_t aligned_mutex __attribute__((__aligned__(64)));
} toku_mutex_aligned_t; } toku_mutex_aligned_t;
// Initializing with {} will fill in a struct with all zeros. // Initializing with {} will fill in a struct with all zeros.
// But you may also need a pragma to suppress the warnings, as follows // But you may also need a pragma to suppress the warnings, as follows
// //
// #pragma GCC diagnostic push // #pragma GCC diagnostic push
// #pragma GCC diagnostic ignored "-Wmissing-field-initializers" // #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
// toku_mutex_t foo = ZERO_MUTEX_INITIALIZER; // toku_mutex_t foo = ZERO_MUTEX_INITIALIZER;
// #pragma GCC diagnostic pop // #pragma GCC diagnostic pop
// //
// In general it will be a lot of busy work to make this codebase compile // In general it will be a lot of busy work to make this codebase compile
// cleanly with -Wmissing-field-initializers // cleanly with -Wmissing-field-initializers
#define ZERO_MUTEX_INITIALIZER \ #define ZERO_MUTEX_INITIALIZER \
{} {}
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
#define TOKU_MUTEX_INITIALIZER \ #define TOKU_MUTEX_INITIALIZER \
{ \ { \
.pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr, .owner = 0, \ .pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr, .owner = 0, \
.locked = false, .valid = true, .instr_key_id = 0 \ .locked = false, .valid = true, .instr_key_id = 0 \
} }
#else #else
#define TOKU_MUTEX_INITIALIZER \ #define TOKU_MUTEX_INITIALIZER \
{ .pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr } { .pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr }
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
// Darwin doesn't provide adaptive mutexes // Darwin doesn't provide adaptive mutexes
#if defined(__APPLE__) #if defined(__APPLE__)
#define TOKU_MUTEX_ADAPTIVE PTHREAD_MUTEX_DEFAULT #define TOKU_MUTEX_ADAPTIVE PTHREAD_MUTEX_DEFAULT
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
#define TOKU_ADAPTIVE_MUTEX_INITIALIZER \ #define TOKU_ADAPTIVE_MUTEX_INITIALIZER \
{ \ { \
.pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr, .owner = 0, \ .pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr, .owner = 0, \
.locked = false, .valid = true, .instr_key_id = 0 \ .locked = false, .valid = true, .instr_key_id = 0 \
} }
#else #else
#define TOKU_ADAPTIVE_MUTEX_INITIALIZER \ #define TOKU_ADAPTIVE_MUTEX_INITIALIZER \
{ .pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr } { .pmutex = PTHREAD_MUTEX_INITIALIZER, .psi_mutex = nullptr }
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
#else // __FreeBSD__, __linux__, at least #else // __FreeBSD__, __linux__, at least
#define TOKU_MUTEX_ADAPTIVE PTHREAD_MUTEX_ADAPTIVE_NP #define TOKU_MUTEX_ADAPTIVE PTHREAD_MUTEX_ADAPTIVE_NP
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
#define TOKU_ADAPTIVE_MUTEX_INITIALIZER \ #define TOKU_ADAPTIVE_MUTEX_INITIALIZER \
{ \ { \
.pmutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP, .psi_mutex = nullptr, \ .pmutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP, .psi_mutex = nullptr, \
.owner = 0, .locked = false, .valid = true, .instr_key_id = 0 \ .owner = 0, .locked = false, .valid = true, .instr_key_id = 0 \
} }
#else #else
#define TOKU_ADAPTIVE_MUTEX_INITIALIZER \ #define TOKU_ADAPTIVE_MUTEX_INITIALIZER \
{ .pmutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP, .psi_mutex = nullptr } { .pmutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP, .psi_mutex = nullptr }
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
#endif #endif // defined(__APPLE__)
// Different OSes implement mutexes as different amounts of nested structs. // Different OSes implement mutexes as different amounts of nested structs.
// C++ will fill out all missing values with zeroes if you provide at least one // C++ will fill out all missing values with zeroes if you provide at least one
// zero, but it needs the right amount of nesting. // zero, but it needs the right amount of nesting.
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
#define ZERO_COND_INITIALIZER \ #define ZERO_COND_INITIALIZER \
{ 0 } { 0 }
#elif defined(__APPLE__) #elif defined(__APPLE__)
#if TOKU_PTHREAD_DEBUG #if TOKU_PTHREAD_DEBUG
#define ZERO_COND_INITIALIZER \ #define ZERO_COND_INITIALIZER \
skipping to change at line 200 skipping to change at line 200
int r = pthread_mutexattr_settype(attr, type); int r = pthread_mutexattr_settype(attr, type);
assert_zero(r); assert_zero(r);
} }
static inline void static inline void
toku_mutexattr_destroy(toku_pthread_mutexattr_t *attr) { toku_mutexattr_destroy(toku_pthread_mutexattr_t *attr) {
int r = pthread_mutexattr_destroy(attr); int r = pthread_mutexattr_destroy(attr);
assert_zero(r); assert_zero(r);
} }
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
static inline void toku_mutex_assert_locked(const toku_mutex_t *mutex) { static inline void toku_mutex_assert_locked(const toku_mutex_t *mutex) {
invariant(mutex->locked); invariant(mutex->locked);
invariant(mutex->owner == pthread_self()); invariant(mutex->owner == pthread_self());
} }
#else #else
static inline void static inline void
toku_mutex_assert_locked(const toku_mutex_t *mutex __attribute__((unused))) { toku_mutex_assert_locked(const toku_mutex_t *mutex __attribute__((unused))) {
} }
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
// asserting that a mutex is unlocked only makes sense // asserting that a mutex is unlocked only makes sense
// if the calling thread can guaruntee that no other threads // if the calling thread can guaruntee that no other threads
// are trying to lock this mutex at the time of the assertion // are trying to lock this mutex at the time of the assertion
// //
// a good example of this is a tree with mutexes on each node. // a good example of this is a tree with mutexes on each node.
// when a node is locked the caller knows that no other threads // when a node is locked the caller knows that no other threads
// can be trying to lock its childrens' mutexes. the children // can be trying to lock its childrens' mutexes. the children
// are in one of two fixed states: locked or unlocked. // are in one of two fixed states: locked or unlocked.
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
static inline void static inline void
toku_mutex_assert_unlocked(toku_mutex_t *mutex) { toku_mutex_assert_unlocked(toku_mutex_t *mutex) {
invariant(mutex->owner == 0); invariant(mutex->owner == 0);
invariant(!mutex->locked); invariant(!mutex->locked);
} }
#else #else
static inline void toku_mutex_assert_unlocked(toku_mutex_t *mutex static inline void toku_mutex_assert_unlocked(toku_mutex_t *mutex
__attribute__((unused))) {} __attribute__((unused))) {}
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
#define toku_mutex_lock(M) \ #define toku_mutex_lock(M) \
toku_mutex_lock_with_source_location(M, __FILE__, __LINE__) toku_mutex_lock_with_source_location(M, __FILE__, __LINE__)
static inline void toku_cond_init(toku_cond_t *cond, static inline void toku_cond_init(toku_cond_t *cond,
const toku_pthread_condattr_t *attr) { const toku_pthread_condattr_t *attr) {
int r = pthread_cond_init(&cond->pcond, attr); int r = pthread_cond_init(&cond->pcond, attr);
assert_zero(r); assert_zero(r);
} }
#define toku_mutex_trylock(M) \ #define toku_mutex_trylock(M) \
toku_mutex_trylock_with_source_location(M, __FILE__, __LINE__) toku_mutex_trylock_with_source_location(M, __FILE__, __LINE__)
inline void toku_mutex_unlock(toku_mutex_t *mutex) { inline void toku_mutex_unlock(toku_mutex_t *mutex) {
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
invariant(mutex->owner == pthread_self()); invariant(mutex->owner == pthread_self());
invariant(mutex->valid); invariant(mutex->valid);
invariant(mutex->locked); invariant(mutex->locked);
mutex->locked = false; mutex->locked = false;
mutex->owner = 0; mutex->owner = 0;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
toku_instr_mutex_unlock(mutex->psi_mutex); toku_instr_mutex_unlock(mutex->psi_mutex);
int r = pthread_mutex_unlock(&mutex->pmutex); int r = pthread_mutex_unlock(&mutex->pmutex);
assert_zero(r); assert_zero(r);
} }
inline void toku_mutex_lock_with_source_location(toku_mutex_t *mutex, inline void toku_mutex_lock_with_source_location(toku_mutex_t *mutex,
const char *src_file, const char *src_file,
int src_line) { int src_line) {
toku_mutex_instrumentation mutex_instr; toku_mutex_instrumentation mutex_instr;
toku_instr_mutex_lock_start(mutex_instr, *mutex, src_file, src_line); toku_instr_mutex_lock_start(mutex_instr, *mutex, src_file, src_line);
const int r = pthread_mutex_lock(&mutex->pmutex); const int r = pthread_mutex_lock(&mutex->pmutex);
toku_instr_mutex_lock_end(mutex_instr, r); toku_instr_mutex_lock_end(mutex_instr, r);
assert_zero(r); assert_zero(r);
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
invariant(mutex->valid); invariant(mutex->valid);
invariant(!mutex->locked); invariant(!mutex->locked);
invariant(mutex->owner == 0); invariant(mutex->owner == 0);
mutex->locked = true; mutex->locked = true;
mutex->owner = pthread_self(); mutex->owner = pthread_self();
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
} }
inline int toku_mutex_trylock_with_source_location(toku_mutex_t *mutex, inline int toku_mutex_trylock_with_source_location(toku_mutex_t *mutex,
const char *src_file, const char *src_file,
int src_line) { int src_line) {
toku_mutex_instrumentation mutex_instr; toku_mutex_instrumentation mutex_instr;
toku_instr_mutex_trylock_start(mutex_instr, *mutex, src_file, src_line); toku_instr_mutex_trylock_start(mutex_instr, *mutex, src_file, src_line);
const int r = pthread_mutex_lock(&mutex->pmutex); const int r = pthread_mutex_lock(&mutex->pmutex);
toku_instr_mutex_lock_end(mutex_instr, r); toku_instr_mutex_lock_end(mutex_instr, r);
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
if (r == 0) { if (r == 0) {
invariant(mutex->valid); invariant(mutex->valid);
invariant(!mutex->locked); invariant(!mutex->locked);
invariant(mutex->owner == 0); invariant(mutex->owner == 0);
mutex->locked = true; mutex->locked = true;
mutex->owner = pthread_self(); mutex->owner = pthread_self();
} }
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
return r; return r;
} }
#define toku_cond_wait(C, M) \ #define toku_cond_wait(C, M) \
toku_cond_wait_with_source_location(C, M, __FILE__, __LINE__) toku_cond_wait_with_source_location(C, M, __FILE__, __LINE__)
#define toku_cond_timedwait(C, M, W) \ #define toku_cond_timedwait(C, M, W) \
toku_cond_timedwait_with_source_location(C, M, W, __FILE__, __LINE__) toku_cond_timedwait_with_source_location(C, M, W, __FILE__, __LINE__)
inline void toku_cond_init(const toku_instr_key &key, inline void toku_cond_init(const toku_instr_key &key,
skipping to change at line 322 skipping to change at line 322
toku_instr_cond_destroy(cond->psi_cond); toku_instr_cond_destroy(cond->psi_cond);
int r = pthread_cond_destroy(&cond->pcond); int r = pthread_cond_destroy(&cond->pcond);
assert_zero(r); assert_zero(r);
} }
inline void toku_cond_wait_with_source_location(toku_cond_t *cond, inline void toku_cond_wait_with_source_location(toku_cond_t *cond,
toku_mutex_t *mutex, toku_mutex_t *mutex,
const char *src_file, const char *src_file,
uint src_line) { uint src_line) {
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
invariant(mutex->locked); invariant(mutex->locked);
mutex->locked = false; mutex->locked = false;
mutex->owner = 0; mutex->owner = 0;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
/* Instrumentation start */ /* Instrumentation start */
toku_cond_instrumentation cond_instr; toku_cond_instrumentation cond_instr;
toku_instr_cond_wait_start(cond_instr, toku_instr_cond_wait_start(cond_instr,
toku_instr_cond_op::cond_wait, toku_instr_cond_op::cond_wait,
*cond, *cond,
*mutex, *mutex,
src_file, src_file,
src_line); src_line);
/* Instrumented code */ /* Instrumented code */
const int r = pthread_cond_wait(&cond->pcond, &mutex->pmutex); const int r = pthread_cond_wait(&cond->pcond, &mutex->pmutex);
/* Instrumentation end */ /* Instrumentation end */
toku_instr_cond_wait_end(cond_instr, r); toku_instr_cond_wait_end(cond_instr, r);
assert_zero(r); assert_zero(r);
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
invariant(!mutex->locked); invariant(!mutex->locked);
mutex->locked = true; mutex->locked = true;
mutex->owner = pthread_self(); mutex->owner = pthread_self();
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
} }
inline int toku_cond_timedwait_with_source_location(toku_cond_t *cond, inline int toku_cond_timedwait_with_source_location(toku_cond_t *cond,
toku_mutex_t *mutex, toku_mutex_t *mutex,
toku_timespec_t *wakeup_at, toku_timespec_t *wakeup_at,
const char *src_file, const char *src_file,
uint src_line) { uint src_line) {
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
invariant(mutex->locked); invariant(mutex->locked);
mutex->locked = false; mutex->locked = false;
mutex->owner = 0; mutex->owner = 0;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
/* Instrumentation start */ /* Instrumentation start */
toku_cond_instrumentation cond_instr; toku_cond_instrumentation cond_instr;
toku_instr_cond_wait_start(cond_instr, toku_instr_cond_wait_start(cond_instr,
toku_instr_cond_op::cond_timedwait, toku_instr_cond_op::cond_timedwait,
*cond, *cond,
*mutex, *mutex,
src_file, src_file,
src_line); src_line);
/* Instrumented code */ /* Instrumented code */
const int r = pthread_cond_timedwait( const int r = pthread_cond_timedwait(
&cond->pcond, &mutex->pmutex, wakeup_at); &cond->pcond, &mutex->pmutex, wakeup_at);
/* Instrumentation end */ /* Instrumentation end */
toku_instr_cond_wait_end(cond_instr, r); toku_instr_cond_wait_end(cond_instr, r);
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
invariant(!mutex->locked); invariant(!mutex->locked);
mutex->locked = true; mutex->locked = true;
mutex->owner = pthread_self(); mutex->owner = pthread_self();
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
return r; return r;
} }
inline void toku_cond_signal(toku_cond_t *cond) { inline void toku_cond_signal(toku_cond_t *cond) {
toku_instr_cond_signal(*cond); toku_instr_cond_signal(*cond);
const int r = pthread_cond_signal(&cond->pcond); const int r = pthread_cond_signal(&cond->pcond);
assert_zero(r); assert_zero(r);
} }
inline void toku_cond_broadcast(toku_cond_t *cond) { inline void toku_cond_broadcast(toku_cond_t *cond) {
toku_instr_cond_broadcast(*cond); toku_instr_cond_broadcast(*cond);
const int r = pthread_cond_broadcast(&cond->pcond); const int r = pthread_cond_broadcast(&cond->pcond);
assert_zero(r); assert_zero(r);
} }
inline void toku_mutex_init(const toku_instr_key &key, inline void toku_mutex_init(const toku_instr_key &key,
toku_mutex_t *mutex, toku_mutex_t *mutex,
const toku_pthread_mutexattr_t *attr) { const toku_pthread_mutexattr_t *attr) {
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
mutex->valid = true; mutex->valid = true;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
toku_instr_mutex_init(key, *mutex); toku_instr_mutex_init(key, *mutex);
const int r = pthread_mutex_init(&mutex->pmutex, attr); const int r = pthread_mutex_init(&mutex->pmutex, attr);
assert_zero(r); assert_zero(r);
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
mutex->locked = false; mutex->locked = false;
invariant(mutex->valid); invariant(mutex->valid);
mutex->valid = true; mutex->valid = true;
mutex->owner = 0; mutex->owner = 0;
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
} }
inline void toku_mutex_destroy(toku_mutex_t *mutex) { inline void toku_mutex_destroy(toku_mutex_t *mutex) {
#if TOKU_PTHREAD_DEBUG #if defined(TOKU_PTHREAD_DEBUG)
invariant(mutex->valid); invariant(mutex->valid);
mutex->valid = false; mutex->valid = false;
invariant(!mutex->locked); invariant(!mutex->locked);
#endif #endif // defined(TOKU_PTHREAD_DEBUG)
toku_instr_mutex_destroy(mutex->psi_mutex); toku_instr_mutex_destroy(mutex->psi_mutex);
int r = pthread_mutex_destroy(&mutex->pmutex); int r = pthread_mutex_destroy(&mutex->pmutex);
assert_zero(r); assert_zero(r);
} }
#define toku_pthread_rwlock_rdlock(RW) \ #define toku_pthread_rwlock_rdlock(RW) \
toku_pthread_rwlock_rdlock_with_source_location(RW, __FILE__, __LINE__) toku_pthread_rwlock_rdlock_with_source_location(RW, __FILE__, __LINE__)
#define toku_pthread_rwlock_wrlock(RW) \ #define toku_pthread_rwlock_wrlock(RW) \
toku_pthread_rwlock_wrlock_with_source_location(RW, __FILE__, __LINE__) toku_pthread_rwlock_wrlock_with_source_location(RW, __FILE__, __LINE__)
 End of changes. 38 change blocks. 
39 lines changed or deleted 39 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)