MySQL 26.7.0
Source Code Documentation
padded_slot.h
Go to the documentation of this file.
1// Copyright (c) 2026, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is distributed in the hope that it will be useful,
8// but WITHOUT ANY WARRANTY; without even the implied warranty of
9// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10// GNU General Public License, version 2.0, for more details.
11//
12// You should have received a copy of the GNU General Public License
13// along with this program; if not, write to the Free Software
14// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15
16#ifndef MYSQL_CONCURRENCY_PADDED_SLOT
17#define MYSQL_CONCURRENCY_PADDED_SLOT
18
19#include "my_compiler.h" // MY_COMPILER_DIAGNOSTIC_*
21
23
24/// @brief Padded slot for Sync_bounded_queue, aligning the struct to cache line
25/// size to minimize false sharing in concurrent access.
26/// @details Holds an element, validity flag, mutex, and condition variables for
27/// producer-consumer synchronization. Each slot is padded to prevent adjacent
28/// slots from sharing cache lines, reducing contention in multi-threaded
29/// environments.
30/// @tparam T Element type.
31/// @tparam Mutex_tp Mutex type
32/// @tparam Cv_tp Condition variable type
33/// @tparam cache_line_size_tp Padding size (default:
34/// hardware_destructive_interference_size).
35/// @see Sync_bounded_queue
36template <typename T, typename Mutex_tp, typename Cv_tp,
37 size_t cache_line_size_tp = hardware_destructive_interference_size>
38struct alignas(cache_line_size_tp) Padded_slot {
39 /// The stored element in the queue slot.
40 T element{};
41 /// Validity flag: true if the slot contains an element ready for consumption,
42 /// false if empty.
43 bool validity{false};
44 /// Mutex protecting access to the element and flags.
45 Mutex_tp validity_mt;
46 /// Condition variable for producers waiting for the slot to become free (full
47 /// queue).
49 /// Condition variable for consumers waiting for the slot to be filled (empty
50 /// queue).
52};
53
54} // namespace mysql::concurrency::detail
55
56#endif // MYSQL_CONCURRENCY_PADDED_SLOT
#define T
Definition: jit_executor_value.cc:373
Header for compiler-dependent features.
Definition: cache_line_size.h:31
constexpr std::size_t hardware_destructive_interference_size
Definition: cache_line_size.h:42
Padded slot for Sync_bounded_queue, aligning the struct to cache line size to minimize false sharing ...
Definition: padded_slot.h:38
Cv_tp consumer_cv
Condition variable for consumers waiting for the slot to be filled (empty queue).
Definition: padded_slot.h:51
Mutex_tp validity_mt
Mutex protecting access to the element and flags.
Definition: padded_slot.h:45
Cv_tp producer_cv
Condition variable for producers waiting for the slot to become free (full queue).
Definition: padded_slot.h:48