Skip to content

Commit

Permalink
Use assert() on RMW arguments
Browse files Browse the repository at this point in the history
The macros ut_ad() and DBUG_ASSERT() can evaluate their argument twice.
That is wrong for any read-modify-write arguments.

Thanks to Nikita Malyavin for pointing this out.
  • Loading branch information
dr-m committed Jan 9, 2025
1 parent addc828 commit 1b8358d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion storage/innobase/include/buf0buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ class buf_page_t
/** Prepare to release a file page to buf_pool.free. */
void free_file_page() noexcept
{
ut_ad((zip.fix.fetch_sub(REMOVE_HASH - MEMORY)) == REMOVE_HASH);
assert((zip.fix.fetch_sub(REMOVE_HASH - MEMORY)) == REMOVE_HASH);
/* buf_LRU_block_free_non_file_page() asserts !oldest_modification() */
ut_d(oldest_modification_= 0;)
id_= page_id_t(~0ULL);
Expand Down
6 changes: 2 additions & 4 deletions storage/innobase/include/sux_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@ class sux_lock final
@param id the new owner of the U or X lock */
void set_new_owner(pthread_t id)
{
IF_DBUG(DBUG_ASSERT(writer.exchange(id, std::memory_order_relaxed)),
writer.store(id, std::memory_order_relaxed));
writer.store(id, std::memory_order_relaxed);
}
/** Assign the ownership of a write lock to a thread
@param id the owner of the U or X lock */
void set_first_owner(pthread_t id)
{
IF_DBUG(DBUG_ASSERT(!writer.exchange(id, std::memory_order_relaxed)),
writer.store(id, std::memory_order_relaxed));
writer.store(id, std::memory_order_relaxed);
}
#ifdef UNIV_DEBUG
/** Register the current thread as a holder of a shared lock */
Expand Down
8 changes: 4 additions & 4 deletions storage/innobase/include/trx0trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,14 @@ struct trx_t : ilist_node<>
{
ut_ad(!mutex_is_owner());
mutex.wr_lock();
ut_ad(!mutex_owner.exchange(pthread_self(),
std::memory_order_relaxed));
assert(!mutex_owner.exchange(pthread_self(),
std::memory_order_relaxed));
}
/** Release the mutex */
void mutex_unlock()
{
ut_ad(mutex_owner.exchange(0, std::memory_order_relaxed)
== pthread_self());
assert(mutex_owner.exchange(0, std::memory_order_relaxed) ==
pthread_self());
mutex.wr_unlock();
}
#ifndef SUX_LOCK_GENERIC
Expand Down

0 comments on commit 1b8358d

Please sign in to comment.