diff options
author | Eugene Kosov <claprix@yandex.ru> | 2021-03-17 10:03:06 +0300 |
---|---|---|
committer | Eugene Kosov <claprix@yandex.ru> | 2021-03-19 11:44:28 +0300 |
commit | dbe941e06fe51fe0ff30dff5f1ae62960ff4fc61 (patch) | |
tree | d9d40ca19ccfe2962e593ba23fed88b2890674a8 /storage/innobase | |
parent | da3428805efd2860a26f162cc1e4fff9d95f84e1 (diff) | |
download | mariadb-git-dbe941e06fe51fe0ff30dff5f1ae62960ff4fc61.tar.gz |
cleanup: os_thread_create -> std::thread
Diffstat (limited to 'storage/innobase')
-rw-r--r-- | storage/innobase/buf/buf0flu.cc | 17 | ||||
-rw-r--r-- | storage/innobase/fil/fil0crypt.cc | 20 | ||||
-rw-r--r-- | storage/innobase/include/os0thread.h | 35 | ||||
-rw-r--r-- | storage/innobase/include/trx0roll.h | 7 | ||||
-rw-r--r-- | storage/innobase/os/os0thread.cc | 71 | ||||
-rw-r--r-- | storage/innobase/srv/srv0start.cc | 7 | ||||
-rw-r--r-- | storage/innobase/trx/trx0roll.cc | 20 |
7 files changed, 27 insertions, 150 deletions
diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index dbb623b3054..45d7ee993b1 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -2025,11 +2025,9 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in, return(n_pages); } -/******************************************************************//** -page_cleaner thread tasked with flushing dirty pages from the buffer -pools. As of now we'll have only one coordinator. -@return a dummy parameter */ -static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*) +/** page_cleaner thread tasked with flushing dirty pages from the buffer +pools. As of now we'll have only one coordinator. */ +static void buf_flush_page_cleaner() { my_thread_init(); #ifdef UNIV_PFS_THREAD @@ -2253,11 +2251,10 @@ next: mysql_mutex_unlock(&buf_pool.flush_list_mutex); my_thread_end(); - /* We count the number of threads in os_thread_exit(). A created - thread should always use that to exit and not use return() to exit. */ - os_thread_exit(); - OS_THREAD_DUMMY_RETURN; +#ifdef UNIV_PFS_THREAD + pfs_delete_thread(); +#endif } /** Initialize page_cleaner. */ @@ -2269,7 +2266,7 @@ ATTRIBUTE_COLD void buf_flush_page_cleaner_init() srv_operation == SRV_OPERATION_RESTORE_EXPORT); buf_flush_sync_lsn= 0; buf_page_cleaner_is_active= true; - os_thread_create(buf_flush_page_cleaner); + std::thread(buf_flush_page_cleaner).detach(); } /** @return the number of dirty pages in the buffer pool */ diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 01b103a726f..c481b76f036 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -2062,10 +2062,9 @@ static void fil_crypt_complete_rotate_space(rotate_thread_t* state) mysql_mutex_unlock(&crypt_data->mutex); } -/*********************************************************************//** -A thread which monitors global key state and rotates tablespaces accordingly -@return a dummy parameter */ -static os_thread_ret_t DECLARE_THREAD(fil_crypt_thread)(void*) +/** A thread which monitors global key state and rotates tablespaces +accordingly */ +static void fil_crypt_thread() { mysql_mutex_lock(&fil_crypt_threads_mutex); rotate_thread_t thr(srv_n_fil_crypt_threads_started++); @@ -2144,12 +2143,9 @@ wait_for_work: 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 - thread should always use that to exit and not use return() to exit. */ - - os_thread_exit(); - - OS_THREAD_DUMMY_RETURN; +#ifdef UNIV_PFS_THREAD + pfs_delete_thread(); +#endif } /********************************************************************* @@ -2172,10 +2168,12 @@ fil_crypt_set_thread_cnt( uint add = new_cnt - srv_n_fil_crypt_threads; srv_n_fil_crypt_threads = new_cnt; for (uint i = 0; i < add; i++) { + std::thread thd(fil_crypt_thread); ib::info() << "Creating #" << i+1 << " encryption thread id " - << os_thread_create(fil_crypt_thread) + << thd.get_id() << " total threads " << new_cnt << "."; + thd.detach(); } } else if (new_cnt < srv_n_fil_crypt_threads) { srv_n_fil_crypt_threads = new_cnt; diff --git a/storage/innobase/include/os0thread.h b/storage/innobase/include/os0thread.h index d53099148d4..b2971462a70 100644 --- a/storage/innobase/include/os0thread.h +++ b/storage/innobase/include/os0thread.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2020, MariaDB Corporation. +Copyright (c) 2017, 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 @@ -28,48 +28,15 @@ Created 9/8/1995 Heikki Tuuri #pragma once #include "univ.i" -/* Possible fixed priorities for threads */ -#define OS_THREAD_PRIORITY_NONE 100 -#define OS_THREAD_PRIORITY_BACKGROUND 1 -#define OS_THREAD_PRIORITY_NORMAL 2 -#define OS_THREAD_PRIORITY_ABOVE_NORMAL 3 - #ifdef _WIN32 -typedef DWORD os_thread_t; typedef DWORD os_thread_id_t; /*!< In Windows the thread id is an unsigned long int */ -extern "C" { -typedef LPTHREAD_START_ROUTINE os_thread_func_t; -} - -/** Macro for specifying a Windows thread start function. */ -#define DECLARE_THREAD(func) WINAPI func #else -typedef pthread_t os_thread_t; typedef pthread_t os_thread_id_t; /*!< In Unix we use the thread handle itself as the id of the thread */ -extern "C" { typedef void* (*os_thread_func_t)(void*); } - -/** Macro for specifying a POSIX thread start function. */ -#define DECLARE_THREAD(func) func #endif /* _WIN32 */ -/* Define a function pointer type to use in a typecast */ -typedef void* (*os_posix_f_t) (void*); - #define os_thread_eq(a,b) IF_WIN(a == b, pthread_equal(a, b)) #define os_thread_get_curr_id() IF_WIN(GetCurrentThreadId(), pthread_self()) - -/****************************************************************//** -Creates a new thread of execution. The execution starts from -the function given. -NOTE: We count the number of threads in os_thread_exit(). A created -thread should always use that to exit so thatthe thread count will be -decremented. -We do not return an error code because if there is one, we crash here. */ -os_thread_t os_thread_create(os_thread_func_t func, void *arg= nullptr); - -/** Detach and terminate the current thread. */ -ATTRIBUTE_NORETURN void os_thread_exit(); diff --git a/storage/innobase/include/trx0roll.h b/storage/innobase/include/trx0roll.h index 01c17f1943c..d39e5bfb2f5 100644 --- a/storage/innobase/include/trx0roll.h +++ b/storage/innobase/include/trx0roll.h @@ -50,11 +50,8 @@ Rollback or clean up any incomplete transactions which were encountered in crash recovery. If the transaction already was committed, then we clean up a possible insert undo log. If the transaction was not yet committed, then we roll it back. -Note: this is done in a background thread. -@return a dummy parameter */ -extern "C" -os_thread_ret_t -DECLARE_THREAD(trx_rollback_all_recovered)(void*); +Note: this is done in a background thread. */ +void trx_rollback_all_recovered(void*); /*********************************************************************//** Creates a rollback command node struct. @return own: rollback node struct */ diff --git a/storage/innobase/os/os0thread.cc b/storage/innobase/os/os0thread.cc index cb627a6392d..a5158ef825d 100644 --- a/storage/innobase/os/os0thread.cc +++ b/storage/innobase/os/os0thread.cc @@ -26,74 +26,3 @@ Created 9/8/1995 Heikki Tuuri #include "univ.i" #include "srv0srv.h" - -/****************************************************************//** -Creates a new thread of execution. The execution starts from -the function given. -NOTE: We count the number of threads in os_thread_exit(). A created -thread should always use that to exit so thatthe thread count will be -decremented. -We do not return an error code because if there is one, we crash here. */ -os_thread_t os_thread_create(os_thread_func_t func, void *arg) -{ - os_thread_id_t new_thread_id; - -#ifdef _WIN32 - HANDLE handle; - - handle = CreateThread(NULL, /* no security attributes */ - 0, /* default size stack */ - func, - arg, - 0, /* thread runs immediately */ - &new_thread_id); - - if (!handle) { - /* If we cannot start a new thread, life has no meaning. */ - ib::fatal() << "CreateThread returned " << GetLastError(); - } - - CloseHandle(handle); - - return((os_thread_t)new_thread_id); -#else /* _WIN32 else */ - - pthread_attr_t attr; - - int ret = pthread_attr_init(&attr); - if (UNIV_UNLIKELY(ret)) { - fprintf(stderr, - "InnoDB: Error: pthread_attr_init() returned %d\n", - ret); - abort(); - } - - ret = pthread_create(&new_thread_id, &attr, func, arg); - - ut_a(ret == 0); - - pthread_attr_destroy(&attr); - -#endif /* not _WIN32 */ - - return((os_thread_t)new_thread_id); -} - -/** Detach and terminate the current thread. */ -ATTRIBUTE_NORETURN void os_thread_exit() -{ -#ifdef UNIV_DEBUG_THREAD_CREATION - ib::info() << "Thread exits, id " << os_thread_get_curr_id(); -#endif - -#ifdef UNIV_PFS_THREAD - pfs_delete_thread(); -#endif - -#ifdef _WIN32 - ExitThread(0); -#else - pthread_detach(pthread_self()); - pthread_exit(NULL); -#endif -} diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 7df61a3922a..59678b09825 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1042,6 +1042,11 @@ static dberr_t find_and_check_log_file(bool &log_file_found) return DB_SUCCESS; } +static tpool::task_group rollback_all_recovered_group(1); +static tpool::task rollback_all_recovered_task(trx_rollback_all_recovered, + nullptr, + &rollback_all_recovered_group); + /** Start InnoDB. @param[in] create_new_db whether to create a new database @return DB_SUCCESS or error code */ @@ -1785,7 +1790,7 @@ file_checked: /* Rollback incomplete non-DDL transactions */ trx_rollback_is_active = true; - os_thread_create(trx_rollback_all_recovered); + srv_thread_pool->submit_task(&rollback_all_recovered_task); } } diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index 6b5b08e9c70..5ff0250be8c 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -800,19 +800,11 @@ Rollback or clean up any incomplete transactions which were encountered in crash recovery. If the transaction already was committed, then we clean up a possible insert undo log. If the transaction was not yet committed, then we roll it back. -Note: this is done in a background thread. -@return a dummy parameter */ -extern "C" -os_thread_ret_t -DECLARE_THREAD(trx_rollback_all_recovered)(void*) +Note: this is done in a background thread. */ +void trx_rollback_all_recovered(void*) { - my_thread_init(); ut_ad(!srv_read_only_mode); -#ifdef UNIV_PFS_THREAD - pfs_register_thread(trx_rollback_clean_thread_key); -#endif /* UNIV_PFS_THREAD */ - if (trx_sys.rw_trx_hash.size()) { ib::info() << "Starting in background the rollback of" " recovered transactions"; @@ -822,14 +814,6 @@ DECLARE_THREAD(trx_rollback_all_recovered)(void*) } trx_rollback_is_active = false; - - my_thread_end(); - /* We count the number of threads in os_thread_exit(). A created - thread should always use that to exit and not use return() to exit. */ - - os_thread_exit(); - - OS_THREAD_DUMMY_RETURN; } /****************************************************************//** |