2016-10-06 19:24:09 +02:00
|
|
|
/*
|
|
|
|
Portions Copyright (c) 2015-Present, Facebook, Inc.
|
|
|
|
Portions Copyright (c) 2012, Monty Program Ab
|
|
|
|
|
|
|
|
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 Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2018-02-10 08:28:23 +01:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
|
2016-10-06 19:24:09 +02:00
|
|
|
|
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2019-06-15 20:29:46 +02:00
|
|
|
#pragma implementation // gcc: Class implementation
|
2016-10-06 19:24:09 +02:00
|
|
|
#endif
|
|
|
|
|
2016-10-09 14:36:58 +02:00
|
|
|
#include <my_config.h>
|
|
|
|
|
2016-10-06 19:24:09 +02:00
|
|
|
/* The C++ file's header */
|
|
|
|
#include "./rdb_threads.h"
|
|
|
|
|
|
|
|
namespace myrocks {
|
|
|
|
|
2017-02-06 18:39:08 +01:00
|
|
|
void *Rdb_thread::thread_func(void *const thread_ptr) {
|
2016-10-06 19:24:09 +02:00
|
|
|
DBUG_ASSERT(thread_ptr != nullptr);
|
2019-03-15 15:03:26 +01:00
|
|
|
Rdb_thread *const thread = static_cast<Rdb_thread *>(thread_ptr);
|
2017-02-06 18:39:08 +01:00
|
|
|
if (!thread->m_run_once.exchange(true)) {
|
2017-03-11 05:17:42 +01:00
|
|
|
thread->setname();
|
2016-10-06 19:24:09 +02:00
|
|
|
thread->run();
|
|
|
|
thread->uninit();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rdb_thread::init(
|
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
2017-02-06 18:39:08 +01:00
|
|
|
my_core::PSI_mutex_key stop_bg_psi_mutex_key,
|
|
|
|
my_core::PSI_cond_key stop_bg_psi_cond_key
|
2016-10-06 19:24:09 +02:00
|
|
|
#endif
|
2019-06-15 20:29:46 +02:00
|
|
|
) {
|
2016-10-06 19:24:09 +02:00
|
|
|
DBUG_ASSERT(!m_run_once);
|
|
|
|
mysql_mutex_init(stop_bg_psi_mutex_key, &m_signal_mutex, MY_MUTEX_INIT_FAST);
|
|
|
|
mysql_cond_init(stop_bg_psi_cond_key, &m_signal_cond, nullptr);
|
|
|
|
}
|
|
|
|
|
2017-02-06 18:39:08 +01:00
|
|
|
void Rdb_thread::uninit() {
|
2016-10-06 19:24:09 +02:00
|
|
|
mysql_mutex_destroy(&m_signal_mutex);
|
|
|
|
mysql_cond_destroy(&m_signal_cond);
|
|
|
|
}
|
|
|
|
|
2017-02-06 18:39:08 +01:00
|
|
|
int Rdb_thread::create_thread(const std::string &thread_name
|
2016-10-06 19:24:09 +02:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
2017-02-06 18:39:08 +01:00
|
|
|
,
|
|
|
|
PSI_thread_key background_psi_thread_key
|
2016-10-06 19:24:09 +02:00
|
|
|
#endif
|
2019-06-15 20:29:46 +02:00
|
|
|
) {
|
2017-03-11 05:17:42 +01:00
|
|
|
// Make a copy of the name so we can return without worrying that the
|
|
|
|
// caller will free the memory
|
|
|
|
m_name = thread_name;
|
2016-10-06 19:24:09 +02:00
|
|
|
|
2017-03-11 05:17:42 +01:00
|
|
|
return mysql_thread_create(background_psi_thread_key, &m_handle, nullptr,
|
|
|
|
thread_func, this);
|
2016-10-06 19:24:09 +02:00
|
|
|
|
2017-02-06 18:39:08 +01:00
|
|
|
}
|
2016-10-06 19:24:09 +02:00
|
|
|
|
2019-06-15 20:29:46 +02:00
|
|
|
void Rdb_thread::signal(const bool stop_thread) {
|
2017-03-11 05:17:42 +01:00
|
|
|
RDB_MUTEX_LOCK_CHECK(m_signal_mutex);
|
|
|
|
|
2016-10-06 19:24:09 +02:00
|
|
|
if (stop_thread) {
|
2017-02-06 18:39:08 +01:00
|
|
|
m_stop = true;
|
2016-10-06 19:24:09 +02:00
|
|
|
}
|
2017-03-11 05:17:42 +01:00
|
|
|
|
2016-10-06 19:24:09 +02:00
|
|
|
mysql_cond_signal(&m_signal_cond);
|
2017-03-11 05:17:42 +01:00
|
|
|
|
|
|
|
RDB_MUTEX_UNLOCK_CHECK(m_signal_mutex);
|
2016-10-06 19:24:09 +02:00
|
|
|
}
|
|
|
|
|
2019-06-15 20:29:46 +02:00
|
|
|
} // namespace myrocks
|