MySQL 8.4.2
Source Code Documentation
os0thread-create.h File Reference

The interface to the threading wrapper. More...

#include <my_thread.h>
#include "univ.i"
#include "os0thread.h"
#include "sql_thd_internal_api.h"
#include <atomic>
#include <functional>

Go to the source code of this file.

Classes

class  MySQL_thread
 Register with MySQL infrastructure. More...
 
class  Runnable
 Execute in the context of a non detached MySQL thread. More...
 
class  Detached_thread
 Wrapper for a callable, it will count the number of registered Runnable instances and will register the thread executing the callable with the PFS and the Server threading infrastructure. More...
 

Macros

#define os_thread_create(...)   create_detached_thread(__VA_ARGS__)
 
#define par_for(...)   par_for(__VA_ARGS__)
 

Functions

void os_thread_open ()
 Initializes OS thread management data structures. More...
 
bool os_thread_any_active ()
 Check if there are threads active. More...
 
void os_thread_close ()
 Frees OS thread management data structures. More...
 
bool thread_is_stopped (const IB_thread &thread)
 Check if thread is stopped. More...
 
bool thread_is_active (const IB_thread &thread)
 Check if thread is active. More...
 
template<typename F , typename... Args>
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. More...
 
template<typename Container , typename F , typename... Args>
void par_for (mysql_pfs_key_t pfs_key, const Container &c, size_t n, F &&f, Args &&... args)
 Parallel for loop over a container. More...
 

Variables

uint32_t srv_max_n_threads
 Maximum number of threads inside InnoDB. More...
 
std::atomic_int os_thread_count
 Number of threads active. More...
 

Detailed Description

The interface to the threading wrapper.

Created 2016-May-17 Sunny Bains

Macro Definition Documentation

◆ os_thread_create

#define os_thread_create (   ...)    create_detached_thread(__VA_ARGS__)

◆ par_for

#define par_for (   ...)    par_for(__VA_ARGS__)

Function Documentation

◆ create_detached_thread()

template<typename F , typename... Args>
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.

After thread is created, you should assign the received object to any of variables/fields which you later could access to check thread's state. You are allowed to either move or copy that object (any number of copies is allowed). After assigning you are allowed to start the thread by calling start() on any of those objects.

Parameters
[in]pfs_keyPerformance schema thread key
[in]pfs_seqnumPerformance schema thread sequence number
[in]fCallable instance
[in]argsZero or more args
Returns
Object which allows to start the created thread, monitor its state and wait until the thread is finished.

◆ os_thread_any_active()

bool os_thread_any_active ( )
inline

Check if there are threads active.

Returns
true if the thread count > 0.

◆ os_thread_close()

void os_thread_close ( )
inline

Frees OS thread management data structures.

◆ os_thread_open()

void os_thread_open ( )
inline

Initializes OS thread management data structures.

◆ par_for()

template<typename Container , typename F , typename... Args>
void par_for ( mysql_pfs_key_t  pfs_key,
const Container &  c,
size_t  n,
F &&  f,
Args &&...  args 
)

Parallel for loop over a container.

Parameters
[in]pfs_keyPerformance schema thread key
[in]cContainer to iterate over in parallel
[in]nNumber of threads to create
[in]fCallable instance
[in]argsZero or more args

◆ thread_is_active()

bool thread_is_active ( const IB_thread thread)
inline

Check if thread is active.

Parameters
[in]threadThread handle.
Returns
true if the thread is active.

◆ thread_is_stopped()

bool thread_is_stopped ( const IB_thread thread)
inline

Check if thread is stopped.

Parameters
[in]threadThread handle.
Returns
true if the thread has started, finished tasks and stopped.

Variable Documentation

◆ os_thread_count

std::atomic_int os_thread_count
extern

Number of threads active.

◆ srv_max_n_threads

uint32_t srv_max_n_threads
extern

Maximum number of threads inside InnoDB.

Maximum number of threads inside InnoDB.

innodb_init_params() sets the value.