34#ifndef os0thread_create_h
35#define os0thread_create_h
50#include <sanitizer/asan_interface.h>
98#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
113#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
122#ifdef UNIV_PFS_THREAD
134#ifdef UNIV_PFS_THREAD
165 if (
m_thd !=
nullptr) {
176 template <
typename F,
typename... Args>
178 return std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
187 if (thd ==
nullptr) {
193 if (caller_thd !=
nullptr) {
195 ASAN_POISON_MEMORY_REGION((
void *)&thd->variables,
196 sizeof(thd->variables));
197 ASAN_UNPOISON_MEMORY_REGION((
void *)&thd->variables.sql_mode,
198 sizeof(thd->variables.sql_mode));
200 thd->variables.sql_mode = caller_thd->variables.sql_mode;
212 ASAN_UNPOISON_MEMORY_REGION((
void *)&thd->variables,
213 sizeof(thd->variables));
241 template <
typename F,
typename... Args>
253 std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
272 std::atomic_thread_fence(std::memory_order_release);
283 std::atomic_thread_fence(std::memory_order_release);
312 switch (thread.
state()) {
361template <
typename F,
typename... Args>
366 auto thread = detached_thread.thread();
368 std::thread t(std::move(detached_thread), f, args...);
379#ifdef UNIV_PFS_THREAD
380#define os_thread_create(...) create_detached_thread(__VA_ARGS__)
382#define os_thread_create(k, s, ...) create_detached_thread(0, 0, __VA_ARGS__)
391template <
typename Container,
typename F,
typename... Args>
398 size_t slice = (
n > 0) ? c.size() /
n : 0;
400 using Workers = std::vector<IB_thread>;
406 for (
size_t i = 0; i <
n; ++i) {
407 auto b = c.begin() + (i * slice);
413 workers.push_back(std::move(worker));
416 f(c.begin() + (
n * slice), c.end(),
n, args...);
418 for (
auto &worker : workers) {
423#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
424#define par_for(...) par_for(__VA_ARGS__)
426#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:227
void operator()(F &&f, Args &&...args)
Method to execute the callable.
Definition: os0thread-create.h:242
void init()
Initializes the m_shared_future, uses the m_promise's get_future, which cannot be used since then,...
Definition: os0thread-create.h:266
std::promise< void > m_promise
Promise which is set when task is done.
Definition: os0thread-create.h:298
Detached_thread(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the detached thread.
Definition: os0thread-create.h:232
void preamble()
Register the thread with the server.
Definition: os0thread-create.h:269
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:295
IB_thread thread() const
Definition: os0thread-create.h:261
void epilogue()
Deregister the thread.
Definition: os0thread-create.h:280
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:77
void epilogue()
Deregister the thread.
Definition: os0thread-create.h:110
MySQL_thread(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the Runnable object.
Definition: os0thread-create.h:83
PSI_thread_seqnum m_pfs_seqnum
Performance schema sequence number.
Definition: os0thread-create.h:139
THD * create_mysql_thd() noexcept
Definition: os0thread-create.h:121
const mysql_pfs_key_t m_pfs_key
Performance schema key.
Definition: os0thread-create.h:136
void destroy_mysql_thd(THD *thd) noexcept
Destroy a THD instance.
Definition: os0thread-create.h:131
void preamble()
Register the thread with the server.
Definition: os0thread-create.h:94
Execute in the context of a non detached MySQL thread.
Definition: os0thread-create.h:144
THD * create_current_thd(const THD *caller_thd) noexcept
Create and configure the THD used by this DDL worker invocation.
Definition: os0thread-create.h:183
~Runnable() noexcept
Destroy the current THD and deregister the MySQL thread.
Definition: os0thread-create.h:164
THD * m_thd
Definition: os0thread-create.h:221
void destroy_current_thd(THD *thd) noexcept
Destroy a THD created by create_current_thd().
Definition: os0thread-create.h:208
dberr_t operator()(F &&f, Args &&...args)
Method to execute the callable.
Definition: os0thread-create.h:177
Runnable(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the Runnable object.
Definition: os0thread-create.h:149
dberr_t setup_thd(const THD *caller_thd=nullptr) noexcept
Create and configure the current THD for this Runnable.
Definition: os0thread-create.h:156
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:210
#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:60
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:362
#define os_thread_create(...)
Definition: os0thread-create.h:380
bool thread_is_active(const IB_thread &thread)
Check if thread is active.
Definition: os0thread-create.h:311
#define par_for(...)
Definition: os0thread-create.h:424
bool os_thread_any_active()
Check if there are threads active.
Definition: os0thread-create.h:65
void os_thread_close()
Frees OS thread management data structures.
Definition: os0thread-create.h:70
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:304
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:271
Version control for database, common definitions, and include files.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_ad_eq(LHS, RHS)
Debug-only assertion that LHS == RHS.
Definition: ut0dbg.h:115
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:107
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
#define UT_RELAX_CPU()
Definition: ut0ut.h:90
int n
Definition: xcom_base.cc:509