34#ifndef os0thread_create_h
35#define os0thread_create_h
92#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
107#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
116#ifdef UNIV_PFS_THREAD
128#ifdef UNIV_PFS_THREAD
150 template <
typename F,
typename... Args>
154 auto r = std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
179 template <
typename F,
typename... Args>
191 std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
210 std::atomic_thread_fence(std::memory_order_release);
221 std::atomic_thread_fence(std::memory_order_release);
250 switch (thread.
state()) {
299template <
typename F,
typename... Args>
304 auto thread = detached_thread.thread();
306 std::thread t(std::move(detached_thread), f, args...);
317#ifdef UNIV_PFS_THREAD
318#define os_thread_create(...) create_detached_thread(__VA_ARGS__)
320#define os_thread_create(k, s, ...) create_detached_thread(0, 0, __VA_ARGS__)
329template <
typename Container,
typename F,
typename... Args>
336 size_t slice = (
n > 0) ? c.size() /
n : 0;
338 using Workers = std::vector<IB_thread>;
344 for (
size_t i = 0; i <
n; ++i) {
345 auto b = c.begin() + (i * slice);
351 workers.push_back(std::move(worker));
354 f(c.begin() + (
n * slice), c.end(),
n, args...);
356 for (
auto &worker : workers) {
361#if defined(UNIV_PFS_THREAD) && !defined(UNIV_HOTBACKUP)
362#define par_for(...) par_for(__VA_ARGS__)
364#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:165
void operator()(F &&f, Args &&...args)
Method to execute the callable.
Definition: os0thread-create.h:180
void init()
Initializes the m_shared_future, uses the m_promise's get_future, which cannot be used since then,...
Definition: os0thread-create.h:204
std::promise< void > m_promise
Promise which is set when task is done.
Definition: os0thread-create.h:236
Detached_thread(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the detached thread.
Definition: os0thread-create.h:170
void preamble()
Register the thread with the server.
Definition: os0thread-create.h:207
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:233
IB_thread thread() const
Definition: os0thread-create.h:199
void epilogue()
Deregister the thread.
Definition: os0thread-create.h:218
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:71
void epilogue()
Deregister the thread.
Definition: os0thread-create.h:104
MySQL_thread(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the Runnable object.
Definition: os0thread-create.h:77
PSI_thread_seqnum m_pfs_seqnum
Performance schema sequence number.
Definition: os0thread-create.h:133
THD * create_mysql_thd() noexcept
Definition: os0thread-create.h:115
const mysql_pfs_key_t m_pfs_key
Performance schema key.
Definition: os0thread-create.h:130
void destroy_mysql_thd(THD *thd) noexcept
Destroy a THD instance.
Definition: os0thread-create.h:125
void preamble()
Register the thread with the server.
Definition: os0thread-create.h:88
Execute in the context of a non detached MySQL thread.
Definition: os0thread-create.h:138
dberr_t operator()(F &&f, Args &&...args)
Method to execute the callable.
Definition: os0thread-create.h:151
Runnable(mysql_pfs_key_t pfs_key, PSI_thread_seqnum pfs_seqnum)
Constructor for the Runnable object.
Definition: os0thread-create.h:143
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
dberr_t
Definition: db0err.h:39
unsigned int PSI_thread_seqnum
Instrumented thread sequence number.
Definition: psi_thread_bits.h:59
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:263
void my_thread_end()
Deallocate memory used by the thread for book-keeping.
Definition: my_thr_init.cc:312
void os_thread_open()
Initializes OS thread management data structures.
Definition: os0thread-create.h:54
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:300
#define os_thread_create(...)
Definition: os0thread-create.h:318
bool thread_is_active(const IB_thread &thread)
Check if thread is active.
Definition: os0thread-create.h:249
#define par_for(...)
Definition: os0thread-create.h:362
bool os_thread_any_active()
Check if there are threads active.
Definition: os0thread-create.h:59
void os_thread_close()
Frees OS thread management data structures.
Definition: os0thread-create.h:64
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:242
The interface to the operating system process and thread control primitives.
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
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
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_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
#define UT_RELAX_CPU()
Definition: ut0ut.h:93
int n
Definition: xcom_base.cc:509