Skip to content

Commit d2e96e4

Browse files
committed
Merge 10.4 into 10.5
2 parents 49b29e3 + fa03978 commit d2e96e4

File tree

5 files changed

+88
-45
lines changed

5 files changed

+88
-45
lines changed

include/my_atomic.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -169,49 +169,4 @@
169169
#define my_atomic_casptr_strong_explicit(P, E, D, S, F) \
170170
my_atomic_casptr((P), (E), (D))
171171
#endif
172-
173-
#ifdef __cplusplus
174-
#include <atomic>
175-
/**
176-
A wrapper for std::atomic, defaulting to std::memory_order_relaxed.
177-
178-
When it comes to atomic loads or stores at std::memory_order_relaxed
179-
on IA-32 or AMD64, this wrapper is only introducing some constraints
180-
to the C++ compiler, to prevent some optimizations of loads or
181-
stores.
182-
183-
On POWER and ARM, atomic loads and stores involve different instructions
184-
from normal loads and stores and will thus incur some overhead.
185-
186-
Because atomic read-modify-write operations will always incur
187-
overhead, we intentionally do not define
188-
operator++(), operator--(), operator+=(), operator-=(), or similar,
189-
to make the overhead stand out in the users of this code.
190-
*/
191-
template <typename Type> class Atomic_relaxed
192-
{
193-
std::atomic<Type> m;
194-
public:
195-
Atomic_relaxed(const Atomic_relaxed<Type> &rhs)
196-
{ m.store(rhs, std::memory_order_relaxed); }
197-
Atomic_relaxed(Type val) : m(val) {}
198-
Atomic_relaxed() {}
199-
200-
operator Type() const { return m.load(std::memory_order_relaxed); }
201-
Type operator=(const Type val)
202-
{ m.store(val, std::memory_order_relaxed); return val; }
203-
Type operator=(const Atomic_relaxed<Type> &rhs) { return *this= Type{rhs}; }
204-
Type fetch_add(const Type i, std::memory_order o= std::memory_order_relaxed)
205-
{ return m.fetch_add(i, o); }
206-
Type fetch_sub(const Type i, std::memory_order o= std::memory_order_relaxed)
207-
{ return m.fetch_sub(i, o); }
208-
bool compare_exchange_strong(Type& i1, const Type i2,
209-
std::memory_order o1= std::memory_order_relaxed,
210-
std::memory_order o2= std::memory_order_relaxed)
211-
{ return m.compare_exchange_strong(i1, i2, o1, o2); }
212-
Type exchange(const Type i, std::memory_order o= std::memory_order_relaxed)
213-
{ return m.exchange(i, o); }
214-
};
215-
#endif /* __cplusplus */
216-
217172
#endif /* MY_ATOMIC_INCLUDED */

include/my_atomic_wrapper.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Copyright (c) 2020, MariaDB
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 as published by
5+
the Free Software Foundation; version 2 of the License.
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 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-1335 USA */
15+
16+
#ifdef __cplusplus
17+
#include <atomic>
18+
/**
19+
A wrapper for std::atomic, defaulting to std::memory_order_relaxed.
20+
21+
When it comes to atomic loads or stores at std::memory_order_relaxed
22+
on IA-32 or AMD64, this wrapper is only introducing some constraints
23+
to the C++ compiler, to prevent some optimizations of loads or
24+
stores.
25+
26+
On POWER and ARM, atomic loads and stores involve different instructions
27+
from normal loads and stores and will thus incur some overhead.
28+
29+
Because atomic read-modify-write operations will always incur
30+
overhead, we intentionally do not define
31+
operator++(), operator--(), operator+=(), operator-=(), or similar,
32+
to make the overhead stand out in the users of this code.
33+
*/
34+
template <typename Type> class Atomic_relaxed
35+
{
36+
std::atomic<Type> m;
37+
public:
38+
Atomic_relaxed(const Atomic_relaxed<Type> &rhs)
39+
{ m.store(rhs, std::memory_order_relaxed); }
40+
Atomic_relaxed(Type val) : m(val) {}
41+
Atomic_relaxed() {}
42+
43+
operator Type() const { return m.load(std::memory_order_relaxed); }
44+
Type operator=(const Type val)
45+
{ m.store(val, std::memory_order_relaxed); return val; }
46+
Type operator=(const Atomic_relaxed<Type> &rhs) { return *this= Type{rhs}; }
47+
Type fetch_add(const Type i, std::memory_order o= std::memory_order_relaxed)
48+
{ return m.fetch_add(i, o); }
49+
Type fetch_sub(const Type i, std::memory_order o= std::memory_order_relaxed)
50+
{ return m.fetch_sub(i, o); }
51+
bool compare_exchange_strong(Type& i1, const Type i2,
52+
std::memory_order o1= std::memory_order_relaxed,
53+
std::memory_order o2= std::memory_order_relaxed)
54+
{ return m.compare_exchange_strong(i1, i2, o1, o2); }
55+
Type exchange(const Type i, std::memory_order o= std::memory_order_relaxed)
56+
{ return m.exchange(i, o); }
57+
};
58+
#endif /* __cplusplus */

mysql-test/main/table_value_constr.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,3 +2621,16 @@ EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE;
26212621
ERROR HY000: 'ignore' is not allowed in this context
26222622
EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT;
26232623
ERROR HY000: 'default' is not allowed in this context
2624+
#
2625+
# MDEV-22610 Crash in INSERT INTO t1 (VALUES (DEFAULT) UNION VALUES (DEFAULT))
2626+
#
2627+
VALUES (DEFAULT) UNION VALUES (DEFAULT);
2628+
ERROR HY000: 'default' is not allowed in this context
2629+
VALUES (IGNORE) UNION VALUES (IGNORE);
2630+
ERROR HY000: 'ignore' is not allowed in this context
2631+
CREATE TABLE t1 (a INT DEFAULT 10);
2632+
INSERT INTO t1 (VALUES (DEFAULT) UNION VALUES (DEFAULT));
2633+
ERROR HY000: 'default' is not allowed in this context
2634+
INSERT INTO t1 (VALUES (IGNORE) UNION VALUES (IGNORE));
2635+
ERROR HY000: 'ignore' is not allowed in this context
2636+
DROP TABLE t1;

mysql-test/main/table_value_constr.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,3 +1353,19 @@ VALUES (DEFAULT);
13531353
EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE;
13541354
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
13551355
EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT;
1356+
1357+
1358+
--echo #
1359+
--echo # MDEV-22610 Crash in INSERT INTO t1 (VALUES (DEFAULT) UNION VALUES (DEFAULT))
1360+
--echo #
1361+
1362+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
1363+
VALUES (DEFAULT) UNION VALUES (DEFAULT);
1364+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
1365+
VALUES (IGNORE) UNION VALUES (IGNORE);
1366+
CREATE TABLE t1 (a INT DEFAULT 10);
1367+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
1368+
INSERT INTO t1 (VALUES (DEFAULT) UNION VALUES (DEFAULT));
1369+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
1370+
INSERT INTO t1 (VALUES (IGNORE) UNION VALUES (IGNORE));
1371+
DROP TABLE t1;

storage/innobase/include/srv0mon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Created 12/15/2009 Jimmy Yang
3838

3939
#include <stdint.h>
4040
#include "my_atomic.h"
41+
#include "my_atomic_wrapper.h"
4142

4243
/** Possible status values for "mon_status" in "struct monitor_value" */
4344
enum monitor_running_status {

0 commit comments

Comments
 (0)