Skip to content

Commit

Permalink
Cleanup: Replace mysql_cond_t with pthread_cond_t
Browse files Browse the repository at this point in the history
Let us avoid the memory overhead and the dead duplicated code
for each use of never-instrumented condition variables in InnoDB.
  • Loading branch information
dr-m committed Feb 7, 2021
1 parent 520c76b commit 786bc31
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 100 deletions.
20 changes: 10 additions & 10 deletions storage/innobase/btr/btr0defragment.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (C) 2012, 2014 Facebook, Inc. All Rights Reserved.
Copyright (C) 2014, 2020, MariaDB Corporation.
Copyright (C) 2014, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -56,11 +56,11 @@ struct btr_defragment_item_t
/** persistent cursor where btr_defragment_n_pages should start */
btr_pcur_t * const pcur;
/** completion signal */
mysql_cond_t *cond;
pthread_cond_t *cond;
/** timestamp of last time this index is processed by defragment thread */
ulonglong last_processed= 0;

btr_defragment_item_t(btr_pcur_t *pcur, mysql_cond_t *cond)
btr_defragment_item_t(btr_pcur_t *pcur, pthread_cond_t *cond)
: pcur(pcur), cond(cond) {}
};

Expand Down Expand Up @@ -126,7 +126,7 @@ btr_defragment_shutdown()
btr_defragment_item_t* item = *iter;
iter = btr_defragment_wq.erase(iter);
if (item->cond) {
mysql_cond_signal(item->cond);
pthread_cond_signal(item->cond);
}
}
mysql_mutex_unlock(&btr_defragment_mutex);
Expand Down Expand Up @@ -169,8 +169,8 @@ btr_defragment_find_index(
bool btr_defragment_add_index(btr_pcur_t *pcur, THD *thd)
{
dict_stats_empty_defrag_summary(pcur->btr_cur.index);
mysql_cond_t cond;
mysql_cond_init(0, &cond, nullptr);
pthread_cond_t cond;
pthread_cond_init(&cond, nullptr);
btr_defragment_item_t item(pcur, &cond);
mysql_mutex_lock(&btr_defragment_mutex);
btr_defragment_wq.push_back(&item);
Expand All @@ -182,7 +182,7 @@ bool btr_defragment_add_index(btr_pcur_t *pcur, THD *thd)
{
timespec abstime;
set_timespec(abstime, 1);
if (!mysql_cond_timedwait(&cond, &btr_defragment_mutex, &abstime))
if (!my_cond_timedwait(&cond, &btr_defragment_mutex.m_mutex, &abstime))
break;
if (thd_killed(thd))
{
Expand All @@ -192,7 +192,7 @@ bool btr_defragment_add_index(btr_pcur_t *pcur, THD *thd)
}
}

mysql_cond_destroy(&cond);
pthread_cond_destroy(&cond);
mysql_mutex_unlock(&btr_defragment_mutex);
return interrupted;
}
Expand All @@ -210,7 +210,7 @@ btr_defragment_remove_table(
{
if (item->cond && table == item->pcur->btr_cur.index->table)
{
mysql_cond_signal(item->cond);
pthread_cond_signal(item->cond);
item->cond= nullptr;
}
}
Expand Down Expand Up @@ -704,7 +704,7 @@ static void btr_defragment_chunk(void*)

mysql_mutex_lock(&btr_defragment_mutex);
if (item->cond) {
mysql_cond_signal(item->cond);
pthread_cond_signal(item->cond);
}
goto processed;
}
Expand Down
61 changes: 31 additions & 30 deletions storage/innobase/fil/fil0crypt.cc
@@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
Copyright (c) 2014, 2020, MariaDB Corporation.
Copyright (c) 2014, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -56,14 +56,14 @@ UNIV_INTERN uint srv_n_fil_crypt_threads_started = 0;
UNIV_INTERN uint srv_fil_crypt_rotate_key_age;

/** Condition variable for srv_n_fil_crypt_threads_started */
static mysql_cond_t fil_crypt_cond;
static pthread_cond_t fil_crypt_cond;

/** Condition variable to to signal the key rotation threads */
static mysql_cond_t fil_crypt_threads_cond;
static pthread_cond_t fil_crypt_threads_cond;

/** Condition variable for interrupting sleeptime_ms sleep at the end
of fil_crypt_rotate_page() */
static mysql_cond_t fil_crypt_throttle_sleep_cond;
static pthread_cond_t fil_crypt_throttle_sleep_cond;

/** Mutex for key rotation threads. Acquired before fil_system.mutex! */
static mysql_mutex_t fil_crypt_threads_mutex;
Expand All @@ -87,9 +87,9 @@ void fil_crypt_threads_signal(bool broadcast)
{
mysql_mutex_lock(&fil_crypt_threads_mutex);
if (broadcast)
mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
else
mysql_cond_signal(&fil_crypt_threads_cond);
pthread_cond_signal(&fil_crypt_threads_cond);
mysql_mutex_unlock(&fil_crypt_threads_mutex);
}

Expand All @@ -112,7 +112,7 @@ fil_crypt_needs_rotation(
Init space crypt */
void fil_space_crypt_init()
{
mysql_cond_init(0, &fil_crypt_throttle_sleep_cond, nullptr);
pthread_cond_init(&fil_crypt_throttle_sleep_cond, nullptr);
mysql_mutex_init(0, &crypt_stat_mutex, nullptr);
memset(&crypt_stat, 0, sizeof crypt_stat);
}
Expand All @@ -121,7 +121,7 @@ void fil_space_crypt_init()
Cleanup space crypt */
void fil_space_crypt_cleanup()
{
mysql_cond_destroy(&fil_crypt_throttle_sleep_cond);
pthread_cond_destroy(&fil_crypt_throttle_sleep_cond);
mysql_mutex_destroy(&crypt_stat_mutex);
}

Expand Down Expand Up @@ -1281,8 +1281,8 @@ static bool fil_crypt_alloc_iops(rotate_thread_t *state)

if (n_fil_crypt_iops_allocated >= srv_n_fil_crypt_iops) {
wait:
mysql_cond_wait(&fil_crypt_threads_cond,
&fil_crypt_threads_mutex);
my_cond_wait(&fil_crypt_threads_cond,
&fil_crypt_threads_mutex.m_mutex);
return false;
}

Expand Down Expand Up @@ -1354,7 +1354,7 @@ static bool fil_crypt_realloc_iops(rotate_thread_t *state)
state->allocated_iops = state->estimated_max_iops;
ut_ad(n_fil_crypt_iops_allocated >= extra);
n_fil_crypt_iops_allocated -= extra;
mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
} else if (srv_n_fil_crypt_iops > n_fil_crypt_iops_allocated) {
/* there are extra iops free */
uint add = srv_n_fil_crypt_iops - n_fil_crypt_iops_allocated;
Expand Down Expand Up @@ -1390,7 +1390,7 @@ static void fil_crypt_return_iops(rotate_thread_t *state, bool wake= true)
n_fil_crypt_iops_allocated-= iops;
state->allocated_iops= 0;
if (wake)
mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
}

fil_crypt_update_total_stat(state);
Expand Down Expand Up @@ -1879,8 +1879,8 @@ fil_crypt_rotate_page(
mysql_mutex_lock(&fil_crypt_threads_mutex);
timespec abstime;
set_timespec_nsec(abstime, 1000000ULL * sleeptime_ms);
mysql_cond_timedwait(&fil_crypt_throttle_sleep_cond,
&fil_crypt_threads_mutex, &abstime);
my_cond_timedwait(&fil_crypt_throttle_sleep_cond,
&fil_crypt_threads_mutex.m_mutex, &abstime);
mysql_mutex_unlock(&fil_crypt_threads_mutex);
}
}
Expand Down Expand Up @@ -2057,7 +2057,7 @@ static os_thread_ret_t DECLARE_THREAD(fil_crypt_thread)(void*)
{
mysql_mutex_lock(&fil_crypt_threads_mutex);
rotate_thread_t thr(srv_n_fil_crypt_threads_started++);
mysql_cond_signal(&fil_crypt_cond); /* signal that we started */
pthread_cond_signal(&fil_crypt_cond); /* signal that we started */

if (!thr.should_shutdown()) {
/* if we find a tablespace that is starting, skip over it
Expand All @@ -2069,8 +2069,8 @@ static os_thread_ret_t DECLARE_THREAD(fil_crypt_thread)(void*)
/* wait for key state changes
* i.e either new key version of change or
* new rotate_key_age */
mysql_cond_wait(&fil_crypt_threads_cond,
&fil_crypt_threads_mutex);
my_cond_wait(&fil_crypt_threads_cond,
&fil_crypt_threads_mutex.m_mutex);
}

recheck = false;
Expand Down Expand Up @@ -2129,7 +2129,7 @@ static os_thread_ret_t DECLARE_THREAD(fil_crypt_thread)(void*)

fil_crypt_return_iops(&thr);
srv_n_fil_crypt_threads_started--;
mysql_cond_signal(&fil_crypt_cond); /* signal that we stopped */
pthread_cond_signal(&fil_crypt_cond); /* signal that we stopped */
mysql_mutex_unlock(&fil_crypt_threads_mutex);

/* We count the number of threads in os_thread_exit(). A created
Expand Down Expand Up @@ -2169,13 +2169,14 @@ fil_crypt_set_thread_cnt(
srv_n_fil_crypt_threads = new_cnt;
}

mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);

while (srv_n_fil_crypt_threads_started != srv_n_fil_crypt_threads) {
mysql_cond_wait(&fil_crypt_cond, &fil_crypt_threads_mutex);
my_cond_wait(&fil_crypt_cond,
&fil_crypt_threads_mutex.m_mutex);
}

mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
mysql_mutex_unlock(&fil_crypt_threads_mutex);
}

Expand Down Expand Up @@ -2238,7 +2239,7 @@ void fil_crypt_set_rotate_key_age(uint val)
if (val == 0)
fil_crypt_rotation_list_fill();
mysql_mutex_unlock(&fil_system.mutex);
mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
mysql_mutex_unlock(&fil_crypt_threads_mutex);
}

Expand All @@ -2249,7 +2250,7 @@ void fil_crypt_set_rotation_iops(uint val)
{
mysql_mutex_lock(&fil_crypt_threads_mutex);
srv_n_fil_crypt_iops= val;
mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
mysql_mutex_unlock(&fil_crypt_threads_mutex);
}

Expand All @@ -2268,7 +2269,7 @@ void fil_crypt_set_encrypt_tables(ulong val)

mysql_mutex_unlock(&fil_system.mutex);

mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
mysql_mutex_unlock(&fil_crypt_threads_mutex);
}

Expand All @@ -2277,8 +2278,8 @@ Init threads for key rotation */
void fil_crypt_threads_init()
{
if (!fil_crypt_threads_inited) {
mysql_cond_init(0, &fil_crypt_cond, nullptr);
mysql_cond_init(0, &fil_crypt_threads_cond, nullptr);
pthread_cond_init(&fil_crypt_cond, nullptr);
pthread_cond_init(&fil_crypt_threads_cond, nullptr);
mysql_mutex_init(0, &fil_crypt_threads_mutex, nullptr);
uint cnt = srv_n_fil_crypt_threads;
srv_n_fil_crypt_threads = 0;
Expand All @@ -2297,8 +2298,8 @@ fil_crypt_threads_cleanup()
return;
}
ut_a(!srv_n_fil_crypt_threads_started);
mysql_cond_destroy(&fil_crypt_cond);
mysql_cond_destroy(&fil_crypt_threads_cond);
pthread_cond_destroy(&fil_crypt_cond);
pthread_cond_destroy(&fil_crypt_threads_cond);
mysql_mutex_destroy(&fil_crypt_threads_mutex);
fil_crypt_threads_inited = false;
}
Expand Down Expand Up @@ -2332,8 +2333,8 @@ fil_space_crypt_close_tablespace(

/* wakeup throttle (all) sleepers */
mysql_mutex_lock(&fil_crypt_threads_mutex);
mysql_cond_broadcast(&fil_crypt_throttle_sleep_cond);
mysql_cond_broadcast(&fil_crypt_threads_cond);
pthread_cond_broadcast(&fil_crypt_throttle_sleep_cond);
pthread_cond_broadcast(&fil_crypt_threads_cond);
mysql_mutex_unlock(&fil_crypt_threads_mutex);

os_thread_sleep(20000);
Expand Down
14 changes: 7 additions & 7 deletions storage/innobase/fts/fts0fts.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2016, 2020, MariaDB Corporation.
Copyright (c) 2016, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -295,7 +295,7 @@ fts_cache_destroy(fts_cache_t* cache)
mysql_mutex_destroy(&cache->init_lock);
mysql_mutex_destroy(&cache->deleted_lock);
mysql_mutex_destroy(&cache->doc_id_lock);
mysql_cond_destroy(&cache->sync->cond);
pthread_cond_destroy(&cache->sync->cond);

if (cache->stopword_info.cached_stopword) {
rbt_free(cache->stopword_info.cached_stopword);
Expand Down Expand Up @@ -636,7 +636,7 @@ fts_cache_create(
mem_heap_zalloc(heap, sizeof(fts_sync_t)));

cache->sync->table = table;
mysql_cond_init(0, &cache->sync->cond, nullptr);
pthread_cond_init(&cache->sync->cond, nullptr);

/* Create the index cache vector that will hold the inverted indexes. */
cache->indexes = ib_vector_create(
Expand Down Expand Up @@ -3522,9 +3522,9 @@ fts_add_doc_by_id(
fts_optimize_request_sync_table(table);
mysql_mutex_lock(&cache->lock);
if (cache->sync->in_progress)
mysql_cond_wait(
my_cond_wait(
&cache->sync->cond,
&cache->lock);
&cache->lock.m_mutex);
mysql_mutex_unlock(&cache->lock);
);

Expand Down Expand Up @@ -4249,7 +4249,7 @@ fts_sync(
return(DB_SUCCESS);
}
do {
mysql_cond_wait(&sync->cond, &cache->lock);
my_cond_wait(&sync->cond, &cache->lock.m_mutex);
} while (sync->in_progress);
}

Expand Down Expand Up @@ -4320,7 +4320,7 @@ fts_sync(
ut_ad(sync->in_progress);
sync->interrupted = false;
sync->in_progress = false;
mysql_cond_broadcast(&sync->cond);
pthread_cond_broadcast(&sync->cond);
mysql_mutex_unlock(&cache->lock);

/* We need to check whether an optimize is required, for that
Expand Down

0 comments on commit 786bc31

Please sign in to comment.