Commit 0acac3df authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

closes #5380 add mutex assertions in fair rwlock, only active during debug builds


git-svn-id: file:///svn/toku/tokudb@47041 c7de825b-a66e-492c-adef-691d508d4ae1
parent d9fd0803
......@@ -60,6 +60,7 @@ inline toku_cond_t *frwlock::deq_item(void) {
// Prerequisite: Holds m_mutex.
inline void frwlock::write_lock(bool expensive) {
toku_mutex_assert_locked(m_mutex);
if (this->try_write_lock(expensive)) {
return;
}
......@@ -92,6 +93,7 @@ inline void frwlock::write_lock(bool expensive) {
}
inline bool frwlock::try_write_lock(bool expensive) {
toku_mutex_assert_locked(m_mutex);
if (m_num_readers > 0 || m_num_writers > 0 || m_num_signaled_readers > 0 || m_num_want_write > 0) {
return false;
}
......@@ -104,6 +106,7 @@ inline bool frwlock::try_write_lock(bool expensive) {
}
inline void frwlock::read_lock(void) {
toku_mutex_assert_locked(m_mutex);
if (m_num_writers > 0 || m_num_want_write > 0) {
if (!m_wait_read_is_in_queue) {
// Throw the read cond_t onto the queue.
......@@ -135,6 +138,7 @@ inline void frwlock::read_lock(void) {
}
inline bool frwlock::try_read_lock(void) {
toku_mutex_assert_locked(m_mutex);
if (m_num_writers > 0 || m_num_want_write > 0) {
return false;
}
......@@ -156,6 +160,7 @@ inline void frwlock::maybe_signal_next_writer(void) {
}
inline void frwlock::read_unlock(void) {
toku_mutex_assert_locked(m_mutex);
invariant(m_num_writers == 0);
invariant(m_num_readers > 0);
--m_num_readers;
......@@ -163,6 +168,7 @@ inline void frwlock::read_unlock(void) {
}
inline bool frwlock::read_lock_is_expensive(void) {
toku_mutex_assert_locked(m_mutex);
if (m_wait_read_is_in_queue) {
return m_read_wait_expensive;
}
......@@ -198,32 +204,40 @@ inline void frwlock::maybe_signal_or_broadcast_next(void) {
}
inline void frwlock::write_unlock(void) {
toku_mutex_assert_locked(m_mutex);
invariant(m_num_writers == 1);
m_num_writers = 0;
m_current_writer_expensive = false;
this->maybe_signal_or_broadcast_next();
}
inline bool frwlock::write_lock_is_expensive(void) {
toku_mutex_assert_locked(m_mutex);
return (m_num_expensive_want_write > 0) || (m_current_writer_expensive);
}
inline uint32_t frwlock::users(void) const {
toku_mutex_assert_locked(m_mutex);
return m_num_readers + m_num_writers + m_num_want_read + m_num_want_write;
}
inline uint32_t frwlock::blocked_users(void) const {
toku_mutex_assert_locked(m_mutex);
return m_num_want_read + m_num_want_write;
}
inline uint32_t frwlock::writers(void) const {
toku_mutex_assert_locked(m_mutex);
return m_num_writers;
}
inline uint32_t frwlock::blocked_writers(void) const {
toku_mutex_assert_locked(m_mutex);
return m_num_want_write;
}
inline uint32_t frwlock::readers(void) const {
toku_mutex_assert_locked(m_mutex);
return m_num_readers;
}
inline uint32_t frwlock::blocked_readers(void) const {
toku_mutex_assert_locked(m_mutex);
return m_num_want_read;
}
......
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