From 1eb79142b9d975c1582173ebeef4c84a1bd2f5e9 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:03:02 +0900 Subject: [PATCH 01/19] gh-109693: Update _gil_runtime_state.locked to use pyatomic.h --- Include/cpython/pyatomic.h | 6 ++++++ Include/cpython/pyatomic_gcc.h | 8 ++++++++ Include/cpython/pyatomic_msc.h | 24 ++++++++++++++++++++++++ Include/cpython/pyatomic_std.h | 17 +++++++++++++++++ Include/internal/pycore_gil.h | 3 +-- Python/ceval_gil.c | 23 +++++++++++------------ 6 files changed, 67 insertions(+), 14 deletions(-) diff --git a/Include/cpython/pyatomic.h b/Include/cpython/pyatomic.h index 7a783058c173aa..5314a70436bfc3 100644 --- a/Include/cpython/pyatomic.h +++ b/Include/cpython/pyatomic.h @@ -463,6 +463,12 @@ _Py_atomic_load_ptr_acquire(const void *obj); static inline void _Py_atomic_store_ptr_release(void *obj, void *value); +static inline void +_Py_atomic_store_int_release(int *obj, int value); + +static inline int +_Py_atomic_load_int_acquire(const int *obj); + // --- _Py_atomic_fence ------------------------------------------------------ diff --git a/Include/cpython/pyatomic_gcc.h b/Include/cpython/pyatomic_gcc.h index f1a38c7b52871a..70f2b7e1b5706a 100644 --- a/Include/cpython/pyatomic_gcc.h +++ b/Include/cpython/pyatomic_gcc.h @@ -487,6 +487,14 @@ static inline void _Py_atomic_store_ptr_release(void *obj, void *value) { __atomic_store_n((void **)obj, value, __ATOMIC_RELEASE); } +static inline void +_Py_atomic_store_int_release(int *obj, int value) +{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); } + +static inline int +_Py_atomic_load_int_acquire(const int *obj) +{ return __atomic_load_n(obj, __ATOMIC_ACQUIRE); } + // --- _Py_atomic_fence ------------------------------------------------------ diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index 287ed43b5714cd..89821a1d27b568 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -912,6 +912,30 @@ _Py_atomic_store_ptr_release(void *obj, void *value) #endif } +static inline void +_Py_atomic_store_int_release(int *obj, int value) +{ +#if defined(_M_X64) || defined(_M_IX86) + *(void * int *)obj = value; +#elif defined(_M_ARM64) + __stlr64((unsigned __int64 volatile *)obj, (int)value); +#else +# error "no implementation of _Py_atomic_store_ptr_release" +#endif +} + +static inline int +_Py_atomic_load_int_acquire(const int *obj) +{ +#if defined(_M_X64) || defined(_M_IX86) + return *(int * volatile *)obj; +#elif defined(_M_ARM64) + return (int *)__ldar64((unsigned __int64 volatile *)obj); +#else +# error "no implementation of _Py_atomic_load_ptr_acquire" +#endif +} + // --- _Py_atomic_fence ------------------------------------------------------ diff --git a/Include/cpython/pyatomic_std.h b/Include/cpython/pyatomic_std.h index bf74a90887c634..fe0efbd711ddba 100644 --- a/Include/cpython/pyatomic_std.h +++ b/Include/cpython/pyatomic_std.h @@ -854,6 +854,23 @@ _Py_atomic_store_ptr_release(void *obj, void *value) memory_order_release); } +static inline void +_Py_atomic_store_int_release(int *obj, int value) +{ + _Py_USING_STD; + atomic_store_explicit((_Atomic(int)*)obj, value, + memory_order_release); +} + +static inline int +_Py_atomic_load_int_acquire(const int *obj) +{ + _Py_USING_STD; + return atomic_load_explicit((const _Atomic(int*)*)obj, + memory_order_acquire); +} + + // --- _Py_atomic_fence ------------------------------------------------------ diff --git a/Include/internal/pycore_gil.h b/Include/internal/pycore_gil.h index daf1e73e7827e8..19b0d23a68568a 100644 --- a/Include/internal/pycore_gil.h +++ b/Include/internal/pycore_gil.h @@ -8,7 +8,6 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif -#include "pycore_atomic.h" // _Py_atomic_int #include "pycore_condvar.h" // PyCOND_T #ifndef Py_HAVE_CONDVAR @@ -28,7 +27,7 @@ struct _gil_runtime_state { PyThreadState* last_holder; /* Whether the GIL is already taken (-1 if uninitialized). This is atomic because it can be read without any lock taken in ceval.c. */ - _Py_atomic_int locked; + int locked; /* Number of GIL switches since the beginning. */ unsigned long switch_number; /* This condition variable allows one or several threads to wait diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index bbb1e784dfa04e..593dffb67075db 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -166,8 +166,7 @@ UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp) static void _gil_initialize(struct _gil_runtime_state *gil) { - _Py_atomic_int uninitialized = {-1}; - gil->locked = uninitialized; + gil->locked = -1; gil->interval = DEFAULT_INTERVAL; } @@ -176,7 +175,7 @@ static int gil_created(struct _gil_runtime_state *gil) if (gil == NULL) { return 0; } - return (_Py_atomic_load_explicit(&gil->locked, _Py_memory_order_acquire) >= 0); + return (_Py_atomic_load_int_acquire(&gil->locked) >= 0); } static void create_gil(struct _gil_runtime_state *gil) @@ -191,7 +190,7 @@ static void create_gil(struct _gil_runtime_state *gil) #endif _Py_atomic_store_ptr_relaxed(&gil->last_holder, 0); _Py_ANNOTATE_RWLOCK_CREATE(&gil->locked); - _Py_atomic_store_explicit(&gil->locked, 0, _Py_memory_order_release); + _Py_atomic_store_int_release(&gil->locked, 0); } static void destroy_gil(struct _gil_runtime_state *gil) @@ -205,8 +204,8 @@ static void destroy_gil(struct _gil_runtime_state *gil) COND_FINI(gil->switch_cond); MUTEX_FINI(gil->switch_mutex); #endif - _Py_atomic_store_explicit(&gil->locked, -1, - _Py_memory_order_release); + _Py_atomic_store_int_relaxed(&gil->locked, -1); + _Py_atomic_store_int_release(&gil->locked, -1); _Py_ANNOTATE_RWLOCK_DESTROY(&gil->locked); } @@ -247,7 +246,7 @@ drop_gil(PyInterpreterState *interp, PyThreadState *tstate) MUTEX_LOCK(gil->mutex); _Py_ANNOTATE_RWLOCK_RELEASED(&gil->locked, /*is_write=*/1); - _Py_atomic_store_relaxed(&gil->locked, 0); + _Py_atomic_store_int_relaxed(&gil->locked, 0); COND_SIGNAL(gil->cond); MUTEX_UNLOCK(gil->mutex); @@ -313,12 +312,12 @@ take_gil(PyThreadState *tstate) MUTEX_LOCK(gil->mutex); - if (!_Py_atomic_load_relaxed(&gil->locked)) { + if (!_Py_atomic_load_int_relaxed(&gil->locked)) { goto _ready; } int drop_requested = 0; - while (_Py_atomic_load_relaxed(&gil->locked)) { + while (_Py_atomic_load_int_relaxed(&gil->locked)) { unsigned long saved_switchnum = gil->switch_number; unsigned long interval = (gil->interval >= 1 ? gil->interval : 1); @@ -328,7 +327,7 @@ take_gil(PyThreadState *tstate) /* If we timed out and no switch occurred in the meantime, it is time to ask the GIL-holding thread to drop it. */ if (timed_out && - _Py_atomic_load_relaxed(&gil->locked) && + _Py_atomic_load_int_relaxed(&gil->locked) && gil->switch_number == saved_switchnum) { if (_PyThreadState_MustExit(tstate)) { @@ -358,7 +357,7 @@ take_gil(PyThreadState *tstate) MUTEX_LOCK(gil->switch_mutex); #endif /* We now hold the GIL */ - _Py_atomic_store_relaxed(&gil->locked, 1); + _Py_atomic_store_int_relaxed(&gil->locked, 1); _Py_ANNOTATE_RWLOCK_ACQUIRED(&gil->locked, /*is_write=*/1); if (tstate != (PyThreadState*)_Py_atomic_load_ptr_relaxed(&gil->last_holder)) { @@ -437,7 +436,7 @@ current_thread_holds_gil(struct _gil_runtime_state *gil, PyThreadState *tstate) if (((PyThreadState*)_Py_atomic_load_ptr_relaxed(&gil->last_holder)) != tstate) { return 0; } - return _Py_atomic_load_relaxed(&gil->locked); + return _Py_atomic_load_int_relaxed(&gil->locked); } static void From 6ad8d1b1fc2bf8d46e0a47521fcdffb1632b3515 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:05:47 +0900 Subject: [PATCH 02/19] nit --- Python/ceval_gil.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index 593dffb67075db..254a9cad6b48c4 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -1,6 +1,5 @@ #include "Python.h" -#include "pycore_atomic.h" // _Py_atomic_int #include "pycore_ceval.h" // _PyEval_SignalReceived() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_interp.h" // _Py_RunGC() @@ -120,9 +119,6 @@ UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp) #include #include -#include "pycore_atomic.h" - - #include "condvar.h" #define MUTEX_INIT(mut) \ From 7624da864a5ab7db61716d0ce680084032fb528a Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:11:43 +0900 Subject: [PATCH 03/19] fix --- Include/cpython/pyatomic_msc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index 89821a1d27b568..1616cefc18eb43 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -916,7 +916,7 @@ static inline void _Py_atomic_store_int_release(int *obj, int value) { #if defined(_M_X64) || defined(_M_IX86) - *(void * int *)obj = value; + *(int * volatile *)obj = value; #elif defined(_M_ARM64) __stlr64((unsigned __int64 volatile *)obj, (int)value); #else From efe778d33ff83042dc7384f19f07fd5a1fa26519 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:14:58 +0900 Subject: [PATCH 04/19] fix --- Include/cpython/pyatomic_msc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index 1616cefc18eb43..2b55940f98448e 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -928,7 +928,7 @@ static inline int _Py_atomic_load_int_acquire(const int *obj) { #if defined(_M_X64) || defined(_M_IX86) - return *(int * volatile *)obj; + return *(int volatile *)obj; #elif defined(_M_ARM64) return (int *)__ldar64((unsigned __int64 volatile *)obj); #else From 869a350442fc25d7eb7b1ad775dfbeeb2a0837fe Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:21:10 +0900 Subject: [PATCH 05/19] fix --- Include/cpython/pyatomic_msc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index 2b55940f98448e..862d04ac87cef9 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -918,7 +918,7 @@ _Py_atomic_store_int_release(int *obj, int value) #if defined(_M_X64) || defined(_M_IX86) *(int * volatile *)obj = value; #elif defined(_M_ARM64) - __stlr64((unsigned __int64 volatile *)obj, (int)value); + __stlr32((unsigned __int32 volatile *)obj, (int)value); #else # error "no implementation of _Py_atomic_store_ptr_release" #endif @@ -930,7 +930,7 @@ _Py_atomic_load_int_acquire(const int *obj) #if defined(_M_X64) || defined(_M_IX86) return *(int volatile *)obj; #elif defined(_M_ARM64) - return (int *)__ldar64((unsigned __int64 volatile *)obj); + return (int *)__ldar32((unsigned __int32 volatile *)obj); #else # error "no implementation of _Py_atomic_load_ptr_acquire" #endif From 64196a852b53b0158e138aec66c4ec8f104f5435 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:29:01 +0900 Subject: [PATCH 06/19] fix --- Include/cpython/pyatomic_msc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index 862d04ac87cef9..3db11577844ece 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -916,7 +916,7 @@ static inline void _Py_atomic_store_int_release(int *obj, int value) { #if defined(_M_X64) || defined(_M_IX86) - *(int * volatile *)obj = value; + *(int volatile *)obj = value; #elif defined(_M_ARM64) __stlr32((unsigned __int32 volatile *)obj, (int)value); #else From bd7d3b1fe088c3fafc5dc9c3360c6c57c4c690c5 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:33:25 +0900 Subject: [PATCH 07/19] Address code review --- Include/cpython/pyatomic_msc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index 3db11577844ece..134d178aea226c 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -918,7 +918,7 @@ _Py_atomic_store_int_release(int *obj, int value) #if defined(_M_X64) || defined(_M_IX86) *(int volatile *)obj = value; #elif defined(_M_ARM64) - __stlr32((unsigned __int32 volatile *)obj, (int)value); + __stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value); #else # error "no implementation of _Py_atomic_store_ptr_release" #endif @@ -930,7 +930,7 @@ _Py_atomic_load_int_acquire(const int *obj) #if defined(_M_X64) || defined(_M_IX86) return *(int volatile *)obj; #elif defined(_M_ARM64) - return (int *)__ldar32((unsigned __int32 volatile *)obj); + return (int)__ldar32((unsigned __int32 volatile *)obj); #else # error "no implementation of _Py_atomic_load_ptr_acquire" #endif From 06847b62de0c00c90f028e25d1f614de6eca1f04 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:34:16 +0900 Subject: [PATCH 08/19] Address code review --- Include/cpython/pyatomic_std.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/pyatomic_std.h b/Include/cpython/pyatomic_std.h index fe0efbd711ddba..a05bfaec47e89d 100644 --- a/Include/cpython/pyatomic_std.h +++ b/Include/cpython/pyatomic_std.h @@ -866,7 +866,7 @@ static inline int _Py_atomic_load_int_acquire(const int *obj) { _Py_USING_STD; - return atomic_load_explicit((const _Atomic(int*)*)obj, + return atomic_load_explicit((const _Atomic(int)*)obj, memory_order_acquire); } From 39989fc7dd377e1217e1ff6f85b507a1e11d3fe2 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:37:22 +0900 Subject: [PATCH 09/19] Address code review --- Python/ceval_gil.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index 254a9cad6b48c4..92c4b2fee9f863 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -200,7 +200,6 @@ static void destroy_gil(struct _gil_runtime_state *gil) COND_FINI(gil->switch_cond); MUTEX_FINI(gil->switch_mutex); #endif - _Py_atomic_store_int_relaxed(&gil->locked, -1); _Py_atomic_store_int_release(&gil->locked, -1); _Py_ANNOTATE_RWLOCK_DESTROY(&gil->locked); } From 48cb6639c4b8267573cdcd197fd733dfcb23384c Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:40:07 +0900 Subject: [PATCH 10/19] Address code review --- Include/cpython/pyatomic_msc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index 134d178aea226c..fac965c6669c40 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -920,7 +920,7 @@ _Py_atomic_store_int_release(int *obj, int value) #elif defined(_M_ARM64) __stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value); #else -# error "no implementation of _Py_atomic_store_ptr_release" +# error "no implementation of _Py_atomic_store_int_release" #endif } @@ -932,7 +932,7 @@ _Py_atomic_load_int_acquire(const int *obj) #elif defined(_M_ARM64) return (int)__ldar32((unsigned __int32 volatile *)obj); #else -# error "no implementation of _Py_atomic_load_ptr_acquire" +# error "no implementation of _Py_atomic_load_int_acquire" #endif } From 89aa5b7c93d657f59cdb577bf43480354265288d Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:48:25 +0900 Subject: [PATCH 11/19] Add test code --- Modules/_testcapi/pyatomic.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Modules/_testcapi/pyatomic.c b/Modules/_testcapi/pyatomic.c index 5aedf687705707..00e079b9096b84 100644 --- a/Modules/_testcapi/pyatomic.c +++ b/Modules/_testcapi/pyatomic.c @@ -140,6 +140,22 @@ test_atomic_release_acquire(PyObject *self, PyObject *obj) { Py_RETURN_NONE; } +static PyObject * +test_atomic_load_store_int_release_acquire(PyObject *self, PyObject *obj) { \ + int x = 0; + int y = 1; + int z = 2; + assert(_Py_atomic_load_int_acquire(&x) == 0); + assert(x == 0); + _Py_atomic_store_int_release(&x, y); + assert(_Py_atomic_load_int_acquire(&x) == 1); + assert(x == 1); + _Py_atomic_store_int_release(&x, z); + assert(_Py_atomic_load_int_relaxed(&x) == 2); + assert(x == 2); + Py_RETURN_NONE; +} + // NOTE: all tests should start with "test_atomic_" to be included // in test_pyatomic.py @@ -162,6 +178,7 @@ static PyMethodDef test_methods[] = { FOR_BITWISE_TYPES(BIND_TEST_AND_OR) {"test_atomic_fences", test_atomic_fences, METH_NOARGS}, {"test_atomic_release_acquire", test_atomic_release_acquire, METH_NOARGS}, + {"test_atomic_load_store_int_release_acquire", test_atomic_load_store_int_release_acquire, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; From c0bdbc63d93f74bd2077a0170a9c82df7f621d15 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:54:49 +0900 Subject: [PATCH 12/19] nit --- Modules/_testcapi/pyatomic.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/_testcapi/pyatomic.c b/Modules/_testcapi/pyatomic.c index 00e079b9096b84..f80b90fa6f2cf8 100644 --- a/Modules/_testcapi/pyatomic.c +++ b/Modules/_testcapi/pyatomic.c @@ -145,14 +145,14 @@ test_atomic_load_store_int_release_acquire(PyObject *self, PyObject *obj) { \ int x = 0; int y = 1; int z = 2; - assert(_Py_atomic_load_int_acquire(&x) == 0); + _Py_atomic_load_int_acquire(&x); assert(x == 0); _Py_atomic_store_int_release(&x, y); - assert(_Py_atomic_load_int_acquire(&x) == 1); - assert(x == 1); + assert(x == y); + assert(_Py_atomic_load_int_acquire(&x) == y); _Py_atomic_store_int_release(&x, z); - assert(_Py_atomic_load_int_relaxed(&x) == 2); - assert(x == 2); + assert(x == z); + assert(_Py_atomic_load_int_relaxed(&x) == z); Py_RETURN_NONE; } From fffdcff88ea5e78287aabea3170eb4ab897d9b04 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 00:58:48 +0900 Subject: [PATCH 13/19] fix --- Modules/_testcapi/pyatomic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapi/pyatomic.c b/Modules/_testcapi/pyatomic.c index f80b90fa6f2cf8..d8a7fb83f88488 100644 --- a/Modules/_testcapi/pyatomic.c +++ b/Modules/_testcapi/pyatomic.c @@ -152,7 +152,7 @@ test_atomic_load_store_int_release_acquire(PyObject *self, PyObject *obj) { \ assert(_Py_atomic_load_int_acquire(&x) == y); _Py_atomic_store_int_release(&x, z); assert(x == z); - assert(_Py_atomic_load_int_relaxed(&x) == z); + assert(_Py_atomic_load_int_acquire(&x) == z); Py_RETURN_NONE; } From 061265e51b54ed1e7c26caf6423e4511e7eb66aa Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 02:05:34 +0900 Subject: [PATCH 14/19] Revert header --- Python/ceval_gil.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index 92c4b2fee9f863..5927fb5547b11a 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -1,5 +1,6 @@ #include "Python.h" +#include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_XXXX #include "pycore_ceval.h" // _PyEval_SignalReceived() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_interp.h" // _Py_RunGC() From b5d053950958624f9910435e05ae1984fc72dd88 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 14 Oct 2023 02:13:39 +0900 Subject: [PATCH 15/19] Update --- Python/thread_pthread.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 76a1f7763f23b9..48f197a8e5b03a 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -1,5 +1,6 @@ #include "pycore_interp.h" // _PyInterpreterState.threads.stacksize #include "pycore_pythread.h" // _POSIX_SEMAPHORES +#include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_XXXX /* Posix threads interface */ From e37e80da38c544dceb3e0752310f26bcca6b87f2 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 16 Oct 2023 22:23:03 +0900 Subject: [PATCH 16/19] fix test --- Modules/_testcapi/pyatomic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Modules/_testcapi/pyatomic.c b/Modules/_testcapi/pyatomic.c index d8a7fb83f88488..4f72844535ebd6 100644 --- a/Modules/_testcapi/pyatomic.c +++ b/Modules/_testcapi/pyatomic.c @@ -145,8 +145,7 @@ test_atomic_load_store_int_release_acquire(PyObject *self, PyObject *obj) { \ int x = 0; int y = 1; int z = 2; - _Py_atomic_load_int_acquire(&x); - assert(x == 0); + assert(_Py_atomic_load_int_acquire(&x) == 0); _Py_atomic_store_int_release(&x, y); assert(x == y); assert(_Py_atomic_load_int_acquire(&x) == y); From 044570ebed4dcae4a4d087c4589585bf1192b73c Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 16 Oct 2023 22:29:48 +0900 Subject: [PATCH 17/19] Address code review --- Python/ceval_gil.c | 2 +- Python/thread_pthread.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index 5927fb5547b11a..45a44bb715d309 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -1,6 +1,6 @@ #include "Python.h" -#include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_XXXX +#include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_ACQUIRED/CREATE/DESTROY #include "pycore_ceval.h" // _PyEval_SignalReceived() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_interp.h" // _Py_RunGC() diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 48f197a8e5b03a..7a6aef7ad18a5a 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -1,6 +1,6 @@ #include "pycore_interp.h" // _PyInterpreterState.threads.stacksize #include "pycore_pythread.h" // _POSIX_SEMAPHORES -#include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_XXXX +#include "pycore_atomic.h" // _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX /* Posix threads interface */ From b067e13b6586b1903dc21a871f1e26854fbc4051 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 16 Oct 2023 22:35:52 +0900 Subject: [PATCH 18/19] Address code review --- Include/cpython/pyatomic_msc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h index fac965c6669c40..601a0cf65afc1c 100644 --- a/Include/cpython/pyatomic_msc.h +++ b/Include/cpython/pyatomic_msc.h @@ -918,6 +918,7 @@ _Py_atomic_store_int_release(int *obj, int value) #if defined(_M_X64) || defined(_M_IX86) *(int volatile *)obj = value; #elif defined(_M_ARM64) + _Py_atomic_ASSERT_ARG_TYPE(unsigned __int32); __stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value); #else # error "no implementation of _Py_atomic_store_int_release" @@ -930,6 +931,7 @@ _Py_atomic_load_int_acquire(const int *obj) #if defined(_M_X64) || defined(_M_IX86) return *(int volatile *)obj; #elif defined(_M_ARM64) + _Py_atomic_ASSERT_ARG_TYPE(unsigned __int32); return (int)__ldar32((unsigned __int32 volatile *)obj); #else # error "no implementation of _Py_atomic_load_int_acquire" From c58dfc80ab34933793a2d6c7d27a7af71234c1f1 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 16 Oct 2023 22:39:19 +0900 Subject: [PATCH 19/19] Update --- Python/ceval_gil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index 45a44bb715d309..97ef39e80aab25 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -1,6 +1,6 @@ #include "Python.h" -#include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_ACQUIRED/CREATE/DESTROY +#include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_CREATE #include "pycore_ceval.h" // _PyEval_SignalReceived() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_interp.h" // _Py_RunGC()