MySQL 9.4.0
Source Code Documentation
jit_executor_context_pool.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, 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, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, 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 Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_JIT_EXECUTOR_CONTEXT_POOL_H_
27#define ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_JIT_EXECUTOR_CONTEXT_POOL_H_
28
29#include <atomic>
30#include <condition_variable>
31#include <deque>
32#include <functional>
33#include <memory>
34#include <mutex>
35#include <stdexcept>
36#include <string>
37#include <thread>
38#include <vector>
39
47
48namespace jit_executor {
49
51
52class PooledContextHandle;
53class CommonContext;
54class ContextPool final {
55 public:
56 ContextPool(CommonContext *common_context);
57
59
60 std::shared_ptr<PooledContextHandle> get_context();
61 void teardown();
62
63 private:
64 friend class PooledContextHandle;
65 void release(IContext *ctx);
66 void release_thread();
67
68 void increase_active_items();
69 void decrease_active_items();
70
71 bool can_create();
73 void destroy(IContext *ctx);
74
75 void do_release(IContext *ctx);
76 void discard(IContext *ctx);
77 void do_teardown();
78 IContext *create(size_t id);
79 IContext *get();
80
83 std::unique_ptr<std::thread> m_release_thread;
84
85 std::mutex m_mutex;
86 std::condition_variable m_item_availability;
87 bool m_teardown = false;
88 std::deque<IContext *> m_items;
89 size_t m_active_items = 0;
90 size_t m_created_items = 0;
91
92 std::atomic_bool m_forbid_context_creation = false;
93};
94
95/**
96 * A wrapper that will return a context to the pool as soon as it is released
97 */
99 public:
101 : m_pool{pool}, m_context{ctx} {}
103
104 IContext *get() override { return m_context; }
105
106 private:
109};
110
111} // namespace jit_executor
112
113#endif // ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_JIT_EXECUTOR_CONTEXT_POOL_H_
int destroy(azio_stream *s)
Definition: azio.cc:372
Specialization of the Polyglot_common_context to provide MRS specific logging functions as well as th...
Definition: jit_executor_common_context.h:48
Definition: jit_executor_context_pool.h:54
std::unique_ptr< std::thread > m_release_thread
Definition: jit_executor_context_pool.h:83
void release(IContext *ctx)
Definition: jit_executor_context_pool.cc:70
std::condition_variable m_item_availability
Definition: jit_executor_context_pool.h:86
std::deque< IContext * > m_items
Definition: jit_executor_context_pool.h:88
CommonContext * m_common_context
Definition: jit_executor_context_pool.h:81
mysql_harness::WaitingMPSCQueue< IContext * > m_release_queue
Definition: jit_executor_context_pool.h:82
std::mutex m_mutex
Definition: jit_executor_context_pool.h:85
Base handler for Jit Executor Context instances.
Definition: jit_executor_context_handle.h:36
Definition: jit_executor_context.h:40
A wrapper that will return a context to the pool as soon as it is released.
Definition: jit_executor_context_pool.h:98
IContext * m_context
Definition: jit_executor_context_pool.h:108
IContext * get() override
Definition: jit_executor_context_pool.h:104
~PooledContextHandle() override
Definition: jit_executor_context_pool.h:102
PooledContextHandle(ContextPool *pool, IContext *ctx)
Definition: jit_executor_context_pool.h:100
ContextPool * m_pool
Definition: jit_executor_context_pool.h:107
provide waiting pop and push operator to thread-safe queues.
Definition: waiting_queue_adaptor.h:40
Logging interface for using and extending the logging subsystem.
#define IMPORT_LOG_FUNCTIONS()
convenience macro to avoid common boilerplate
Definition: logging.h:331
Definition: jit_executor_callbacks.h:36
static mysql_service_status_t get(THD **thd) noexcept
Definition: mysql_current_thread_reader_all_empty.cc:31
static mysql_service_status_t create(my_h_string *) noexcept
Definition: mysql_string_all_empty.cc:43