Commit 379c7135 authored by Marko Mäkelä's avatar Marko Mäkelä

WIP: Catch pthread_mutex_wrapper misuse

TODO: Do not globally define SUX_LOCK_GENERIC, nor add maybe_reinit

TODO: Rebase this on 10.6 instead of 10.11
parent 1c8af2ae
......@@ -30,7 +30,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
# define SUX_LOCK_GENERIC /* fall back to generic synchronization primitives */
#endif
#if !defined SUX_LOCK_GENERIC && 0 /* defined SAFE_MUTEX */
#if !defined SUX_LOCK_GENERIC // && 0 /* defined SAFE_MUTEX */
# define SUX_LOCK_GENERIC /* Use dummy implementation for debugging purposes */
#endif
......@@ -39,15 +39,26 @@ template<bool spinloop>
class pthread_mutex_wrapper final
{
pthread_mutex_t lock;
#ifdef UNIV_DEBUG
bool initialized{false};
public:
void init()
~pthread_mutex_wrapper() { ut_ad(!initialized); }
#endif
public:
void init(bool maybe_reinit= false)
{
ut_ad(maybe_reinit || !initialized);
ut_d(initialized= true);
if (spinloop)
pthread_mutex_init(&lock, MY_MUTEX_INIT_FAST);
else
pthread_mutex_init(&lock, nullptr);
}
void destroy() { pthread_mutex_destroy(&lock); }
void destroy()
{
ut_ad(initialized); ut_d(initialized=false);
pthread_mutex_destroy(&lock);
}
# ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
void wr_lock() { pthread_mutex_lock(&lock); }
# else
......
......@@ -294,7 +294,7 @@ template<> inline void sux_lock<ssux_lock_impl<true>>::init()
lock.init();
ut_ad(!writer.load(std::memory_order_relaxed));
ut_ad(!recursive);
ut_d(readers_lock.init());
ut_d(readers_lock.init(true));
#ifdef UNIV_DEBUG
if (auto r= readers.load(std::memory_order_relaxed))
ut_ad(r->empty());
......
......@@ -3198,6 +3198,7 @@ static void add_fts_index(dict_table_t *table)
{
dict_index_t *fts_index= dict_mem_index_create(
table, FTS_DOC_ID_INDEX_NAME, DICT_UNIQUE, 2);
fts_index->lock.SRW_LOCK_INIT(index_tree_rw_lock_key);
fts_index->page= FIL_NULL;
fts_index->cached= 1;
fts_index->n_uniq= 1;
......@@ -3279,6 +3280,7 @@ static dict_table_t *build_fts_hidden_table(
new_table, old_index->name, old_index->type,
old_index->n_fields + is_clustered);
new_index->lock.SRW_LOCK_INIT(index_tree_rw_lock_key);
new_index->id= old_index->id;
new_index->n_uniq= old_index->n_uniq;
new_index->type= old_index->type;
......
......@@ -661,6 +661,7 @@ void srw_lock_debug::destroy()
ut_ad(r->empty());
delete r;
}
readers_lock.destroy();
srw_lock::destroy();
}
......
......@@ -662,6 +662,7 @@ dberr_t trx_rseg_array_init()
break;
}
rseg.destroy();
rseg.init(rseg_space, page_no);
ut_ad(rseg.is_persistent());
err = trx_rseg_mem_restore(&rseg, &mtr);
......@@ -743,6 +744,7 @@ dberr_t trx_temp_rseg_create(mtr_t *mtr)
mtr->commit();
return err;
}
trx_sys.temp_rsegs[i].destroy();
trx_sys.temp_rsegs[i].init(fil_system.temp_space,
rblock->page.id().page_no());
mtr->commit();
......
......@@ -152,6 +152,10 @@ void trx_sys_t::create()
m_initialised= true;
trx_list.create();
rw_trx_hash.init();
for (auto &rseg : temp_rsegs)
rseg.init(nullptr, FIL_NULL);
for (auto &rseg : rseg_array)
rseg.init(nullptr, FIL_NULL);
}
size_t trx_sys_t::history_size()
......@@ -230,6 +234,7 @@ static trx_rseg_t *trx_rseg_create(uint32_t space_id)
? nullptr : trx_rseg_header_create(space, rseg_id, 0, &mtr, &err))
{
rseg= &trx_sys.rseg_array[rseg_id];
rseg->destroy();
rseg->init(space, rblock->page.id().page_no());
ut_ad(rseg->is_persistent());
mtr.write<4,mtr_t::MAYBE_NOP>
......@@ -328,13 +333,8 @@ trx_sys_t::close()
rw_trx_hash.destroy();
/* There can't be any active transactions. */
for (ulint i = 0; i < array_elements(temp_rsegs); ++i) {
temp_rsegs[i].destroy();
}
for (ulint i = 0; i < array_elements(rseg_array); ++i) {
rseg_array[i].destroy();
}
for (auto& rseg : temp_rsegs) rseg.destroy();
for (auto& rseg : rseg_array) rseg.destroy();
ut_a(trx_list.empty());
trx_list.close();
......
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