summaryrefslogtreecommitdiffstats
path: root/wsrep-lib/dbsim
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:39:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:39:13 +0000
commit86fbb58c3ac0865482819c10a3e81f2eea001c36 (patch)
tree28c9e526ea739c6f9b89e36115e1e2698bddf981 /wsrep-lib/dbsim
parentReleasing progress-linux version 1:10.11.6-2~progress7.99u1. (diff)
downloadmariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.tar.xz
mariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.zip
Merging upstream version 1:10.11.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wsrep-lib/dbsim')
-rw-r--r--wsrep-lib/dbsim/db_threads.cpp52
1 files changed, 25 insertions, 27 deletions
diff --git a/wsrep-lib/dbsim/db_threads.cpp b/wsrep-lib/dbsim/db_threads.cpp
index 10b580dd..409672b1 100644
--- a/wsrep-lib/dbsim/db_threads.cpp
+++ b/wsrep-lib/dbsim/db_threads.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Codership Oy <info@codership.com>
+ * Copyright (C) 2019-2023 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
@@ -113,12 +113,10 @@ namespace
::abort();
}
}
+
static inline int append_key(const char* name, const char* type)
{
-
key_vec.push_back(std::string(name) + "_" + type);
- wsrep::log_info() << "Register key " << name << "_" << type
- << " with index " << (key_cnt + 1);
ops_map.push_back(std::vector<size_t>());
ops_map_sync.push_back(new std::mutex());
ops_map.back().resize(oc_max);
@@ -175,21 +173,6 @@ namespace
void* args;
};
- pthread_key_t this_thread_key;
- struct this_thread_key_initializer
- {
- this_thread_key_initializer()
- {
- pthread_key_create(&this_thread_key, nullptr);
- }
-
- ~this_thread_key_initializer()
- {
- pthread_key_delete(this_thread_key);
- }
- };
-
-
class ti_thread : public ti_obj
{
public:
@@ -229,11 +212,7 @@ namespace
void retval(void* retval) { retval_ = retval; }
- static ti_thread* self()
- {
- return reinterpret_cast<ti_thread*>(
- pthread_getspecific(this_thread_key));
- }
+ static ti_thread* self();
int setschedparam(int policy, const struct sched_param* param)
{
@@ -256,6 +235,25 @@ namespace
bool detached_;
};
+ thread_local ti_thread* this_ti_thread = nullptr;
+
+ static bool main_thread_initializer()
+ {
+ const auto* main_thread_key
+ = reinterpret_cast<const wsrep::thread_service::thread_key*>(
+ append_key("main", "thread"));
+ static ti_thread main_thread(main_thread_key);
+ this_ti_thread = &main_thread;
+ return true;
+ }
+ static bool main_thread_init = main_thread_initializer();
+
+ ti_thread* ti_thread::self()
+ {
+ return this_ti_thread;
+ }
+
+
class ti_mutex : public ti_obj
{
public:
@@ -472,12 +470,12 @@ static void* start_thread(void* args_ptr)
{
thread_args* ta(reinterpret_cast<thread_args*>(args_ptr));
ti_thread* thread = reinterpret_cast<ti_thread*>(ta->this_thread);
- pthread_setspecific(this_thread_key, thread);
+ this_ti_thread = thread;
void* (*fn)(void*) = ta->fn;
void* args = ta->args;
delete ta;
void* ret = (*fn)(args);
- pthread_setspecific(this_thread_key, nullptr);
+ this_ti_thread = nullptr;
// If we end here the thread returned instead of calling
// pthread_exit()
if (thread->detached())
@@ -488,7 +486,7 @@ static void* start_thread(void* args_ptr)
WSREP_NORETURN
static void exit_thread(wsrep::thread_service::thread* thread, void* retval)
{
- pthread_setspecific(this_thread_key, nullptr);
+ this_ti_thread = nullptr;
ti_thread* th(reinterpret_cast<ti_thread*>(thread));
th->retval(retval);
if (th->detached())