Commit a7c9bf2c authored by Marc Alff's avatar Marc Alff

Bug#51295 Build warnings in mdl.cc

Before this fix, the performance schema instrumentation
in mdl.h / mdl.cc was incomplete, causing:
- build warnings,
- no data collection for the performance schema

This fix:
- added instrumentation helpers for the new preferred
  reader read write lock, mysql_prlock_*
- implemented completely the performance schema
  instrumentation of mdl.h / mdl.cc
parent 8c28d0d1
...@@ -106,6 +106,22 @@ struct st_mysql_rwlock ...@@ -106,6 +106,22 @@ struct st_mysql_rwlock
struct PSI_rwlock *m_psi; struct PSI_rwlock *m_psi;
}; };
/**
An instrumented prlock structure.
@sa mysql_prlock_t
*/
struct st_mysql_prlock
{
/** The real prlock */
rw_pr_lock_t m_prlock;
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_rwlock_t interface.
*/
struct PSI_rwlock *m_psi;
};
/** /**
Type of an instrumented rwlock. Type of an instrumented rwlock.
@c mysql_rwlock_t is a drop-in replacement for @c pthread_rwlock_t. @c mysql_rwlock_t is a drop-in replacement for @c pthread_rwlock_t.
...@@ -119,6 +135,20 @@ struct st_mysql_rwlock ...@@ -119,6 +135,20 @@ struct st_mysql_rwlock
*/ */
typedef struct st_mysql_rwlock mysql_rwlock_t; typedef struct st_mysql_rwlock mysql_rwlock_t;
/**
Type of an instrumented prlock.
A prlock is a read write lock that 'prefers readers' (pr).
@c mysql_prlock_t is a drop-in replacement for @c rw_pr_lock_t.
@sa mysql_prlock_init
@sa mysql_prlock_rdlock
@sa mysql_prlock_tryrdlock
@sa mysql_prlock_wrlock
@sa mysql_prlock_trywrlock
@sa mysql_prlock_unlock
@sa mysql_prlock_destroy
*/
typedef struct st_mysql_prlock mysql_prlock_t;
/** /**
An instrumented cond structure. An instrumented cond structure.
@sa mysql_cond_t @sa mysql_cond_t
...@@ -281,6 +311,19 @@ typedef struct st_mysql_cond mysql_cond_t; ...@@ -281,6 +311,19 @@ typedef struct st_mysql_cond mysql_cond_t;
#define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW) #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW)
#endif #endif
/**
@def mysql_prlock_init(K, RW)
Instrumented rw_pr_init.
@c mysql_prlock_init is a replacement for @c rw_pr_init.
@param K The PSI_rwlock_key for this instrumented prlock
@param RW The prlock to initialize
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_prlock_init(K, RW) inline_mysql_prlock_init(K, RW)
#else
#define mysql_prlock_init(K, RW) inline_mysql_prlock_init(RW)
#endif
/** /**
@def mysql_rwlock_destroy(RW) @def mysql_rwlock_destroy(RW)
Instrumented rwlock_destroy. Instrumented rwlock_destroy.
...@@ -289,6 +332,14 @@ typedef struct st_mysql_cond mysql_cond_t; ...@@ -289,6 +332,14 @@ typedef struct st_mysql_cond mysql_cond_t;
*/ */
#define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW) #define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW)
/**
@def mysql_prlock_destroy(RW)
Instrumented rw_pr_destroy.
@c mysql_prlock_destroy is a drop-in replacement
for @c rw_pr_destroy.
*/
#define mysql_prlock_destroy(RW) inline_mysql_prlock_destroy(RW)
/** /**
@def mysql_rwlock_rdlock(RW) @def mysql_rwlock_rdlock(RW)
Instrumented rwlock_rdlock. Instrumented rwlock_rdlock.
...@@ -303,6 +354,20 @@ typedef struct st_mysql_cond mysql_cond_t; ...@@ -303,6 +354,20 @@ typedef struct st_mysql_cond mysql_cond_t;
inline_mysql_rwlock_rdlock(RW) inline_mysql_rwlock_rdlock(RW)
#endif #endif
/**
@def mysql_prlock_rdlock(RW)
Instrumented rw_pr_rdlock.
@c mysql_prlock_rdlock is a drop-in replacement
for @c rw_pr_rdlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_prlock_rdlock(RW) \
inline_mysql_prlock_rdlock(RW, __FILE__, __LINE__)
#else
#define mysql_prlock_rdlock(RW) \
inline_mysql_prlock_rdlock(RW)
#endif
/** /**
@def mysql_rwlock_wrlock(RW) @def mysql_rwlock_wrlock(RW)
Instrumented rwlock_wrlock. Instrumented rwlock_wrlock.
...@@ -317,6 +382,20 @@ typedef struct st_mysql_cond mysql_cond_t; ...@@ -317,6 +382,20 @@ typedef struct st_mysql_cond mysql_cond_t;
inline_mysql_rwlock_wrlock(RW) inline_mysql_rwlock_wrlock(RW)
#endif #endif
/**
@def mysql_prlock_wrlock(RW)
Instrumented rw_pr_wrlock.
@c mysql_prlock_wrlock is a drop-in replacement
for @c rw_pr_wrlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_prlock_wrlock(RW) \
inline_mysql_prlock_wrlock(RW, __FILE__, __LINE__)
#else
#define mysql_prlock_wrlock(RW) \
inline_mysql_prlock_wrlock(RW)
#endif
/** /**
@def mysql_rwlock_tryrdlock(RW) @def mysql_rwlock_tryrdlock(RW)
Instrumented rwlock_tryrdlock. Instrumented rwlock_tryrdlock.
...@@ -331,6 +410,20 @@ typedef struct st_mysql_cond mysql_cond_t; ...@@ -331,6 +410,20 @@ typedef struct st_mysql_cond mysql_cond_t;
inline_mysql_rwlock_tryrdlock(RW) inline_mysql_rwlock_tryrdlock(RW)
#endif #endif
/**
@def mysql_prlock_tryrdlock(RW)
Instrumented rw_pr_tryrdlock.
@c mysql_prlock_tryrdlock is a drop-in replacement
for @c rw_pr_tryrdlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_prlock_tryrdlock(RW) \
inline_mysql_prlock_tryrdlock(RW, __FILE__, __LINE__)
#else
#define mysql_prlock_tryrdlock(RW) \
inline_mysql_prlock_tryrdlock(RW)
#endif
/** /**
@def mysql_rwlock_trywrlock(RW) @def mysql_rwlock_trywrlock(RW)
Instrumented rwlock_trywrlock. Instrumented rwlock_trywrlock.
...@@ -345,6 +438,20 @@ typedef struct st_mysql_cond mysql_cond_t; ...@@ -345,6 +438,20 @@ typedef struct st_mysql_cond mysql_cond_t;
inline_mysql_rwlock_trywrlock(RW) inline_mysql_rwlock_trywrlock(RW)
#endif #endif
/**
@def mysql_prlock_trywrlock(RW)
Instrumented rw_pr_trywrlock.
@c mysql_prlock_trywrlock is a drop-in replacement
for @c rw_pr_trywrlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_prlock_trywrlock(RW) \
inline_mysql_prlock_trywrlock(RW, __FILE__, __LINE__)
#else
#define mysql_prlock_trywrlock(RW) \
inline_mysql_prlock_trywrlock(RW)
#endif
/** /**
@def mysql_rwlock_unlock(RW) @def mysql_rwlock_unlock(RW)
Instrumented rwlock_unlock. Instrumented rwlock_unlock.
...@@ -353,9 +460,17 @@ typedef struct st_mysql_cond mysql_cond_t; ...@@ -353,9 +460,17 @@ typedef struct st_mysql_cond mysql_cond_t;
*/ */
#define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW) #define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW)
/**
@def mysql_prlock_unlock(RW)
Instrumented rw_pr_unlock.
@c mysql_prlock_unlock is a drop-in replacement
for @c rw_pr_unlock.
*/
#define mysql_prlock_unlock(RW) inline_mysql_prlock_unlock(RW)
/** /**
@def mysql_cond_init(K, C, A) @def mysql_cond_init(K, C, A)
Instrumented rwlock_init. Instrumented cond_init.
@c mysql_cond_init is a replacement for @c pthread_cond_init. @c mysql_cond_init is a replacement for @c pthread_cond_init.
@param C The cond to initialize @param C The cond to initialize
@param K The PSI_cond_key for this instrumented cond @param K The PSI_cond_key for this instrumented cond
...@@ -599,6 +714,21 @@ static inline int inline_mysql_rwlock_init( ...@@ -599,6 +714,21 @@ static inline int inline_mysql_rwlock_init(
return my_rwlock_init(&that->m_rwlock, NULL); return my_rwlock_init(&that->m_rwlock, NULL);
} }
static inline int inline_mysql_prlock_init(
#ifdef HAVE_PSI_INTERFACE
PSI_rwlock_key key,
#endif
mysql_prlock_t *that)
{
#ifdef HAVE_PSI_INTERFACE
that->m_psi= (PSI_server ? PSI_server->init_rwlock(key, &that->m_prlock)
: NULL);
#else
that->m_psi= NULL;
#endif
return rw_pr_init(&that->m_prlock);
}
static inline int inline_mysql_rwlock_destroy( static inline int inline_mysql_rwlock_destroy(
mysql_rwlock_t *that) mysql_rwlock_t *that)
{ {
...@@ -612,6 +742,19 @@ static inline int inline_mysql_rwlock_destroy( ...@@ -612,6 +742,19 @@ static inline int inline_mysql_rwlock_destroy(
return rwlock_destroy(&that->m_rwlock); return rwlock_destroy(&that->m_rwlock);
} }
static inline int inline_mysql_prlock_destroy(
mysql_prlock_t *that)
{
#ifdef HAVE_PSI_INTERFACE
if (likely(PSI_server && that->m_psi))
{
PSI_server->destroy_rwlock(that->m_psi);
that->m_psi= NULL;
}
#endif
return rw_pr_destroy(&that->m_prlock);
}
static inline int inline_mysql_rwlock_rdlock( static inline int inline_mysql_rwlock_rdlock(
mysql_rwlock_t *that mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
...@@ -638,6 +781,32 @@ static inline int inline_mysql_rwlock_rdlock( ...@@ -638,6 +781,32 @@ static inline int inline_mysql_rwlock_rdlock(
return result; return result;
} }
static inline int inline_mysql_prlock_rdlock(
mysql_prlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_READLOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_rdwait(locker, src_file, src_line);
}
#endif
result= rw_pr_rdlock(&that->m_prlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_rdwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_wrlock( static inline int inline_mysql_rwlock_wrlock(
mysql_rwlock_t *that mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
...@@ -664,6 +833,32 @@ static inline int inline_mysql_rwlock_wrlock( ...@@ -664,6 +833,32 @@ static inline int inline_mysql_rwlock_wrlock(
return result; return result;
} }
static inline int inline_mysql_prlock_wrlock(
mysql_prlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_WRITELOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_wrwait(locker, src_file, src_line);
}
#endif
result= rw_pr_wrlock(&that->m_prlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_wrwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_tryrdlock( static inline int inline_mysql_rwlock_tryrdlock(
mysql_rwlock_t *that mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
...@@ -690,6 +885,32 @@ static inline int inline_mysql_rwlock_tryrdlock( ...@@ -690,6 +885,32 @@ static inline int inline_mysql_rwlock_tryrdlock(
return result; return result;
} }
static inline int inline_mysql_prlock_tryrdlock(
mysql_prlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_TRYREADLOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_rdwait(locker, src_file, src_line);
}
#endif
result= rw_pr_tryrdlock(&that->m_prlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_rdwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_trywrlock( static inline int inline_mysql_rwlock_trywrlock(
mysql_rwlock_t *that mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
...@@ -716,6 +937,32 @@ static inline int inline_mysql_rwlock_trywrlock( ...@@ -716,6 +937,32 @@ static inline int inline_mysql_rwlock_trywrlock(
return result; return result;
} }
static inline int inline_mysql_prlock_trywrlock(
mysql_prlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_TRYWRITELOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_wrwait(locker, src_file, src_line);
}
#endif
result= rw_pr_trywrlock(&that->m_prlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_wrwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_unlock( static inline int inline_mysql_rwlock_unlock(
mysql_rwlock_t *that) mysql_rwlock_t *that)
{ {
...@@ -733,6 +980,23 @@ static inline int inline_mysql_rwlock_unlock( ...@@ -733,6 +980,23 @@ static inline int inline_mysql_rwlock_unlock(
return result; return result;
} }
static inline int inline_mysql_prlock_unlock(
mysql_prlock_t *that)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_thread *thread;
if (likely(PSI_server && that->m_psi))
{
thread= PSI_server->get_thread();
if (likely(thread != NULL))
PSI_server->unlock_rwlock(thread, that->m_psi);
}
#endif
result= rw_pr_unlock(&that->m_prlock);
return result;
}
static inline int inline_mysql_cond_init( static inline int inline_mysql_cond_init(
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
PSI_cond_key key, PSI_cond_key key,
......
...@@ -25,9 +25,10 @@ wait/synch/rwlock/sql/LOCK_system_variables_hash YES YES ...@@ -25,9 +25,10 @@ wait/synch/rwlock/sql/LOCK_system_variables_hash YES YES
wait/synch/rwlock/sql/LOCK_sys_init_connect YES YES wait/synch/rwlock/sql/LOCK_sys_init_connect YES YES
wait/synch/rwlock/sql/LOCK_sys_init_slave YES YES wait/synch/rwlock/sql/LOCK_sys_init_slave YES YES
wait/synch/rwlock/sql/LOGGER::LOCK_logger YES YES wait/synch/rwlock/sql/LOGGER::LOCK_logger YES YES
wait/synch/rwlock/sql/MDL_context::waiting_for_lock YES YES
wait/synch/rwlock/sql/MDL_lock::rwlock YES YES
wait/synch/rwlock/sql/Query_cache_query::lock YES YES wait/synch/rwlock/sql/Query_cache_query::lock YES YES
wait/synch/rwlock/sql/THR_LOCK_servers YES YES wait/synch/rwlock/sql/THR_LOCK_servers YES YES
wait/synch/rwlock/sql/THR_LOCK_udf YES YES
select * from performance_schema.SETUP_INSTRUMENTS select * from performance_schema.SETUP_INSTRUMENTS
where name like 'Wait/Synch/Cond/sql/%' where name like 'Wait/Synch/Cond/sql/%'
and name not in ( and name not in (
......
...@@ -19,6 +19,54 @@ ...@@ -19,6 +19,54 @@
#include <hash.h> #include <hash.h>
#include <mysqld_error.h> #include <mysqld_error.h>
#ifdef HAVE_PSI_INTERFACE
static PSI_mutex_key key_MDL_map_mutex;
static PSI_mutex_key key_MDL_context_signal_mutex;
static PSI_mutex_info all_mdl_mutexes[]=
{
{ &key_MDL_map_mutex, "MDL_map::mutex", PSI_FLAG_GLOBAL},
{ &key_MDL_context_signal_mutex, "MDL_context::signal", 0}
};
static PSI_rwlock_key key_MDL_lock_rwlock;
static PSI_rwlock_key key_MDL_context_waiting_for_rwlock;
static PSI_rwlock_info all_mdl_rwlocks[]=
{
{ &key_MDL_lock_rwlock, "MDL_lock::rwlock", 0},
{ &key_MDL_context_waiting_for_rwlock, "MDL_context::waiting_for_lock", 0}
};
static PSI_cond_key key_MDL_context_signal_cond;
static PSI_cond_info all_mdl_conds[]=
{
{ &key_MDL_context_signal_cond, "MDL_context::signal", 0}
};
/**
Initialise all the performance schema instrumentation points
used by the MDL subsystem.
*/
static void init_mdl_psi_keys(void)
{
const char *category= "sql";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_mdl_mutexes);
PSI_server->register_mutex(category, all_mdl_mutexes, count);
count= array_elements(all_mdl_rwlocks);
PSI_server->register_rwlock(category, all_mdl_rwlocks, count);
count= array_elements(all_mdl_conds);
PSI_server->register_cond(category, all_mdl_conds, count);
}
#endif /* HAVE_PSI_INTERFACE */
void notify_shared_lock(THD *thd, MDL_ticket *conflicting_ticket); void notify_shared_lock(THD *thd, MDL_ticket *conflicting_ticket);
...@@ -178,7 +226,7 @@ class MDL_lock ...@@ -178,7 +226,7 @@ class MDL_lock
If m_wrlock prefers readers (actually ignoring pending writers is If m_wrlock prefers readers (actually ignoring pending writers is
enough) ctxA and ctxB will continue and no deadlock will occur. enough) ctxA and ctxB will continue and no deadlock will occur.
*/ */
rw_pr_lock_t m_rwlock; mysql_prlock_t m_rwlock;
bool is_empty() const bool is_empty() const
{ {
...@@ -240,12 +288,12 @@ class MDL_lock ...@@ -240,12 +288,12 @@ class MDL_lock
m_ref_release(0), m_ref_release(0),
m_is_destroyed(FALSE) m_is_destroyed(FALSE)
{ {
rw_pr_init(&m_rwlock); mysql_prlock_init(key_MDL_lock_rwlock, &m_rwlock);
} }
virtual ~MDL_lock() virtual ~MDL_lock()
{ {
rw_pr_destroy(&m_rwlock); mysql_prlock_destroy(&m_rwlock);
} }
inline static void destroy(MDL_lock *lock); inline static void destroy(MDL_lock *lock);
public: public:
...@@ -368,6 +416,11 @@ void mdl_init() ...@@ -368,6 +416,11 @@ void mdl_init()
{ {
DBUG_ASSERT(! mdl_initialized); DBUG_ASSERT(! mdl_initialized);
mdl_initialized= TRUE; mdl_initialized= TRUE;
#ifdef HAVE_PSI_INTERFACE
init_mdl_psi_keys();
#endif
mdl_locks.init(); mdl_locks.init();
} }
...@@ -393,7 +446,7 @@ void mdl_destroy() ...@@ -393,7 +446,7 @@ void mdl_destroy()
void MDL_map::init() void MDL_map::init()
{ {
mysql_mutex_init(NULL /* pfs key */,&m_mutex, NULL); mysql_mutex_init(key_MDL_map_mutex, &m_mutex, NULL);
my_hash_init(&m_locks, &my_charset_bin, 16 /* FIXME */, 0, 0, my_hash_init(&m_locks, &my_charset_bin, 16 /* FIXME */, 0, 0,
mdl_locks_key, 0, 0); mdl_locks_key, 0, 0);
} }
...@@ -507,7 +560,7 @@ bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock) ...@@ -507,7 +560,7 @@ bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock)
lock->m_ref_usage++; lock->m_ref_usage++;
mysql_mutex_unlock(&m_mutex); mysql_mutex_unlock(&m_mutex);
rw_pr_wrlock(&lock->m_rwlock); mysql_prlock_wrlock(&lock->m_rwlock);
lock->m_ref_release++; lock->m_ref_release++;
if (unlikely(lock->m_is_destroyed)) if (unlikely(lock->m_is_destroyed))
{ {
...@@ -522,7 +575,7 @@ bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock) ...@@ -522,7 +575,7 @@ bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock)
*/ */
uint ref_usage= lock->m_ref_usage; uint ref_usage= lock->m_ref_usage;
uint ref_release= lock->m_ref_release; uint ref_release= lock->m_ref_release;
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
if (ref_usage == ref_release) if (ref_usage == ref_release)
MDL_lock::destroy(lock); MDL_lock::destroy(lock);
return TRUE; return TRUE;
...@@ -565,7 +618,7 @@ void MDL_map::remove(MDL_lock *lock) ...@@ -565,7 +618,7 @@ void MDL_map::remove(MDL_lock *lock)
lock->m_is_destroyed= TRUE; lock->m_is_destroyed= TRUE;
ref_usage= lock->m_ref_usage; ref_usage= lock->m_ref_usage;
ref_release= lock->m_ref_release; ref_release= lock->m_ref_release;
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
mysql_mutex_unlock(&m_mutex); mysql_mutex_unlock(&m_mutex);
if (ref_usage == ref_release) if (ref_usage == ref_release)
MDL_lock::destroy(lock); MDL_lock::destroy(lock);
...@@ -586,9 +639,9 @@ MDL_context::MDL_context() ...@@ -586,9 +639,9 @@ MDL_context::MDL_context()
m_deadlock_weight(0), m_deadlock_weight(0),
m_signal(NO_WAKE_UP) m_signal(NO_WAKE_UP)
{ {
rw_pr_init(&m_waiting_for_lock); mysql_prlock_init(key_MDL_context_waiting_for_rwlock, &m_waiting_for_lock);
mysql_mutex_init(NULL /* pfs key */, &m_signal_lock, NULL); mysql_mutex_init(key_MDL_context_signal_mutex, &m_signal_lock, NULL);
mysql_cond_init(NULL /* pfs key */, &m_signal_cond, NULL); mysql_cond_init(key_MDL_context_signal_mutex, &m_signal_cond, NULL);
} }
...@@ -608,7 +661,7 @@ void MDL_context::destroy() ...@@ -608,7 +661,7 @@ void MDL_context::destroy()
{ {
DBUG_ASSERT(m_tickets.is_empty()); DBUG_ASSERT(m_tickets.is_empty());
rw_pr_destroy(&m_waiting_for_lock); mysql_prlock_destroy(&m_waiting_for_lock);
mysql_mutex_destroy(&m_signal_lock); mysql_mutex_destroy(&m_signal_lock);
mysql_cond_destroy(&m_signal_cond); mysql_cond_destroy(&m_signal_cond);
} }
...@@ -1098,7 +1151,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg, ...@@ -1098,7 +1151,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg,
void MDL_lock::remove_ticket(Ticket_list MDL_lock::*list, MDL_ticket *ticket) void MDL_lock::remove_ticket(Ticket_list MDL_lock::*list, MDL_ticket *ticket)
{ {
rw_pr_wrlock(&m_rwlock); mysql_prlock_wrlock(&m_rwlock);
(this->*list).remove_ticket(ticket); (this->*list).remove_ticket(ticket);
if (is_empty()) if (is_empty())
mdl_locks.remove(this); mdl_locks.remove(this);
...@@ -1109,7 +1162,7 @@ void MDL_lock::remove_ticket(Ticket_list MDL_lock::*list, MDL_ticket *ticket) ...@@ -1109,7 +1162,7 @@ void MDL_lock::remove_ticket(Ticket_list MDL_lock::*list, MDL_ticket *ticket)
which now might be able to do it. Wake them up! which now might be able to do it. Wake them up!
*/ */
wake_up_waiters(); wake_up_waiters();
rw_pr_unlock(&m_rwlock); mysql_prlock_unlock(&m_rwlock);
} }
} }
...@@ -1129,9 +1182,9 @@ bool MDL_lock::has_pending_conflicting_lock(enum_mdl_type type) ...@@ -1129,9 +1182,9 @@ bool MDL_lock::has_pending_conflicting_lock(enum_mdl_type type)
mysql_mutex_assert_not_owner(&LOCK_open); mysql_mutex_assert_not_owner(&LOCK_open);
rw_pr_rdlock(&m_rwlock); mysql_prlock_rdlock(&m_rwlock);
result= (m_waiting.bitmap() & incompatible_granted_types_bitmap()[type]); result= (m_waiting.bitmap() & incompatible_granted_types_bitmap()[type]);
rw_pr_unlock(&m_rwlock); mysql_prlock_unlock(&m_rwlock);
return result; return result;
} }
...@@ -1325,7 +1378,7 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request) ...@@ -1325,7 +1378,7 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request)
{ {
ticket->m_lock= lock; ticket->m_lock= lock;
lock->m_granted.add_ticket(ticket); lock->m_granted.add_ticket(ticket);
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
m_tickets.push_front(ticket); m_tickets.push_front(ticket);
...@@ -1335,7 +1388,7 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request) ...@@ -1335,7 +1388,7 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request)
{ {
/* We can't get here if we allocated a new lock. */ /* We can't get here if we allocated a new lock. */
DBUG_ASSERT(! lock->is_empty()); DBUG_ASSERT(! lock->is_empty());
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
MDL_ticket::destroy(ticket); MDL_ticket::destroy(ticket);
} }
...@@ -1376,9 +1429,9 @@ MDL_context::clone_ticket(MDL_request *mdl_request) ...@@ -1376,9 +1429,9 @@ MDL_context::clone_ticket(MDL_request *mdl_request)
ticket->m_lock= mdl_request->ticket->m_lock; ticket->m_lock= mdl_request->ticket->m_lock;
mdl_request->ticket= ticket; mdl_request->ticket= ticket;
rw_pr_wrlock(&ticket->m_lock->m_rwlock); mysql_prlock_wrlock(&ticket->m_lock->m_rwlock);
ticket->m_lock->m_granted.add_ticket(ticket); ticket->m_lock->m_granted.add_ticket(ticket);
rw_pr_unlock(&ticket->m_lock->m_rwlock); mysql_prlock_unlock(&ticket->m_lock->m_rwlock);
m_tickets.push_front(ticket); m_tickets.push_front(ticket);
...@@ -1484,7 +1537,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request, ...@@ -1484,7 +1537,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request,
if (ticket->is_upgradable_or_exclusive()) if (ticket->is_upgradable_or_exclusive())
lock->notify_shared_locks(this); lock->notify_shared_locks(this);
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
set_deadlock_weight(mdl_request->get_deadlock_weight()); set_deadlock_weight(mdl_request->get_deadlock_weight());
will_wait_for(ticket); will_wait_for(ticket);
...@@ -1519,7 +1572,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request, ...@@ -1519,7 +1572,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request,
my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0)); my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0));
return TRUE; return TRUE;
} }
rw_pr_wrlock(&lock->m_rwlock); mysql_prlock_wrlock(&lock->m_rwlock);
} }
lock->m_waiting.remove_ticket(ticket); lock->m_waiting.remove_ticket(ticket);
...@@ -1529,7 +1582,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request, ...@@ -1529,7 +1582,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request,
(*lock->cached_object_release_hook)(lock->cached_object); (*lock->cached_object_release_hook)(lock->cached_object);
lock->cached_object= NULL; lock->cached_object= NULL;
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
m_tickets.push_front(ticket); m_tickets.push_front(ticket);
...@@ -1674,7 +1727,7 @@ MDL_context::upgrade_shared_lock_to_exclusive(MDL_ticket *mdl_ticket, ...@@ -1674,7 +1727,7 @@ MDL_context::upgrade_shared_lock_to_exclusive(MDL_ticket *mdl_ticket,
is_new_ticket= ! has_lock(mdl_svp, mdl_xlock_request.ticket); is_new_ticket= ! has_lock(mdl_svp, mdl_xlock_request.ticket);
/* Merge the acquired and the original lock. @todo: move to a method. */ /* Merge the acquired and the original lock. @todo: move to a method. */
rw_pr_wrlock(&mdl_ticket->m_lock->m_rwlock); mysql_prlock_wrlock(&mdl_ticket->m_lock->m_rwlock);
if (is_new_ticket) if (is_new_ticket)
mdl_ticket->m_lock->m_granted.remove_ticket(mdl_xlock_request.ticket); mdl_ticket->m_lock->m_granted.remove_ticket(mdl_xlock_request.ticket);
/* /*
...@@ -1686,7 +1739,7 @@ MDL_context::upgrade_shared_lock_to_exclusive(MDL_ticket *mdl_ticket, ...@@ -1686,7 +1739,7 @@ MDL_context::upgrade_shared_lock_to_exclusive(MDL_ticket *mdl_ticket,
mdl_ticket->m_type= MDL_EXCLUSIVE; mdl_ticket->m_type= MDL_EXCLUSIVE;
mdl_ticket->m_lock->m_granted.add_ticket(mdl_ticket); mdl_ticket->m_lock->m_granted.add_ticket(mdl_ticket);
rw_pr_unlock(&mdl_ticket->m_lock->m_rwlock); mysql_prlock_unlock(&mdl_ticket->m_lock->m_rwlock);
if (is_new_ticket) if (is_new_ticket)
{ {
...@@ -1704,7 +1757,7 @@ bool MDL_lock::find_deadlock(MDL_ticket *waiting_ticket, ...@@ -1704,7 +1757,7 @@ bool MDL_lock::find_deadlock(MDL_ticket *waiting_ticket,
MDL_ticket *ticket; MDL_ticket *ticket;
bool result= FALSE; bool result= FALSE;
rw_pr_rdlock(&m_rwlock); mysql_prlock_rdlock(&m_rwlock);
Ticket_iterator granted_it(m_granted); Ticket_iterator granted_it(m_granted);
Ticket_iterator waiting_it(m_waiting); Ticket_iterator waiting_it(m_waiting);
...@@ -1756,7 +1809,7 @@ bool MDL_lock::find_deadlock(MDL_ticket *waiting_ticket, ...@@ -1756,7 +1809,7 @@ bool MDL_lock::find_deadlock(MDL_ticket *waiting_ticket,
} }
end: end:
rw_pr_unlock(&m_rwlock); mysql_prlock_unlock(&m_rwlock);
return result; return result;
} }
...@@ -1765,7 +1818,7 @@ bool MDL_context::find_deadlock(Deadlock_detection_context *deadlock_ctx) ...@@ -1765,7 +1818,7 @@ bool MDL_context::find_deadlock(Deadlock_detection_context *deadlock_ctx)
{ {
bool result= FALSE; bool result= FALSE;
rw_pr_rdlock(&m_waiting_for_lock); mysql_prlock_rdlock(&m_waiting_for_lock);
if (m_waiting_for) if (m_waiting_for)
{ {
...@@ -1794,14 +1847,14 @@ bool MDL_context::find_deadlock(Deadlock_detection_context *deadlock_ctx) ...@@ -1794,14 +1847,14 @@ bool MDL_context::find_deadlock(Deadlock_detection_context *deadlock_ctx)
deadlock_ctx->victim= this; deadlock_ctx->victim= this;
else if (deadlock_ctx->victim->m_deadlock_weight >= m_deadlock_weight) else if (deadlock_ctx->victim->m_deadlock_weight >= m_deadlock_weight)
{ {
rw_pr_unlock(&deadlock_ctx->victim->m_waiting_for_lock); mysql_prlock_unlock(&deadlock_ctx->victim->m_waiting_for_lock);
deadlock_ctx->victim= this; deadlock_ctx->victim= this;
} }
else else
rw_pr_unlock(&m_waiting_for_lock); mysql_prlock_unlock(&m_waiting_for_lock);
} }
else else
rw_pr_unlock(&m_waiting_for_lock); mysql_prlock_unlock(&m_waiting_for_lock);
return result; return result;
} }
...@@ -1827,7 +1880,7 @@ bool MDL_context::find_deadlock() ...@@ -1827,7 +1880,7 @@ bool MDL_context::find_deadlock()
if (deadlock_ctx.victim != this) if (deadlock_ctx.victim != this)
{ {
deadlock_ctx.victim->awake(VICTIM_WAKE_UP); deadlock_ctx.victim->awake(VICTIM_WAKE_UP);
rw_pr_unlock(&deadlock_ctx.victim->m_waiting_for_lock); mysql_prlock_unlock(&deadlock_ctx.victim->m_waiting_for_lock);
/* /*
After adding new arc to waiting graph we found that it participates After adding new arc to waiting graph we found that it participates
in some loop (i.e. there is a deadlock). We decided to destroy this in some loop (i.e. there is a deadlock). We decided to destroy this
...@@ -1840,7 +1893,7 @@ bool MDL_context::find_deadlock() ...@@ -1840,7 +1893,7 @@ bool MDL_context::find_deadlock()
else else
{ {
DBUG_ASSERT(&deadlock_ctx.victim->m_waiting_for_lock == &m_waiting_for_lock); DBUG_ASSERT(&deadlock_ctx.victim->m_waiting_for_lock == &m_waiting_for_lock);
rw_pr_unlock(&deadlock_ctx.victim->m_waiting_for_lock); mysql_prlock_unlock(&deadlock_ctx.victim->m_waiting_for_lock);
return TRUE; return TRUE;
} }
} }
...@@ -1897,14 +1950,14 @@ MDL_context::wait_for_lock(MDL_request *mdl_request, ulong lock_wait_timeout) ...@@ -1897,14 +1950,14 @@ MDL_context::wait_for_lock(MDL_request *mdl_request, ulong lock_wait_timeout)
if (lock->can_grant_lock(mdl_request->type, this)) if (lock->can_grant_lock(mdl_request->type, this))
{ {
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
return FALSE; return FALSE;
} }
MDL_ticket *pending_ticket; MDL_ticket *pending_ticket;
if (! (pending_ticket= MDL_ticket::create(this, mdl_request->type))) if (! (pending_ticket= MDL_ticket::create(this, mdl_request->type)))
{ {
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
return TRUE; return TRUE;
} }
...@@ -1913,7 +1966,7 @@ MDL_context::wait_for_lock(MDL_request *mdl_request, ulong lock_wait_timeout) ...@@ -1913,7 +1966,7 @@ MDL_context::wait_for_lock(MDL_request *mdl_request, ulong lock_wait_timeout)
lock->m_waiting.add_ticket(pending_ticket); lock->m_waiting.add_ticket(pending_ticket);
wait_reset(); wait_reset();
rw_pr_unlock(&lock->m_rwlock); mysql_prlock_unlock(&lock->m_rwlock);
set_deadlock_weight(MDL_DEADLOCK_WEIGHT_DML); set_deadlock_weight(MDL_DEADLOCK_WEIGHT_DML);
will_wait_for(pending_ticket); will_wait_for(pending_ticket);
...@@ -2064,7 +2117,7 @@ void MDL_ticket::downgrade_exclusive_lock(enum_mdl_type type) ...@@ -2064,7 +2117,7 @@ void MDL_ticket::downgrade_exclusive_lock(enum_mdl_type type)
if (m_type != MDL_EXCLUSIVE) if (m_type != MDL_EXCLUSIVE)
return; return;
rw_pr_wrlock(&m_lock->m_rwlock); mysql_prlock_wrlock(&m_lock->m_rwlock);
/* /*
To update state of MDL_lock object correctly we need to temporarily To update state of MDL_lock object correctly we need to temporarily
exclude ticket from the granted queue and then include it back. exclude ticket from the granted queue and then include it back.
...@@ -2073,7 +2126,7 @@ void MDL_ticket::downgrade_exclusive_lock(enum_mdl_type type) ...@@ -2073,7 +2126,7 @@ void MDL_ticket::downgrade_exclusive_lock(enum_mdl_type type)
m_type= type; m_type= type;
m_lock->m_granted.add_ticket(this); m_lock->m_granted.add_ticket(this);
m_lock->wake_up_waiters(); m_lock->wake_up_waiters();
rw_pr_unlock(&m_lock->m_rwlock); mysql_prlock_unlock(&m_lock->m_rwlock);
} }
......
...@@ -628,7 +628,7 @@ class MDL_context ...@@ -628,7 +628,7 @@ class MDL_context
important as deadlock detector won't work correctly important as deadlock detector won't work correctly
otherwise. @sa Comment for MDL_lock::m_rwlock. otherwise. @sa Comment for MDL_lock::m_rwlock.
*/ */
rw_pr_lock_t m_waiting_for_lock; mysql_prlock_t m_waiting_for_lock;
MDL_ticket *m_waiting_for; MDL_ticket *m_waiting_for;
uint m_deadlock_weight; uint m_deadlock_weight;
/** /**
...@@ -652,9 +652,9 @@ class MDL_context ...@@ -652,9 +652,9 @@ class MDL_context
void will_wait_for(MDL_ticket *pending_ticket) void will_wait_for(MDL_ticket *pending_ticket)
{ {
rw_pr_wrlock(&m_waiting_for_lock); mysql_prlock_wrlock(&m_waiting_for_lock);
m_waiting_for= pending_ticket; m_waiting_for= pending_ticket;
rw_pr_unlock(&m_waiting_for_lock); mysql_prlock_unlock(&m_waiting_for_lock);
} }
void set_deadlock_weight(uint weight) void set_deadlock_weight(uint weight)
...@@ -670,9 +670,9 @@ class MDL_context ...@@ -670,9 +670,9 @@ class MDL_context
void stop_waiting() void stop_waiting()
{ {
rw_pr_wrlock(&m_waiting_for_lock); mysql_prlock_wrlock(&m_waiting_for_lock);
m_waiting_for= NULL; m_waiting_for= NULL;
rw_pr_unlock(&m_waiting_for_lock); mysql_prlock_unlock(&m_waiting_for_lock);
} }
void wait_reset() void wait_reset()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment