MySQL 8.0.39
Source Code Documentation
mysql_client_thread_token.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_MYSQL_CLIENT_THREAD_TOKEN_INCLUDED
27#define ROUTER_MYSQL_CLIENT_THREAD_TOKEN_INCLUDED
28
29#include <stdexcept>
30
31#include <mysql.h>
32
33namespace mysqlrouter {
34
35/**
36 * Thread Token for libmysqlclient API users.
37 *
38 * libmysqlclient requires that all threads that used the API deinit
39 * via mysql_thread_end()
40 *
41 * @note Not calling mysql_thread_end() for a thread which had
42 * mysql_thread_init() called leads to 5 seconds wait on mysql_library_end()
43 * in debug-builds.
44 *
45 * While the first call to to mysql_init() in a thread calls,
46 * mysql_thread_init() automatically, there is no equivalent for the shutdown.
47 *
48 * Placing the thread token on the stack ensures right after the
49 * thread is started ensures, the thread is properly accounted for
50 * by libmysqlclient.
51 *
52 * @code
53 * void *some_thread(void *) {
54 * MySQLClientThreadToken api_token;
55 *
56 * if (true) throw std::runtime_error();
57 *
58 * return nullptr;
59 * }
60 * @endcode
61 *
62 * @see mysql_library_end()
63 * @see mysql_thread_end()
64 * @see my_thread_end()
65 */
67 public:
69
71
72 private:
73 // disable copy constructor
75 // disable copy assignment
77 // disable move constructor
79 // disable move assignment
81};
82
83} // namespace mysqlrouter
84#endif
Thread Token for libmysqlclient API users.
Definition: mysql_client_thread_token.h:66
~MySQLClientThreadToken()
Definition: mysql_client_thread_token.h:70
MySQLClientThreadToken & operator=(MySQLClientThreadToken &&)=delete
MySQLClientThreadToken(MySQLClientThreadToken &&)=delete
MySQLClientThreadToken & operator=(const MySQLClientThreadToken &)=delete
MySQLClientThreadToken(const MySQLClientThreadToken &)=delete
MySQLClientThreadToken()
Definition: mysql_client_thread_token.h:68
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
bool STDCALL mysql_thread_init(void)
Definition: libmysql.cc:212
void STDCALL mysql_thread_end(void)
Definition: libmysql.cc:214
Definition: dim.h:358