From bf6fa4092b51f4d5573fa8ff3ea8b9adeade1950 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Wed, 24 Mar 2021 01:23:02 +0300 Subject: cleanup: use std::thread::id instead of os_thread_id_t --- extra/mariabackup/xbstream.cc | 5 +++ extra/mariabackup/xtrabackup.cc | 4 ++ sql/mysqld.cc | 5 +++ storage/innobase/CMakeLists.txt | 2 - storage/innobase/buf/buf0dump.cc | 1 - storage/innobase/buf/buf0flu.cc | 2 +- storage/innobase/include/dict0mem.h | 15 ++++--- storage/innobase/include/dict0stats_bg.h | 1 - storage/innobase/include/fil0fil.h | 18 ++++----- storage/innobase/include/lock0lock.h | 25 ++++++------ storage/innobase/include/os0thread.h | 42 -------------------- storage/innobase/include/sux_lock.h | 68 +++++++++++++++++--------------- storage/innobase/include/trx0trx.h | 17 ++++---- storage/innobase/include/ut0counter.h | 4 +- storage/innobase/lock/lock0lock.cc | 9 +++-- storage/innobase/os/os0file.cc | 1 - storage/innobase/os/os0thread.cc | 28 ------------- storage/innobase/srv/srv0start.cc | 1 - storage/innobase/trx/trx0purge.cc | 1 - storage/innobase/ut/ut0ut.cc | 3 +- 20 files changed, 100 insertions(+), 152 deletions(-) delete mode 100644 storage/innobase/include/os0thread.h delete mode 100644 storage/innobase/os/os0thread.cc diff --git a/extra/mariabackup/xbstream.cc b/extra/mariabackup/xbstream.cc index 3fe9d17d86e..a665172492f 100644 --- a/extra/mariabackup/xbstream.cc +++ b/extra/mariabackup/xbstream.cc @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA #include "common.h" #include "xbstream.h" #include "datasink.h" +#include #define XBSTREAM_VERSION "1.0" #define XBSTREAM_BUFFER_SIZE (10 * 1024 * 1024UL) @@ -92,9 +93,13 @@ static int mode_extract(int n_threads, int argc, char **argv); static my_bool get_one_option(const struct my_option *opt, const char *argument, const char *filename); +std::thread::id main_thread_id; + int main(int argc, char **argv) { + main_thread_id=std::this_thread::get_id(); + MY_INIT(argv[0]); if (get_options(&argc, &argv)) { diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 86c358dc212..991086e75cb 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -6379,9 +6379,13 @@ void handle_options(int argc, char **argv, char ***argv_server, static int main_low(char** argv); static int get_exepath(char *buf, size_t size, const char *argv0); +extern std::thread::id main_thread_id; + /* ================= main =================== */ int main(int argc, char **argv) { + main_thread_id = std::this_thread::get_id(); + char **server_defaults; char **client_defaults; char **backup_defaults; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4f522d96a9f..fc45a7d75c1 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -132,6 +132,7 @@ #define mysqld_charset &my_charset_latin1 +#include extern "C" { // Because of SCO 3.2V4.2 #include @@ -5226,8 +5227,12 @@ static void test_lc_time_sz() #endif//DBUG_OFF +std::thread::id main_thread_id; + int mysqld_main(int argc, char **argv) { + main_thread_id = std::this_thread::get_id(); + #ifndef _WIN32 /* We can't close stdin just now, because it may be booststrap mode. */ bool please_close_stdin= fcntl(STDIN_FILENO, F_GETFD) >= 0; diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 4a20d6807a6..83104b25154 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -188,7 +188,6 @@ SET(INNOBASE_SOURCES include/mtr0types.h include/os0file.h include/os0file.ic - include/os0thread.h include/page0cur.h include/page0cur.ic include/page0page.h @@ -285,7 +284,6 @@ SET(INNOBASE_SOURCES mem/mem0mem.cc mtr/mtr0mtr.cc os/os0file.cc - os/os0thread.cc page/page0cur.cc page/page0page.cc page/page0zip.cc diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index db7b0032ec7..437f3c6dba9 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -35,7 +35,6 @@ Created April 08, 2011 Vasil Dimov #include "buf0dump.h" #include "dict0dict.h" #include "os0file.h" -#include "os0thread.h" #include "srv0srv.h" #include "srv0start.h" #include "ut0byte.h" diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index 45d7ee993b1..91d567b6d90 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -2038,7 +2038,7 @@ static void buf_flush_page_cleaner() #ifdef UNIV_DEBUG_THREAD_CREATION ib::info() << "page_cleaner thread running, id " - << os_thread_get_curr_id(); + << std::this_thread::get_id(); #endif /* UNIV_DEBUG_THREAD_CREATION */ #ifdef UNIV_LINUX /* linux might be able to set different setting for each thread. diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 2d87d7f689f..2af2df2f50b 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -1961,10 +1961,10 @@ struct dict_table_t { #ifdef UNIV_DEBUG /** @return whether the current thread holds the lock_mutex */ bool lock_mutex_is_owner() const - { return lock_mutex_owner == os_thread_get_curr_id(); } + { return lock_mutex_owner == std::this_thread::get_id(); } /** @return whether the current thread holds the stats_mutex (lock_mutex) */ bool stats_mutex_is_owner() const - { return lock_mutex_owner == os_thread_get_curr_id(); } + { return lock_mutex_owner == std::this_thread::get_id(); } #endif /* UNIV_DEBUG */ void lock_mutex_init() { lock_mutex.init(); } void lock_mutex_destroy() { lock_mutex.destroy(); } @@ -1973,20 +1973,23 @@ struct dict_table_t { { ut_ad(!lock_mutex_is_owner()); lock_mutex.wr_lock(); - ut_ad(!lock_mutex_owner.exchange(os_thread_get_curr_id())); + ut_ad(lock_mutex_owner.exchange(std::this_thread::get_id()) == + std::thread::id()); } /** Try to acquire lock_mutex */ bool lock_mutex_trylock() { ut_ad(!lock_mutex_is_owner()); bool acquired= lock_mutex.wr_lock_try(); - ut_ad(!acquired || !lock_mutex_owner.exchange(os_thread_get_curr_id())); + ut_ad(!acquired || lock_mutex_owner.exchange(std::this_thread::get_id()) == + std::thread::id()); return acquired; } /** Release lock_mutex */ void lock_mutex_unlock() { - ut_ad(lock_mutex_owner.exchange(0) == os_thread_get_curr_id()); + ut_ad(lock_mutex_owner.exchange(std::thread::id()) == + std::this_thread::get_id()); lock_mutex.wr_unlock(); } @@ -2315,7 +2318,7 @@ private: srw_mutex lock_mutex; #ifdef UNIV_DEBUG /** The owner of lock_mutex (0 if none) */ - Atomic_relaxed lock_mutex_owner{0}; + Atomic_relaxed lock_mutex_owner; #endif public: /** Autoinc counter value to give to the next inserted row. */ diff --git a/storage/innobase/include/dict0stats_bg.h b/storage/innobase/include/dict0stats_bg.h index e9318a0116d..c5e19a1a593 100644 --- a/storage/innobase/include/dict0stats_bg.h +++ b/storage/innobase/include/dict0stats_bg.h @@ -28,7 +28,6 @@ Created Apr 26, 2012 Vasil Dimov #define dict0stats_bg_h #include "dict0types.h" -#include "os0thread.h" #ifdef HAVE_PSI_INTERFACE extern mysql_pfs_key_t recalc_pool_mutex_key; diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index 70cbedc3a94..de98a2ed0ce 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -341,7 +341,7 @@ struct fil_space_t final friend fil_node_t; ~fil_space_t() { - ut_ad(!latch_owner); + ut_ad(latch_owner == std::thread::id()); ut_ad(!latch_count); latch.destroy(); } @@ -396,7 +396,7 @@ private: static constexpr uint32_t PENDING= ~(STOPPING | CLOSING | NEEDS_FSYNC); /** latch protecting all page allocation bitmap pages */ srw_lock latch; - os_thread_id_t latch_owner; + std::thread::id latch_owner; ut_d(Atomic_relaxed latch_count;) public: UT_LIST_NODE_T(fil_space_t) named_spaces; @@ -995,21 +995,21 @@ public: #ifdef UNIV_DEBUG bool is_latched() const { return latch_count != 0; } #endif - bool is_owner() const { return latch_owner == os_thread_get_curr_id(); } + bool is_owner() const { return latch_owner == std::this_thread::get_id(); } /** Acquire the allocation latch in exclusive mode */ void x_lock() { latch.wr_lock(SRW_LOCK_CALL); - ut_ad(!latch_owner); - latch_owner= os_thread_get_curr_id(); + ut_ad(latch_owner == std::thread::id()); + latch_owner= std::this_thread::get_id(); ut_ad(!latch_count.fetch_add(1)); } /** Release the allocation latch from exclusive mode */ void x_unlock() { ut_ad(latch_count.fetch_sub(1) == 1); - ut_ad(latch_owner == os_thread_get_curr_id()); - latch_owner= 0; + ut_ad(latch_owner == std::this_thread::get_id()); + latch_owner= std::thread::id(); latch.wr_unlock(); } /** Acquire the allocation latch in shared mode */ @@ -1017,14 +1017,14 @@ public: { ut_ad(!is_owner()); latch.rd_lock(SRW_LOCK_CALL); - ut_ad(!latch_owner); + ut_ad(latch_owner == std::thread::id()); ut_d(latch_count.fetch_add(1)); } /** Release the allocation latch from shared mode */ void s_unlock() { ut_ad(latch_count.fetch_sub(1)); - ut_ad(!latch_owner); + ut_ad(latch_owner == std::thread::id()); latch.rd_unlock(); } diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h index c3b802f4284..7542aaae310 100644 --- a/storage/innobase/include/lock0lock.h +++ b/storage/innobase/include/lock0lock.h @@ -641,8 +641,8 @@ private: /** mutex proteting the locks */ MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) srw_lock latch; #ifdef UNIV_DEBUG - /** The owner of exclusive latch (0 if none); protected by latch */ - std::atomic writer{0}; + /** The owner of exclusive latch; protected by latch */ + std::atomic writer; /** Number of shared latches */ std::atomic readers{0}; #endif @@ -705,14 +705,14 @@ public: { ut_ad(!is_writer()); latch.wr_lock(); - ut_ad(!writer.exchange(os_thread_get_curr_id(), - std::memory_order_relaxed)); + ut_ad(writer.exchange(std::this_thread::get_id(), + std::memory_order_relaxed) == std::thread::id()); } /** Release exclusive lock_sys.latch */ void wr_unlock() { - ut_ad(writer.exchange(0, std::memory_order_relaxed) == - os_thread_get_curr_id()); + ut_ad(writer.exchange(std::thread::id(), std::memory_order_relaxed) == + std::this_thread::get_id()); latch.wr_unlock(); } /** Acquire shared lock_sys.latch */ @@ -720,7 +720,7 @@ public: { ut_ad(!is_writer()); latch.rd_lock(); - ut_ad(!writer.load(std::memory_order_relaxed)); + ut_ad(writer.load(std::memory_order_relaxed) == std::thread::id()); ut_d(readers.fetch_add(1, std::memory_order_relaxed)); } /** Release shared lock_sys.latch */ @@ -737,8 +737,8 @@ public: { ut_ad(!is_writer()); if (!latch.wr_lock_try()) return false; - ut_ad(!writer.exchange(os_thread_get_curr_id(), - std::memory_order_relaxed)); + ut_ad(writer.exchange(std::this_thread::get_id(), + std::memory_order_relaxed) == std::thread::id()); return true; } /** Try to acquire shared lock_sys.latch @@ -747,7 +747,7 @@ public: { ut_ad(!is_writer()); if (!latch.rd_lock_try()) return false; - ut_ad(!writer.load(std::memory_order_relaxed)); + ut_ad(writer.load(std::memory_order_relaxed) == std::thread::id()); ut_d(readers.fetch_add(1, std::memory_order_relaxed)); return true; } @@ -759,7 +759,10 @@ public: #ifdef UNIV_DEBUG /** @return whether the current thread is the lock_sys.latch writer */ bool is_writer() const - { return writer.load(std::memory_order_relaxed) == os_thread_get_curr_id(); } + { + return writer.load(std::memory_order_relaxed) == + std::this_thread::get_id(); + } /** Assert that a lock shard is exclusively latched (by some thread) */ void assert_locked(const lock_t &lock) const; /** Assert that a table lock shard is exclusively latched by this thread */ diff --git a/storage/innobase/include/os0thread.h b/storage/innobase/include/os0thread.h deleted file mode 100644 index b2971462a70..00000000000 --- a/storage/innobase/include/os0thread.h +++ /dev/null @@ -1,42 +0,0 @@ -/***************************************************************************** - -Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -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 -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 Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/**************************************************//** -@file include/os0thread.h -The interface to the operating system -process and thread control primitives - -Created 9/8/1995 Heikki Tuuri -*******************************************************/ - -#pragma once -#include "univ.i" - -#ifdef _WIN32 -typedef DWORD os_thread_id_t; /*!< In Windows the thread id - is an unsigned long int */ -#else - -typedef pthread_t os_thread_id_t; /*!< In Unix we use the thread - handle itself as the id of - the thread */ -#endif /* _WIN32 */ - -#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()) diff --git a/storage/innobase/include/sux_lock.h b/storage/innobase/include/sux_lock.h index f967e8c81cd..f7106b164cf 100644 --- a/storage/innobase/include/sux_lock.h +++ b/storage/innobase/include/sux_lock.h @@ -19,10 +19,12 @@ this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "srw_lock.h" #include "my_atomic_wrapper.h" -#include "os0thread.h" #ifdef UNIV_DEBUG # include #endif +#include + +extern std::thread::id main_thread_id; /** A "fat" rw-lock that supports S (shared), U (update, or shared-exclusive), and X (exclusive) modes @@ -36,19 +38,15 @@ class sux_lock final /** Numbers of U and X locks. Protected by lock. */ uint32_t recursive; /** The owner of the U or X lock (0 if none); protected by lock */ - std::atomic writer; + std::atomic writer; /** Special writer!=0 value to indicate that the lock is non-recursive and will be released by an I/O thread */ -#if defined __linux__ || defined _WIN32 - static constexpr os_thread_id_t FOR_IO= os_thread_id_t(~0UL); -#else -# define FOR_IO ((os_thread_id_t) ~0UL) /* it could be a pointer */ -#endif + static std::thread::id FOR_IO; #ifdef UNIV_DEBUG /** Protects readers */ mutable srw_mutex readers_lock; /** Threads that hold the lock in shared mode */ - std::atomic*> readers; + std::atomic*> readers; #endif /** The multiplier in recursive for X locks */ @@ -65,16 +63,18 @@ public: void SRW_LOCK_INIT(mysql_pfs_key_t key) { lock.SRW_LOCK_INIT(key); - ut_ad(!writer.load(std::memory_order_relaxed)); + ut_ad(writer.load(std::memory_order_relaxed) == std::thread::id()); ut_ad(!recursive); ut_d(readers_lock.init()); ut_ad(!readers.load(std::memory_order_relaxed)); + FOR_IO= main_thread_id; + ut_ad(FOR_IO != std::thread::id()); } /** Free the rw-lock after create() */ void free() { - ut_ad(!writer.load(std::memory_order_relaxed)); + ut_ad(writer.load(std::memory_order_relaxed) == std::thread::id()); ut_ad(!recursive); #ifdef UNIV_DEBUG readers_lock.destroy(); @@ -103,7 +103,7 @@ public: /** Acquire a recursive lock */ template void writer_recurse() { - ut_ad(writer == os_thread_get_curr_id()); + ut_ad(writer == std::this_thread::get_id()); ut_d(auto rec= (recursive / (allow_readers ? RECURSIVE_U : RECURSIVE_X)) & RECURSIVE_MAX); ut_ad(allow_readers ? recursive : rec); @@ -114,28 +114,30 @@ public: private: /** Transfer the ownership of a write lock to another thread @param id the new owner of the U or X lock */ - void set_new_owner(os_thread_id_t id) + void set_new_owner(std::thread::id id) { - IF_DBUG(DBUG_ASSERT(writer.exchange(id, std::memory_order_relaxed)), + IF_DBUG(DBUG_ASSERT(writer.exchange(id, std::memory_order_relaxed) != + std::thread::id()), 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(os_thread_id_t id) + void set_first_owner(std::thread::id id) { - IF_DBUG(DBUG_ASSERT(!writer.exchange(id, std::memory_order_relaxed)), + IF_DBUG(DBUG_ASSERT(writer.exchange(id, std::memory_order_relaxed) == + std::thread::id()), writer.store(id, std::memory_order_relaxed)); } #ifdef UNIV_DEBUG /** Register the current thread as a holder of a shared lock */ void s_lock_register() { - const os_thread_id_t id= os_thread_get_curr_id(); + const auto id= std::this_thread::get_id(); readers_lock.wr_lock(); auto r= readers.load(std::memory_order_relaxed); if (!r) { - r= new std::unordered_multiset(); + r= new std::unordered_multiset(); readers.store(r, std::memory_order_relaxed); } r->emplace(id); @@ -146,12 +148,12 @@ private: public: /** In crash recovery or the change buffer, claim the ownership of the exclusive block lock to the current thread */ - void claim_ownership() { set_new_owner(os_thread_get_curr_id()); } + void claim_ownership() { set_new_owner(std::this_thread::get_id()); } /** @return whether the current thread is holding X or U latch */ bool have_u_or_x() const { - if (os_thread_get_curr_id() != writer.load(std::memory_order_relaxed)) + if (std::this_thread::get_id() != writer.load(std::memory_order_relaxed)) return false; ut_ad(recursive); return true; @@ -169,7 +171,7 @@ public: if (auto r= readers.load(std::memory_order_relaxed)) { readers_lock.wr_lock(); - bool found= r->find(os_thread_get_curr_id()) != r->end(); + bool found= r->find(std::this_thread::get_id()) != r->end(); readers_lock.wr_unlock(); return found; } @@ -227,7 +229,7 @@ public: void s_unlock() { #ifdef UNIV_DEBUG - const os_thread_id_t id= os_thread_get_curr_id(); + const auto id= std::this_thread::get_id(); auto r= readers.load(std::memory_order_relaxed); ut_ad(r); readers_lock.wr_lock(); @@ -244,7 +246,7 @@ public: void u_or_x_unlock(bool allow_readers, bool claim_ownership= false) { ut_d(auto owner= writer.load(std::memory_order_relaxed)); - ut_ad(owner == os_thread_get_curr_id() || + ut_ad(owner == std::this_thread::get_id() || (owner == FOR_IO && claim_ownership && recursive == (allow_readers ? RECURSIVE_U : RECURSIVE_X))); ut_d(auto rec= (recursive / (allow_readers ? RECURSIVE_U : RECURSIVE_X)) & @@ -252,7 +254,7 @@ public: ut_ad(rec); if (!(recursive-= allow_readers ? RECURSIVE_U : RECURSIVE_X)) { - set_new_owner(0); + set_new_owner(std::thread::id()); if (allow_readers) lock.u_unlock(); else @@ -270,6 +272,8 @@ public: bool is_waiting() const { return lock.is_waiting(); } }; +template std::thread::id sux_lock::FOR_IO= main_thread_id; + /** needed for dict_index_t::clone() */ template<> inline void sux_lock::operator=(const sux_lock&) { @@ -286,10 +290,10 @@ typedef sux_lock index_lock; template<> inline void sux_lock::init() { lock.init(); - ut_ad(!writer.load(std::memory_order_relaxed)); + ut_ad(writer.load(std::memory_order_relaxed) == std::thread::id()); ut_ad(!recursive); ut_d(readers_lock.init()); - ut_ad(!readers.load(std::memory_order_relaxed)); + ut_ad(readers.load(std::memory_order_relaxed) == std::thread::id()); } template<> @@ -304,7 +308,7 @@ inline void sux_lock::s_lock(const char *file, unsigned line) template<> inline void sux_lock::u_lock(const char *file, unsigned line) { - os_thread_id_t id= os_thread_get_curr_id(); + auto id= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == id) writer_recurse(); else @@ -319,7 +323,7 @@ inline void sux_lock::u_lock(const char *file, unsigned line) template<> inline void sux_lock::x_lock(const char *file, unsigned line) { - os_thread_id_t id= os_thread_get_curr_id(); + auto id= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == id) writer_recurse(); else @@ -352,7 +356,7 @@ inline void sux_lock::s_lock() template<> inline void sux_lock::u_lock() { - os_thread_id_t id= os_thread_get_curr_id(); + auto id= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == id) writer_recurse(); else @@ -367,7 +371,7 @@ inline void sux_lock::u_lock() template<> inline void sux_lock::x_lock(bool for_io) { - os_thread_id_t id= os_thread_get_curr_id(); + auto id= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == id) { ut_ad(!for_io); @@ -392,7 +396,7 @@ inline void sux_lock::u_x_upgrade() template<> inline bool sux_lock::x_lock_upgraded() { - os_thread_id_t id= os_thread_get_curr_id(); + auto id= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == id) { ut_ad(recursive); @@ -420,7 +424,7 @@ template<> inline bool sux_lock::x_lock_upgraded() template<> inline bool sux_lock::u_lock_try(bool for_io) { - os_thread_id_t id= os_thread_get_curr_id(); + auto id= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == id) { if (for_io) @@ -441,7 +445,7 @@ inline bool sux_lock::u_lock_try(bool for_io) template<> inline bool sux_lock::x_lock_try() { - os_thread_id_t id= os_thread_get_curr_id(); + auto id= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == id) { writer_recurse(); diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 9890a9224f8..00af38e7ee2 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -574,7 +574,7 @@ no longer be associated with a session when the server is restarted. A session may be served by at most one thread at a time. The serving thread of a session might change in some MySQL implementations. -Therefore we do not have os_thread_get_curr_id() assertions in the code. +Therefore we do not have std::this_thread::get_id() assertions in the code. Normally, only the thread that is currently associated with a running transaction may access (read and modify) the trx object, and it may do @@ -654,8 +654,8 @@ private: (some are protected by lock_sys.latch) */ srw_mutex mutex; #ifdef UNIV_DEBUG - /** The owner of mutex (0 if none); protected by mutex */ - std::atomic mutex_owner{0}; + /** The owner of mutex; protected by mutex */ + std::atomic mutex_owner; #endif /* UNIV_DEBUG */ public: void mutex_init() { mutex.init(); } @@ -666,14 +666,15 @@ public: { ut_ad(!mutex_is_owner()); mutex.wr_lock(); - ut_ad(!mutex_owner.exchange(os_thread_get_curr_id(), - std::memory_order_relaxed)); + ut_ad(mutex_owner.exchange(std::this_thread::get_id(), + std::memory_order_relaxed) == + std::thread::id()); } /** Release the mutex */ void mutex_unlock() { - ut_ad(mutex_owner.exchange(0, std::memory_order_relaxed) - == os_thread_get_curr_id()); + ut_ad(mutex_owner.exchange(std::thread::id(), std::memory_order_relaxed) == + std::this_thread::get_id()); mutex.wr_unlock(); } #ifdef UNIV_DEBUG @@ -681,7 +682,7 @@ public: bool mutex_is_owner() const { return mutex_owner.load(std::memory_order_relaxed) == - os_thread_get_curr_id(); + std::this_thread::get_id(); } #endif /* UNIV_DEBUG */ diff --git a/storage/innobase/include/ut0counter.h b/storage/innobase/include/ut0counter.h index 419ad3a81b8..8735907bb33 100644 --- a/storage/innobase/include/ut0counter.h +++ b/storage/innobase/include/ut0counter.h @@ -28,7 +28,7 @@ Created 2012/04/12 by Sunny Bains #ifndef ut0counter_h #define ut0counter_h -#include "os0thread.h" +#include #include "my_rdtsc.h" /** CPU cache line size */ @@ -53,7 +53,7 @@ get_rnd_value() /* We may go here if my_timer_cycles() returns 0, so we have to have the plan B for the counter. */ #if !defined(_WIN32) - return (size_t)os_thread_get_curr_id(); + return std::hash()(std::this_thread::get_id()); #else LARGE_INTEGER cnt; QueryPerformanceCounter(&cnt); diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 164aa29fe59..414c261d8c2 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -166,7 +166,7 @@ void lock_sys_t::assert_locked(const dict_table_t &table) const { ut_ad(!table.is_temporary()); - const os_thread_id_t current_thread= os_thread_get_curr_id(); + const auto current_thread= std::this_thread::get_id(); if (writer.load(std::memory_order_relaxed) == current_thread) return; ut_ad(readers); @@ -392,13 +392,14 @@ void lock_sys_t::create(ulint n_cells) void lock_sys_t::wr_lock(const char *file, unsigned line) { latch.wr_lock(file, line); - ut_ad(!writer.exchange(os_thread_get_curr_id(), std::memory_order_relaxed)); + ut_ad(writer.exchange(std::this_thread::get_id(), + std::memory_order_relaxed) == std::thread::id()); } /** Release exclusive lock_sys.latch */ void lock_sys_t::wr_unlock() { - ut_ad(writer.exchange(0, std::memory_order_relaxed) == - os_thread_get_curr_id()); + ut_ad(writer.exchange(std::thread::id(), std::memory_order_relaxed) == + std::this_thread::get_id()); latch.wr_unlock(); } diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 30955b949fa..6ae92f7bab4 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -50,7 +50,6 @@ Created 10/21/1995 Heikki Tuuri #ifdef HAVE_LINUX_UNISTD_H #include "unistd.h" #endif -#include "os0thread.h" #include "buf0dblwr.h" #include diff --git a/storage/innobase/os/os0thread.cc b/storage/innobase/os/os0thread.cc deleted file mode 100644 index a5158ef825d..00000000000 --- a/storage/innobase/os/os0thread.cc +++ /dev/null @@ -1,28 +0,0 @@ -/***************************************************************************** - -Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2020, 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 -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 Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/**************************************************//** -@file os/os0thread.cc -The interface to the operating system thread control primitives - -Created 9/8/1995 Heikki Tuuri -*******************************************************/ - -#include "univ.i" -#include "srv0srv.h" diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 59678b09825..c2414f056de 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -55,7 +55,6 @@ Created 2/16/1996 Heikki Tuuri #include "buf0dblwr.h" #include "buf0dump.h" #include "os0file.h" -#include "os0thread.h" #include "fil0fil.h" #include "fil0crypt.h" #include "fsp0fsp.h" diff --git a/storage/innobase/trx/trx0purge.cc b/storage/innobase/trx/trx0purge.cc index 9d248061c59..69878241a8c 100644 --- a/storage/innobase/trx/trx0purge.cc +++ b/storage/innobase/trx/trx0purge.cc @@ -29,7 +29,6 @@ Created 3/26/1996 Heikki Tuuri #include "fut0fut.h" #include "mach0data.h" #include "mtr0log.h" -#include "os0thread.h" #include "que0que.h" #include "row0purge.h" #include "row0upd.h" diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc index fa04af6de13..06b49b98994 100644 --- a/storage/innobase/ut/ut0ut.cc +++ b/storage/innobase/ut/ut0ut.cc @@ -32,7 +32,6 @@ Created 5/11/1994 Heikki Tuuri #ifndef UNIV_INNOCHECKSUM #include -#include "os0thread.h" #include "ut0ut.h" #include "trx0trx.h" #include @@ -92,7 +91,7 @@ ut_print_timestamp( #ifdef UNIV_INNOCHECKSUM ulint{0} #else - ulint(os_thread_get_curr_id()) + ulint(std::hash()(std::this_thread::get_id())) #endif ); } -- cgit v1.2.1