Skip to content

Commit b166202

Browse files
committed
Merge branch 'main' into ft-thread-safe-deque
2 parents 1d00d9f + a95b1a5 commit b166202

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This header file provides wrappers around the atomic operations found in
2+
// `pyatomic.h` that are only atomic in free-threaded builds.
3+
//
4+
// These are intended to be used in places where atomics are required in
5+
// free-threaded builds, but not in the default build, and we don't want to
6+
// introduce the potential performance overhead of an atomic operation in the
7+
// default build.
8+
//
9+
// All usages of these macros should be replaced with unconditionally atomic or
10+
// non-atomic versions, and this file should be removed, once the dust settles
11+
// on free threading.
12+
#ifndef Py_ATOMIC_FT_WRAPPERS_H
13+
#define Py_ATOMIC_FT_WRAPPERS_H
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
#ifndef Py_BUILD_CORE
19+
#error "this header requires Py_BUILD_CORE define"
20+
#endif
21+
22+
#ifdef Py_GIL_DISABLED
23+
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) \
24+
_Py_atomic_load_ssize_relaxed(&value)
25+
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) \
26+
_Py_atomic_store_ssize_relaxed(&value, new_value)
27+
#else
28+
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) value
29+
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) value = new_value
30+
#endif
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
#endif /* !Py_ATOMIC_FT_WRAPPERS_H */

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,7 @@ PYTHON_HEADERS= \
11501150
$(srcdir)/Include/internal/pycore_parser.h \
11511151
$(srcdir)/Include/internal/pycore_pathconfig.h \
11521152
$(srcdir)/Include/internal/pycore_pyarena.h \
1153+
$(srcdir)/Include/internal/pycore_pyatomic_ft_wrappers.h \
11531154
$(srcdir)/Include/internal/pycore_pybuffer.h \
11541155
$(srcdir)/Include/internal/pycore_pyerrors.h \
11551156
$(srcdir)/Include/internal/pycore_pyhash.h \

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
<ClInclude Include="..\Include\internal\pycore_parking_lot.h" />
267267
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
268268
<ClInclude Include="..\Include\internal\pycore_pyarena.h" />
269+
<ClInclude Include="..\Include\internal\pycore_pyatomic_ft_wrappers.h" />
269270
<ClInclude Include="..\Include\internal\pycore_pyerrors.h" />
270271
<ClInclude Include="..\Include\internal\pycore_pyhash.h" />
271272
<ClInclude Include="..\Include\internal\pycore_pylifecycle.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,9 @@
723723
<ClInclude Include="..\Include\internal\pycore_pyarena.h">
724724
<Filter>Include\internal</Filter>
725725
</ClInclude>
726+
<ClInclude Include="..\Include\internal\pycore_pyatomic_ft_wrappers.h">
727+
<Filter>Include\internal</Filter>
728+
</ClInclude>
726729
<ClInclude Include="..\Include\internal\pycore_pyerrors.h">
727730
<Filter>Include\internal</Filter>
728731
</ClInclude>

0 commit comments

Comments
 (0)