MySQL 26.7.0
Source Code Documentation
thread_srv_impl.hpp
Go to the documentation of this file.
1// Copyright (c) 2026, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
25
26namespace mysql::concurrency {
27
28namespace detail {
29
30using Func_t = std::function<void(void)>;
31
32/// @brief Function launching the thread function and matching interface of the
33/// my_start_routine
34inline static void *launch_handler_thread(void *arg) {
35 auto *func = reinterpret_cast<Func_t *>(arg);
37 (*func)();
39 delete func;
40 return nullptr;
41}
42
43} // namespace detail
44
45template <class Callable, class... Args>
46Thread::Thread(Thread_key thread_key, Callable &&run_func, Args &&...args) {
49 // launch_handler_thread becomes the owner of func_p, it will
50 // delete it
51 auto *func_p = new detail::Func_t(
52 std::bind(std::move(run_func), std::forward<Args>(args)...));
56 if (m_creation_error_code != 0) {
57 delete func_p;
58 }
59}
60
61template <class Callable, class... Args>
62Thread::Thread(Callable &&run_func, Args &&...args) {
65 // launch_handler_thread becomes the owner of func_p, it will
66 // delete it
67 auto *func_p = new detail::Func_t(
68 std::bind(std::move(run_func), std::forward<Args>(args)...));
72 if (m_creation_error_code != 0) {
73 delete func_p;
74 }
75}
76
77} // namespace mysql::concurrency
int m_creation_error_code
Thread creation error code.
Definition: thread_srv.h:86
Thread_key m_thread_key
Thread key.
Definition: thread_srv.h:84
my_thread_handle m_thread_handle
Mysql thread handle.
Definition: thread_srv.h:80
my_thread_attr_t m_thread_attr
Thread attributes.
Definition: thread_srv.h:82
#define mysql_thread_create(K, P1, P2, P3, P4)
Instrumented my_thread_create.
Definition: mysql_thread.h:90
static int my_thread_attr_setdetachstate(my_thread_attr_t *attr, int detachstate)
Definition: my_thread.h:123
#define MY_THREAD_CREATE_JOINABLE
Definition: my_thread.h:70
bool my_thread_init()
Allocate thread specific memory for the thread, used by mysys and dbug.
Definition: my_thr_init.cc:264
void my_thread_end()
Deallocate memory used by the thread for book-keeping.
Definition: my_thr_init.cc:315
static int my_thread_attr_init(my_thread_attr_t *attr)
Definition: my_thread.h:91
Definition: packet_based_table_with_cursor.h:36
static void * launch_handler_thread(void *arg)
Function launching the thread function and matching interface of the my_start_routine.
Definition: thread_srv_impl.hpp:34
std::function< void(void)> Func_t
Definition: thread_srv_impl.hpp:30
Definition: cache_line_size.h:31
PSI_thread_key Thread_key
Definition: thread_srv.h:43
stdx::expected< void, error_type > bind(native_handle_type native_handle, const struct sockaddr *addr, size_t addr_len)
wrap bind() in a portable way.
Definition: socket.h:339