34#ifndef os0thread_create_h
35#define os0thread_create_h
51#include <sanitizer/asan_interface.h>
99#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
114#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
123#ifdef UNIV_PFS_THREAD
135#ifdef UNIV_PFS_THREAD
166 if (
m_thd !=
nullptr) {
177 template <
typename F,
typename... Args>
179 return std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
188 if (thd ==
nullptr) {
194 if (caller_thd !=
nullptr) {
196 ASAN_POISON_MEMORY_REGION((
void *)&thd->variables,
197 sizeof(thd->variables));
198 ASAN_UNPOISON_MEMORY_REGION((
void *)&thd->variables.sql_mode,
199 sizeof(thd->variables.sql_mode));
201 thd->variables.sql_mode = caller_thd->variables.sql_mode;
213 ASAN_UNPOISON_MEMORY_REGION((
void *)&thd->variables,
214 sizeof(thd->variables));
242 template <
typename F,
typename... Args>
254 std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
273 std::atomic_thread_fence(std::memory_order_release);
284 std::atomic_thread_fence(std::memory_order_release);
313 switch (thread.
state()) {
362template <
typename F,
typename... Args>
367 auto thread = detached_thread.thread();
369 std::thread t(std::move(detached_thread), f, args...);
380#ifdef UNIV_PFS_THREAD
381#define os_thread_create(...) create_detached_thread(__VA_ARGS__)
383#define os_thread_create(k, s, ...) create_detached_thread(0, 0, __VA_ARGS__)
392template <
typename Container,
typename F,
typename... Args>
399 size_t slice = (
n > 0) ? c.size() /
n : 0;
401 using Workers = std::vector<IB_thread>;
407 for (
size_t i = 0; i <
n; ++i) {
408 auto b = c.begin() + (i * slice);
414 workers.push_back(std::move(worker));
417 f(c.begin() + (
n * slice), c.end(),
n, args...);
419 for (
auto &worker : workers) {
424#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
425#define par_for(...) par_for(__VA_ARGS__)
427#define par_for(k, ...) par_for(0, __VA_ARGS__)
Wrapper for a callable, it will count the number of registered Runnable instances and will register t...
Definition: os0thread-create.h:228
void operator()(F &&f, Args &&...args)
Method to execute the callable.
Definition: os0thread-create.h:243
void init()
Initializes the m_shared_future, uses the m_promise's get_future, which cannot be used since then,...
Definition: os0thread-create.h:267
std::promise< void > m_promise
Promise which is set when task is done.
Definition: os0thread-create.h:299
Detached_thread(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the detached thread.
Definition: os0thread-create.h:233
void preamble()
Register the thread with the server.
Definition: os0thread-create.h:270
IB_thread m_thread
Future object which keeps the ref counter >= 1 at least as long as the Detached_thread is not-destroy...
Definition: os0thread-create.h:296
IB_thread thread() const
Definition: os0thread-create.h:262
void epilogue()
Deregister the thread.
Definition: os0thread-create.h:281
Definition: os0thread.h:47
void set_state(State state)
Definition: os0thread.cc:103
void init(std::promise< void > &promise)
Definition: os0thread.cc:98
State state() const
Definition: os0thread.h:51
Register with MySQL infrastructure.
Definition: os0thread-create.h:78
void epilogue()
Deregister the thread.
Definition: os0thread-create.h:111
MySQL_thread(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the Runnable object.
Definition: os0thread-create.h:84
PSI_thread_seqnum m_pfs_seqnum
Performance schema sequence number.
Definition: os0thread-create.h:140
THD * create_mysql_thd() noexcept
Definition: os0thread-create.h:122
const mysql_pfs_key_t m_pfs_key
Performance schema key.
Definition: os0thread-create.h:137
void destroy_mysql_thd(THD *thd) noexcept
Destroy a THD instance.
Definition: os0thread-create.h:132
void preamble()
Register the thread with the server.
Definition: os0thread-create.h:95
Execute in the context of a non detached MySQL thread.
Definition: os0thread-create.h:145
THD * create_current_thd(const THD *caller_thd) noexcept
Create and configure the THD used by this DDL worker invocation.
Definition: os0thread-create.h:184
~Runnable() noexcept
Destroy the current THD and deregister the MySQL thread.
Definition: os0thread-create.h:165
THD * m_thd
Definition: os0thread-create.h:222
void destroy_current_thd(THD *thd) noexcept
Destroy a THD created by create_current_thd().
Definition: os0thread-create.h:209
dberr_t operator()(F &&f, Args &&...args)
Method to execute the callable.
Definition: os0thread-create.h:178
Runnable(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the Runnable object.
Definition: os0thread-create.h:150
dberr_t setup_thd(const THD *caller_thd=nullptr) noexcept
Create and configure the current THD for this Runnable.
Definition: os0thread-create.h:157
static void clone_from(const THD *thd) noexcept
Clone sync points from another THD to the current THD.
Definition: sync0debug.cc:1763
static void erase(const THD *thd, const std::string &target) noexcept
Clear the named target.
Definition: sync0debug.cc:1788
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
The class warn is used to emit warnings.
Definition: ut0log.h:204
#define PSI_THREAD_CALL(M)
Definition: psi_thread.h:36
thread_local THD * current_thd
Definition: current_thd.cc:26
dberr_t
Definition: db0err.h:39
@ DB_OUT_OF_MEMORY
Definition: db0err.h:49
@ DB_SUCCESS
Definition: db0err.h:43
unsigned int PSI_thread_seqnum
Instrumented thread sequence number.
Definition: psi_thread_bits.h:59
#define F
Definition: jit_executor_value.cc:374
Defines to make different thread packages compatible.
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
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
void os_thread_open()
Initializes OS thread management data structures.
Definition: os0thread-create.h:61
std::atomic_int os_thread_count
Number of threads active.
Definition: os0thread.cc:56
IB_thread create_detached_thread(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum, F &&f, Args &&...args)
Create a detached non-started thread.
Definition: os0thread-create.h:363
#define os_thread_create(...)
Definition: os0thread-create.h:381
bool thread_is_active(const IB_thread &thread)
Check if thread is active.
Definition: os0thread-create.h:312
#define par_for(...)
Definition: os0thread-create.h:425
bool os_thread_any_active()
Check if there are threads active.
Definition: os0thread-create.h:66
void os_thread_close()
Frees OS thread management data structures.
Definition: os0thread-create.h:71
uint32_t srv_max_n_threads
Maximum number of threads inside InnoDB.
Definition: os0thread.cc:53
bool thread_is_stopped(const IB_thread &thread)
Check if thread is stopped.
Definition: os0thread-create.h:305
The interface to the operating system process and thread control primitives.
void destroy_thd(THD *thd, bool clear_pfs_events)
Cleanup the THD object, remove it from the global list of THDs and delete it.
Definition: sql_thd_internal_api.cc:169
Define for performance schema registration key.
Definition: sync0sync.h:51
unsigned int m_value
Definition: sync0sync.h:64
Debug checks for latches, header file.
mysql_pfs_key_t PFS_NOT_INSTRUMENTED
THD * create_thd(Channel_info *channel_info)
Definition: connection_handler_manager.cc:277
Version control for database, common definitions, and include files.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_ad_eq(LHS, RHS)
Debug-only assertion that LHS == RHS.
Definition: ut0dbg.h:119
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:111
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
Base of InnoDB utilities.
#define UT_RELAX_CPU()
Definition: ut0ut.h:90
int n
Definition: xcom_base.cc:509