From 2b3690d2f27a1e1e907ef36865bd634c9d993966 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Mon, 5 Feb 2024 15:24:37 -0800 Subject: [PATCH 1/5] Add wrappers that are atomic only in free-threaded builds These are intended to be used in places where atomics are required in free-threaded builds, but not in the default build, and we don't want to introduce the potential performance overhead of an atomic operation in the default build. --- .../internal/pycore_pyatomic_ft_wrappers.h | 35 +++++++++++++++++++ Makefile.pre.in | 1 + 2 files changed, 36 insertions(+) create mode 100644 Include/internal/pycore_pyatomic_ft_wrappers.h diff --git a/Include/internal/pycore_pyatomic_ft_wrappers.h b/Include/internal/pycore_pyatomic_ft_wrappers.h new file mode 100644 index 00000000000000..d1313976da1cfc --- /dev/null +++ b/Include/internal/pycore_pyatomic_ft_wrappers.h @@ -0,0 +1,35 @@ +// This header file provides wrappers around the atomic operations found in +// `pyatomic.h` that are only atomic in free-threaded builds. +// +// These are intended to be used in places where atomics are required in +// free-threaded builds, but not in the default build, and we don't want to +// introduce the potential performance overhead of an atomic operation in the +// default build. +// +// All usages of these macros should be replaced with unconditionally atomic or +// non-atomic versions, and this file should be removed, once the dust settles +// on free threading. +#ifndef Py_ATOMIC_FT_WRAPPERS_H +#define Py_ATOMIC_FT_WRAPPERS_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +#error "this header requires Py_BUILD_CORE define" +#endif + +#ifdef Py_GIL_DISABLED +#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) \ + _Py_atomic_load_ssize_relaxed(&value) +#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) \ + _Py_atomic_store_ssize_relaxed(&value, new_value) +#else +#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) value +#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) value = new_value +#endif + +#ifdef __cplusplus +} +#endif +#endif /* !Py_ATOMIC_FT_WRAPPERS_H */ diff --git a/Makefile.pre.in b/Makefile.pre.in index aad637876ead80..311a7dd5ec7ed0 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1867,6 +1867,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_parking_lot.h \ $(srcdir)/Include/internal/pycore_pathconfig.h \ $(srcdir)/Include/internal/pycore_pyarena.h \ + $(srcdir)/Include/internal/pycore_pyatomic_ft_wrappers.h \ $(srcdir)/Include/internal/pycore_pybuffer.h \ $(srcdir)/Include/internal/pycore_pyerrors.h \ $(srcdir)/Include/internal/pycore_pyhash.h \ From 4cd4621afb66b80398d9e49089740ee5d8b14281 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 23:55:17 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst b/Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst new file mode 100644 index 00000000000000..fddbada766d5d7 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst @@ -0,0 +1 @@ +Add helpers that perform atomic operations in free-threaded builds and decay to equivalent non-atomic operations in default builds. From 1b977a5e3df5e4045d26d5194cdf4a74ccda06b6 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Tue, 13 Feb 2024 13:45:48 -0800 Subject: [PATCH 3/5] Remove NEWS entry --- .../2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst b/Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst deleted file mode 100644 index fddbada766d5d7..00000000000000 --- a/Misc/NEWS.d/next/Core and Builtins/2024-02-05-23-55-16.gh-issue-115041.nePwhM.rst +++ /dev/null @@ -1 +0,0 @@ -Add helpers that perform atomic operations in free-threaded builds and decay to equivalent non-atomic operations in default builds. From e78e018e0da242b841c7018fb202c82c6e93566f Mon Sep 17 00:00:00 2001 From: Matt Page Date: Tue, 13 Feb 2024 13:53:35 -0800 Subject: [PATCH 4/5] Add header to vcxproj files --- PCbuild/pythoncore.vcxproj | 1 + PCbuild/pythoncore.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 4cc0ca4b9af8de..abfafbb2a32f45 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -266,6 +266,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index ceaa21217267cf..d14f5a6d7fb0fc 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -723,6 +723,9 @@ Include\internal + + Include\internal + Include\internal From b44e1ab9bfe0c106eaed3851d63ffff5f3d2c436 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Tue, 13 Feb 2024 14:31:32 -0800 Subject: [PATCH 5/5] Remove stray newline --- Makefile.pre.in | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 99c1fd6f4b7f26..1e4c689179c122 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1934,7 +1934,6 @@ regen-typeslots: $(srcdir)/Objects/typeslots.inc.new $(UPDATE_FILE) $(srcdir)/Objects/typeslots.inc $(srcdir)/Objects/typeslots.inc.new - $(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)