Commit d1edb011 authored by Marko Mäkelä's avatar Marko Mäkelä

Cleanup: Remove os0thread

Let us use the common pthread_t wrapper for Microsoft Windows.

This fixes up commit dbe941e0
parent 7da351d8
# Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2014, 2021, MariaDB Corporation. # Copyright (c) 2014, 2022, MariaDB Corporation.
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -186,7 +186,6 @@ SET(INNOBASE_SOURCES ...@@ -186,7 +186,6 @@ SET(INNOBASE_SOURCES
include/mtr0types.h include/mtr0types.h
include/os0file.h include/os0file.h
include/os0file.inl include/os0file.inl
include/os0thread.h
include/page0cur.h include/page0cur.h
include/page0cur.inl include/page0cur.inl
include/page0page.h include/page0page.h
...@@ -283,7 +282,6 @@ SET(INNOBASE_SOURCES ...@@ -283,7 +282,6 @@ SET(INNOBASE_SOURCES
mem/mem0mem.cc mem/mem0mem.cc
mtr/mtr0mtr.cc mtr/mtr0mtr.cc
os/os0file.cc os/os0file.cc
os/os0thread.cc
page/page0cur.cc page/page0cur.cc
page/page0page.cc page/page0page.cc
page/page0zip.cc page/page0zip.cc
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2011, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2011, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2021, MariaDB Corporation. Copyright (c) 2017, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -35,7 +35,6 @@ Created April 08, 2011 Vasil Dimov ...@@ -35,7 +35,6 @@ Created April 08, 2011 Vasil Dimov
#include "buf0dump.h" #include "buf0dump.h"
#include "dict0dict.h" #include "dict0dict.h"
#include "os0file.h" #include "os0file.h"
#include "os0thread.h"
#include "srv0srv.h" #include "srv0srv.h"
#include "srv0start.h" #include "srv0start.h"
#include "ut0byte.h" #include "ut0byte.h"
......
...@@ -1952,10 +1952,10 @@ struct dict_table_t { ...@@ -1952,10 +1952,10 @@ struct dict_table_t {
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/** @return whether the current thread holds the lock_mutex */ /** @return whether the current thread holds the lock_mutex */
bool lock_mutex_is_owner() const bool lock_mutex_is_owner() const
{ return lock_mutex_owner == os_thread_get_curr_id(); } { return lock_mutex_owner == pthread_self(); }
/** @return whether the current thread holds the stats_mutex (lock_mutex) */ /** @return whether the current thread holds the stats_mutex (lock_mutex) */
bool stats_mutex_is_owner() const bool stats_mutex_is_owner() const
{ return lock_mutex_owner == os_thread_get_curr_id(); } { return lock_mutex_owner == pthread_self(); }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
void lock_mutex_init() { lock_mutex.init(); } void lock_mutex_init() { lock_mutex.init(); }
void lock_mutex_destroy() { lock_mutex.destroy(); } void lock_mutex_destroy() { lock_mutex.destroy(); }
...@@ -1964,20 +1964,20 @@ struct dict_table_t { ...@@ -1964,20 +1964,20 @@ struct dict_table_t {
{ {
ut_ad(!lock_mutex_is_owner()); ut_ad(!lock_mutex_is_owner());
lock_mutex.wr_lock(); lock_mutex.wr_lock();
ut_ad(!lock_mutex_owner.exchange(os_thread_get_curr_id())); ut_ad(!lock_mutex_owner.exchange(pthread_self()));
} }
/** Try to acquire lock_mutex */ /** Try to acquire lock_mutex */
bool lock_mutex_trylock() bool lock_mutex_trylock()
{ {
ut_ad(!lock_mutex_is_owner()); ut_ad(!lock_mutex_is_owner());
bool acquired= lock_mutex.wr_lock_try(); 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(pthread_self()));
return acquired; return acquired;
} }
/** Release lock_mutex */ /** Release lock_mutex */
void lock_mutex_unlock() void lock_mutex_unlock()
{ {
ut_ad(lock_mutex_owner.exchange(0) == os_thread_get_curr_id()); ut_ad(lock_mutex_owner.exchange(0) == pthread_self());
lock_mutex.wr_unlock(); lock_mutex.wr_unlock();
} }
#ifndef SUX_LOCK_GENERIC #ifndef SUX_LOCK_GENERIC
...@@ -2279,7 +2279,7 @@ struct dict_table_t { ...@@ -2279,7 +2279,7 @@ struct dict_table_t {
srw_spin_mutex lock_mutex; srw_spin_mutex lock_mutex;
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/** The owner of lock_mutex (0 if none) */ /** The owner of lock_mutex (0 if none) */
Atomic_relaxed<os_thread_id_t> lock_mutex_owner{0}; Atomic_relaxed<pthread_t> lock_mutex_owner{0};
#endif #endif
public: public:
/** Autoinc counter value to give to the next inserted row. */ /** Autoinc counter value to give to the next inserted row. */
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2012, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2021, MariaDB Corporation. Copyright (c) 2017, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -28,7 +28,6 @@ Created Apr 26, 2012 Vasil Dimov ...@@ -28,7 +28,6 @@ Created Apr 26, 2012 Vasil Dimov
#define dict0stats_bg_h #define dict0stats_bg_h
#include "dict0types.h" #include "dict0types.h"
#include "os0thread.h"
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
extern mysql_pfs_key_t recalc_pool_mutex_key; extern mysql_pfs_key_t recalc_pool_mutex_key;
......
...@@ -412,7 +412,7 @@ struct fil_space_t final ...@@ -412,7 +412,7 @@ struct fil_space_t final
static constexpr uint32_t PENDING= ~(STOPPING | CLOSING | NEEDS_FSYNC); static constexpr uint32_t PENDING= ~(STOPPING | CLOSING | NEEDS_FSYNC);
/** latch protecting all page allocation bitmap pages */ /** latch protecting all page allocation bitmap pages */
srw_lock latch; srw_lock latch;
os_thread_id_t latch_owner; pthread_t latch_owner;
ut_d(Atomic_relaxed<uint32_t> latch_count;) ut_d(Atomic_relaxed<uint32_t> latch_count;)
public: public:
/** MariaDB encryption data */ /** MariaDB encryption data */
...@@ -1040,20 +1040,20 @@ struct fil_space_t final ...@@ -1040,20 +1040,20 @@ struct fil_space_t final
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
bool is_latched() const { return latch_count != 0; } bool is_latched() const { return latch_count != 0; }
#endif #endif
bool is_owner() const { return latch_owner == os_thread_get_curr_id(); } bool is_owner() const { return latch_owner == pthread_self(); }
/** Acquire the allocation latch in exclusive mode */ /** Acquire the allocation latch in exclusive mode */
void x_lock() void x_lock()
{ {
latch.wr_lock(SRW_LOCK_CALL); latch.wr_lock(SRW_LOCK_CALL);
ut_ad(!latch_owner); ut_ad(!latch_owner);
latch_owner= os_thread_get_curr_id(); latch_owner= pthread_self();
ut_ad(!latch_count.fetch_add(1)); ut_ad(!latch_count.fetch_add(1));
} }
/** Release the allocation latch from exclusive mode */ /** Release the allocation latch from exclusive mode */
void x_unlock() void x_unlock()
{ {
ut_ad(latch_count.fetch_sub(1) == 1); ut_ad(latch_count.fetch_sub(1) == 1);
ut_ad(latch_owner == os_thread_get_curr_id()); ut_ad(latch_owner == pthread_self());
latch_owner= 0; latch_owner= 0;
latch.wr_unlock(); latch.wr_unlock();
} }
......
...@@ -687,7 +687,7 @@ class lock_sys_t ...@@ -687,7 +687,7 @@ class lock_sys_t
alignas(CPU_LEVEL1_DCACHE_LINESIZE) srw_spin_lock latch; alignas(CPU_LEVEL1_DCACHE_LINESIZE) srw_spin_lock latch;
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/** The owner of exclusive latch (0 if none); protected by latch */ /** The owner of exclusive latch (0 if none); protected by latch */
std::atomic<os_thread_id_t> writer{0}; std::atomic<pthread_t> writer{0};
/** Number of shared latches */ /** Number of shared latches */
std::atomic<ulint> readers{0}; std::atomic<ulint> readers{0};
#endif #endif
...@@ -751,14 +751,14 @@ class lock_sys_t ...@@ -751,14 +751,14 @@ class lock_sys_t
mysql_mutex_assert_not_owner(&wait_mutex); mysql_mutex_assert_not_owner(&wait_mutex);
ut_ad(!is_writer()); ut_ad(!is_writer());
latch.wr_lock(); latch.wr_lock();
ut_ad(!writer.exchange(os_thread_get_curr_id(), ut_ad(!writer.exchange(pthread_self(),
std::memory_order_relaxed)); std::memory_order_relaxed));
} }
/** Release exclusive lock_sys.latch */ /** Release exclusive lock_sys.latch */
void wr_unlock() void wr_unlock()
{ {
ut_ad(writer.exchange(0, std::memory_order_relaxed) == ut_ad(writer.exchange(0, std::memory_order_relaxed) ==
os_thread_get_curr_id()); pthread_self());
latch.wr_unlock(); latch.wr_unlock();
} }
/** Acquire shared lock_sys.latch */ /** Acquire shared lock_sys.latch */
...@@ -784,7 +784,7 @@ class lock_sys_t ...@@ -784,7 +784,7 @@ class lock_sys_t
{ {
ut_ad(!is_writer()); ut_ad(!is_writer());
if (!latch.wr_lock_try()) return false; if (!latch.wr_lock_try()) return false;
ut_ad(!writer.exchange(os_thread_get_curr_id(), ut_ad(!writer.exchange(pthread_self(),
std::memory_order_relaxed)); std::memory_order_relaxed));
return true; return true;
} }
...@@ -808,9 +808,9 @@ class lock_sys_t ...@@ -808,9 +808,9 @@ class lock_sys_t
bool is_writer() const bool is_writer() const
{ {
# ifdef SUX_LOCK_GENERIC # ifdef SUX_LOCK_GENERIC
return writer.load(std::memory_order_relaxed) == os_thread_get_curr_id(); return writer.load(std::memory_order_relaxed) == pthread_self();
# else # else
return writer.load(std::memory_order_relaxed) == os_thread_get_curr_id() || return writer.load(std::memory_order_relaxed) == pthread_self() ||
(xtest() && !latch.is_locked_or_waiting()); (xtest() && !latch.is_locked_or_waiting());
# endif # endif
} }
......
/*****************************************************************************
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())
/***************************************************************************** /*****************************************************************************
Copyright (c) 2020, 2021, MariaDB Corporation. Copyright (c) 2020, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -19,7 +19,6 @@ this program; if not, write to the Free Software Foundation, Inc., ...@@ -19,7 +19,6 @@ this program; if not, write to the Free Software Foundation, Inc.,
#pragma once #pragma once
#include "srw_lock.h" #include "srw_lock.h"
#include "my_atomic_wrapper.h" #include "my_atomic_wrapper.h"
#include "os0thread.h"
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
# include <unordered_set> # include <unordered_set>
#endif #endif
...@@ -36,19 +35,19 @@ class sux_lock final ...@@ -36,19 +35,19 @@ class sux_lock final
/** Numbers of U and X locks. Protected by lock. */ /** Numbers of U and X locks. Protected by lock. */
uint32_t recursive; uint32_t recursive;
/** The owner of the U or X lock (0 if none); protected by lock */ /** The owner of the U or X lock (0 if none); protected by lock */
std::atomic<os_thread_id_t> writer; std::atomic<pthread_t> writer;
/** Special writer!=0 value to indicate that the lock is non-recursive /** Special writer!=0 value to indicate that the lock is non-recursive
and will be released by an I/O thread */ and will be released by an I/O thread */
#if defined __linux__ || defined _WIN32 #if defined __linux__ || defined _WIN32
static constexpr os_thread_id_t FOR_IO= os_thread_id_t(~0UL); static constexpr pthread_t FOR_IO= pthread_t(~0UL);
#else #else
# define FOR_IO ((os_thread_id_t) ~0UL) /* it could be a pointer */ # define FOR_IO ((pthread_t) ~0UL) /* it could be a pointer */
#endif #endif
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/** Protects readers */ /** Protects readers */
mutable srw_mutex readers_lock; mutable srw_mutex readers_lock;
/** Threads that hold the lock in shared mode */ /** Threads that hold the lock in shared mode */
std::atomic<std::unordered_multiset<os_thread_id_t>*> readers; std::atomic<std::unordered_multiset<pthread_t>*> readers;
#endif #endif
/** The multiplier in recursive for X locks */ /** The multiplier in recursive for X locks */
...@@ -109,7 +108,7 @@ class sux_lock final ...@@ -109,7 +108,7 @@ class sux_lock final
/** Acquire a recursive lock */ /** Acquire a recursive lock */
template<bool allow_readers> void writer_recurse() template<bool allow_readers> void writer_recurse()
{ {
ut_ad(writer == os_thread_get_curr_id()); ut_ad(writer == pthread_self());
ut_d(auto rec= (recursive / (allow_readers ? RECURSIVE_U : RECURSIVE_X)) & ut_d(auto rec= (recursive / (allow_readers ? RECURSIVE_U : RECURSIVE_X)) &
RECURSIVE_MAX); RECURSIVE_MAX);
ut_ad(allow_readers ? recursive : rec); ut_ad(allow_readers ? recursive : rec);
...@@ -120,14 +119,14 @@ class sux_lock final ...@@ -120,14 +119,14 @@ class sux_lock final
private: private:
/** Transfer the ownership of a write lock to another thread /** Transfer the ownership of a write lock to another thread
@param id the new owner of the U or X lock */ @param id the new owner of the U or X lock */
void set_new_owner(os_thread_id_t id) void set_new_owner(pthread_t id)
{ {
IF_DBUG(DBUG_ASSERT(writer.exchange(id, std::memory_order_relaxed)), IF_DBUG(DBUG_ASSERT(writer.exchange(id, std::memory_order_relaxed)),
writer.store(id, std::memory_order_relaxed)); writer.store(id, std::memory_order_relaxed));
} }
/** Assign the ownership of a write lock to a thread /** Assign the ownership of a write lock to a thread
@param id the owner of the U or X lock */ @param id the owner of the U or X lock */
void set_first_owner(os_thread_id_t id) void set_first_owner(pthread_t id)
{ {
IF_DBUG(DBUG_ASSERT(!writer.exchange(id, std::memory_order_relaxed)), IF_DBUG(DBUG_ASSERT(!writer.exchange(id, std::memory_order_relaxed)),
writer.store(id, std::memory_order_relaxed)); writer.store(id, std::memory_order_relaxed));
...@@ -136,12 +135,12 @@ class sux_lock final ...@@ -136,12 +135,12 @@ class sux_lock final
/** Register the current thread as a holder of a shared lock */ /** Register the current thread as a holder of a shared lock */
void s_lock_register() void s_lock_register()
{ {
const os_thread_id_t id= os_thread_get_curr_id(); const pthread_t id= pthread_self();
readers_lock.wr_lock(); readers_lock.wr_lock();
auto r= readers.load(std::memory_order_relaxed); auto r= readers.load(std::memory_order_relaxed);
if (!r) if (!r)
{ {
r= new std::unordered_multiset<os_thread_id_t>(); r= new std::unordered_multiset<pthread_t>();
readers.store(r, std::memory_order_relaxed); readers.store(r, std::memory_order_relaxed);
} }
r->emplace(id); r->emplace(id);
...@@ -152,12 +151,12 @@ class sux_lock final ...@@ -152,12 +151,12 @@ class sux_lock final
public: public:
/** In crash recovery or the change buffer, claim the ownership /** In crash recovery or the change buffer, claim the ownership
of the exclusive block lock to the current thread */ 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(pthread_self()); }
/** @return whether the current thread is holding X or U latch */ /** @return whether the current thread is holding X or U latch */
bool have_u_or_x() const bool have_u_or_x() const
{ {
if (os_thread_get_curr_id() != writer.load(std::memory_order_relaxed)) if (pthread_self() != writer.load(std::memory_order_relaxed))
return false; return false;
ut_ad(recursive); ut_ad(recursive);
return true; return true;
...@@ -175,7 +174,7 @@ class sux_lock final ...@@ -175,7 +174,7 @@ class sux_lock final
if (auto r= readers.load(std::memory_order_relaxed)) if (auto r= readers.load(std::memory_order_relaxed))
{ {
readers_lock.wr_lock(); readers_lock.wr_lock();
bool found= r->find(os_thread_get_curr_id()) != r->end(); bool found= r->find(pthread_self()) != r->end();
readers_lock.wr_unlock(); readers_lock.wr_unlock();
return found; return found;
} }
...@@ -233,7 +232,7 @@ class sux_lock final ...@@ -233,7 +232,7 @@ class sux_lock final
void s_unlock() void s_unlock()
{ {
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
const os_thread_id_t id= os_thread_get_curr_id(); const pthread_t id= pthread_self();
auto r= readers.load(std::memory_order_relaxed); auto r= readers.load(std::memory_order_relaxed);
ut_ad(r); ut_ad(r);
readers_lock.wr_lock(); readers_lock.wr_lock();
...@@ -250,7 +249,7 @@ class sux_lock final ...@@ -250,7 +249,7 @@ class sux_lock final
void u_or_x_unlock(bool allow_readers, bool claim_ownership= false) void u_or_x_unlock(bool allow_readers, bool claim_ownership= false)
{ {
ut_d(auto owner= writer.load(std::memory_order_relaxed)); ut_d(auto owner= writer.load(std::memory_order_relaxed));
ut_ad(owner == os_thread_get_curr_id() || ut_ad(owner == pthread_self() ||
(owner == FOR_IO && claim_ownership && (owner == FOR_IO && claim_ownership &&
recursive == (allow_readers ? RECURSIVE_U : RECURSIVE_X))); recursive == (allow_readers ? RECURSIVE_U : RECURSIVE_X)));
ut_d(auto rec= (recursive / (allow_readers ? RECURSIVE_U : RECURSIVE_X)) & ut_d(auto rec= (recursive / (allow_readers ? RECURSIVE_U : RECURSIVE_X)) &
...@@ -314,7 +313,7 @@ inline void sux_lock<ssux_lock>::s_lock(const char *file, unsigned line) ...@@ -314,7 +313,7 @@ inline void sux_lock<ssux_lock>::s_lock(const char *file, unsigned line)
template<> template<>
inline void sux_lock<ssux_lock>::u_lock(const char *file, unsigned line) inline void sux_lock<ssux_lock>::u_lock(const char *file, unsigned line)
{ {
os_thread_id_t id= os_thread_get_curr_id(); pthread_t id= pthread_self();
if (writer.load(std::memory_order_relaxed) == id) if (writer.load(std::memory_order_relaxed) == id)
writer_recurse<true>(); writer_recurse<true>();
else else
...@@ -329,7 +328,7 @@ inline void sux_lock<ssux_lock>::u_lock(const char *file, unsigned line) ...@@ -329,7 +328,7 @@ inline void sux_lock<ssux_lock>::u_lock(const char *file, unsigned line)
template<> template<>
inline void sux_lock<ssux_lock>::x_lock(const char *file, unsigned line) inline void sux_lock<ssux_lock>::x_lock(const char *file, unsigned line)
{ {
os_thread_id_t id= os_thread_get_curr_id(); pthread_t id= pthread_self();
if (writer.load(std::memory_order_relaxed) == id) if (writer.load(std::memory_order_relaxed) == id)
writer_recurse<false>(); writer_recurse<false>();
else else
...@@ -371,7 +370,7 @@ inline void sux_lock<ssux>::unlock_shared() { s_unlock(); } ...@@ -371,7 +370,7 @@ inline void sux_lock<ssux>::unlock_shared() { s_unlock(); }
template<typename ssux> inline void sux_lock<ssux>::u_lock() template<typename ssux> inline void sux_lock<ssux>::u_lock()
{ {
os_thread_id_t id= os_thread_get_curr_id(); pthread_t id= pthread_self();
if (writer.load(std::memory_order_relaxed) == id) if (writer.load(std::memory_order_relaxed) == id)
writer_recurse<true>(); writer_recurse<true>();
else else
...@@ -385,7 +384,7 @@ template<typename ssux> inline void sux_lock<ssux>::u_lock() ...@@ -385,7 +384,7 @@ template<typename ssux> inline void sux_lock<ssux>::u_lock()
template<typename ssux> inline void sux_lock<ssux>::x_lock(bool for_io) template<typename ssux> inline void sux_lock<ssux>::x_lock(bool for_io)
{ {
os_thread_id_t id= os_thread_get_curr_id(); pthread_t id= pthread_self();
if (writer.load(std::memory_order_relaxed) == id) if (writer.load(std::memory_order_relaxed) == id)
{ {
ut_ad(!for_io); ut_ad(!for_io);
...@@ -409,7 +408,7 @@ template<typename ssux> inline void sux_lock<ssux>::u_x_upgrade() ...@@ -409,7 +408,7 @@ template<typename ssux> inline void sux_lock<ssux>::u_x_upgrade()
template<typename ssux> inline bool sux_lock<ssux>::x_lock_upgraded() template<typename ssux> inline bool sux_lock<ssux>::x_lock_upgraded()
{ {
os_thread_id_t id= os_thread_get_curr_id(); pthread_t id= pthread_self();
if (writer.load(std::memory_order_relaxed) == id) if (writer.load(std::memory_order_relaxed) == id)
{ {
ut_ad(recursive); ut_ad(recursive);
...@@ -436,7 +435,7 @@ template<typename ssux> inline bool sux_lock<ssux>::x_lock_upgraded() ...@@ -436,7 +435,7 @@ template<typename ssux> inline bool sux_lock<ssux>::x_lock_upgraded()
template<typename ssux> inline bool sux_lock<ssux>::u_lock_try(bool for_io) template<typename ssux> inline bool sux_lock<ssux>::u_lock_try(bool for_io)
{ {
os_thread_id_t id= os_thread_get_curr_id(); pthread_t id= pthread_self();
if (writer.load(std::memory_order_relaxed) == id) if (writer.load(std::memory_order_relaxed) == id)
{ {
if (for_io) if (for_io)
...@@ -456,7 +455,7 @@ template<typename ssux> inline bool sux_lock<ssux>::u_lock_try(bool for_io) ...@@ -456,7 +455,7 @@ template<typename ssux> inline bool sux_lock<ssux>::u_lock_try(bool for_io)
template<typename ssux> inline bool sux_lock<ssux>::x_lock_try() template<typename ssux> inline bool sux_lock<ssux>::x_lock_try()
{ {
os_thread_id_t id= os_thread_get_curr_id(); pthread_t id= pthread_self();
if (writer.load(std::memory_order_relaxed) == id) if (writer.load(std::memory_order_relaxed) == id)
{ {
writer_recurse<false>(); writer_recurse<false>();
......
...@@ -522,7 +522,7 @@ no longer be associated with a session when the server is restarted. ...@@ -522,7 +522,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 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. 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 pthread_self() assertions in the code.
Normally, only the thread that is currently associated with a running Normally, only the thread that is currently associated with a running
transaction may access (read and modify) the trx object, and it may do transaction may access (read and modify) the trx object, and it may do
...@@ -601,7 +601,7 @@ struct trx_t : ilist_node<> ...@@ -601,7 +601,7 @@ struct trx_t : ilist_node<>
srw_spin_mutex mutex; srw_spin_mutex mutex;
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/** The owner of mutex (0 if none); protected by mutex */ /** The owner of mutex (0 if none); protected by mutex */
std::atomic<os_thread_id_t> mutex_owner{0}; std::atomic<pthread_t> mutex_owner{0};
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
public: public:
void mutex_init() { mutex.init(); } void mutex_init() { mutex.init(); }
...@@ -612,14 +612,14 @@ struct trx_t : ilist_node<> ...@@ -612,14 +612,14 @@ struct trx_t : ilist_node<>
{ {
ut_ad(!mutex_is_owner()); ut_ad(!mutex_is_owner());
mutex.wr_lock(); mutex.wr_lock();
ut_ad(!mutex_owner.exchange(os_thread_get_curr_id(), ut_ad(!mutex_owner.exchange(pthread_self(),
std::memory_order_relaxed)); std::memory_order_relaxed));
} }
/** Release the mutex */ /** Release the mutex */
void mutex_unlock() void mutex_unlock()
{ {
ut_ad(mutex_owner.exchange(0, std::memory_order_relaxed) ut_ad(mutex_owner.exchange(0, std::memory_order_relaxed)
== os_thread_get_curr_id()); == pthread_self());
mutex.wr_unlock(); mutex.wr_unlock();
} }
#ifndef SUX_LOCK_GENERIC #ifndef SUX_LOCK_GENERIC
...@@ -630,7 +630,7 @@ struct trx_t : ilist_node<> ...@@ -630,7 +630,7 @@ struct trx_t : ilist_node<>
bool mutex_is_owner() const bool mutex_is_owner() const
{ {
return mutex_owner.load(std::memory_order_relaxed) == return mutex_owner.load(std::memory_order_relaxed) ==
os_thread_get_curr_id(); pthread_self();
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
......
...@@ -28,7 +28,7 @@ Created 2012/04/12 by Sunny Bains ...@@ -28,7 +28,7 @@ Created 2012/04/12 by Sunny Bains
#ifndef ut0counter_h #ifndef ut0counter_h
#define ut0counter_h #define ut0counter_h
#include "os0thread.h" #include "univ.i"
#include "my_rdtsc.h" #include "my_rdtsc.h"
/** Use the result of my_timer_cycles(), which mainly uses RDTSC for cycles /** Use the result of my_timer_cycles(), which mainly uses RDTSC for cycles
...@@ -46,7 +46,7 @@ get_rnd_value() ...@@ -46,7 +46,7 @@ get_rnd_value()
/* We may go here if my_timer_cycles() returns 0, /* We may go here if my_timer_cycles() returns 0,
so we have to have the plan B for the counter. */ so we have to have the plan B for the counter. */
#if !defined(_WIN32) #if !defined(_WIN32)
return (size_t)os_thread_get_curr_id(); return (size_t)pthread_self();
#else #else
LARGE_INTEGER cnt; LARGE_INTEGER cnt;
QueryPerformanceCounter(&cnt); QueryPerformanceCounter(&cnt);
......
...@@ -418,13 +418,13 @@ void lock_sys_t::wr_lock(const char *file, unsigned line) ...@@ -418,13 +418,13 @@ void lock_sys_t::wr_lock(const char *file, unsigned line)
{ {
mysql_mutex_assert_not_owner(&wait_mutex); mysql_mutex_assert_not_owner(&wait_mutex);
latch.wr_lock(file, line); latch.wr_lock(file, line);
ut_ad(!writer.exchange(os_thread_get_curr_id(), std::memory_order_relaxed)); ut_ad(!writer.exchange(pthread_self(), std::memory_order_relaxed));
} }
/** Release exclusive lock_sys.latch */ /** Release exclusive lock_sys.latch */
void lock_sys_t::wr_unlock() void lock_sys_t::wr_unlock()
{ {
ut_ad(writer.exchange(0, std::memory_order_relaxed) == ut_ad(writer.exchange(0, std::memory_order_relaxed) ==
os_thread_get_curr_id()); pthread_self());
latch.wr_unlock(); latch.wr_unlock();
} }
......
...@@ -50,7 +50,6 @@ Created 10/21/1995 Heikki Tuuri ...@@ -50,7 +50,6 @@ Created 10/21/1995 Heikki Tuuri
#ifdef HAVE_LINUX_UNISTD_H #ifdef HAVE_LINUX_UNISTD_H
#include "unistd.h" #include "unistd.h"
#endif #endif
#include "os0thread.h"
#include "buf0dblwr.h" #include "buf0dblwr.h"
#include <tpool_structs.h> #include <tpool_structs.h>
......
/*****************************************************************************
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"
...@@ -485,7 +485,7 @@ priority of the background thread so that it will be scheduled and it ...@@ -485,7 +485,7 @@ priority of the background thread so that it will be scheduled and it
can release the resource. This solution is called priority inheritance can release the resource. This solution is called priority inheritance
in real-time programming. A drawback of this solution is that the overhead in real-time programming. A drawback of this solution is that the overhead
of acquiring a mutex increases slightly, maybe 0.2 microseconds on a 100 of acquiring a mutex increases slightly, maybe 0.2 microseconds on a 100
MHz Pentium, because the thread has to call os_thread_get_curr_id. This may MHz Pentium, because the thread has to call pthread_self. This may
be compared to 0.5 microsecond overhead for a mutex lock-unlock pair. Note be compared to 0.5 microsecond overhead for a mutex lock-unlock pair. Note
that the thread cannot store the information in the resource , say mutex, that the thread cannot store the information in the resource , say mutex,
itself, because competing threads could wipe out the information if it is itself, because competing threads could wipe out the information if it is
......
...@@ -55,7 +55,6 @@ Created 2/16/1996 Heikki Tuuri ...@@ -55,7 +55,6 @@ Created 2/16/1996 Heikki Tuuri
#include "buf0dblwr.h" #include "buf0dblwr.h"
#include "buf0dump.h" #include "buf0dump.h"
#include "os0file.h" #include "os0file.h"
#include "os0thread.h"
#include "fil0fil.h" #include "fil0fil.h"
#include "fil0crypt.h" #include "fil0crypt.h"
#include "fsp0fsp.h" #include "fsp0fsp.h"
......
...@@ -29,7 +29,6 @@ Created 3/26/1996 Heikki Tuuri ...@@ -29,7 +29,6 @@ Created 3/26/1996 Heikki Tuuri
#include "fut0fut.h" #include "fut0fut.h"
#include "mach0data.h" #include "mach0data.h"
#include "mtr0log.h" #include "mtr0log.h"
#include "os0thread.h"
#include "que0que.h" #include "que0que.h"
#include "row0purge.h" #include "row0purge.h"
#include "row0upd.h" #include "row0upd.h"
...@@ -1093,7 +1092,7 @@ trx_purge_fetch_next_rec( ...@@ -1093,7 +1092,7 @@ trx_purge_fetch_next_rec(
} }
/* fprintf(stderr, "Thread %lu purging trx %llu undo record %llu\n", /* fprintf(stderr, "Thread %lu purging trx %llu undo record %llu\n",
os_thread_get_curr_id(), iter->trx_no, iter->undo_no); */ pthread_self(), iter->trx_no, iter->undo_no); */
*roll_ptr = trx_undo_build_roll_ptr( *roll_ptr = trx_undo_build_roll_ptr(
/* row_purge_record_func() will later set /* row_purge_record_func() will later set
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1994, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1994, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2021, MariaDB Corporation. Copyright (c) 2017, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -32,7 +32,6 @@ Created 5/11/1994 Heikki Tuuri ...@@ -32,7 +32,6 @@ Created 5/11/1994 Heikki Tuuri
#ifndef UNIV_INNOCHECKSUM #ifndef UNIV_INNOCHECKSUM
#include <mysql_com.h> #include <mysql_com.h>
#include "os0thread.h"
#include "ut0ut.h" #include "ut0ut.h"
#include "trx0trx.h" #include "trx0trx.h"
#include <string> #include <string>
...@@ -92,7 +91,7 @@ ut_print_timestamp( ...@@ -92,7 +91,7 @@ ut_print_timestamp(
#ifdef UNIV_INNOCHECKSUM #ifdef UNIV_INNOCHECKSUM
ulint{0} ulint{0}
#else #else
ulint(os_thread_get_curr_id()) ulint(pthread_self())
#endif #endif
); );
} }
......
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