11
22#include "Python.h"
3- #include "pycore_atomic.h" // _Py_atomic_int
3+ #include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_CREATE
44#include "pycore_ceval.h" // _PyEval_SignalReceived()
55#include "pycore_initconfig.h" // _PyStatus_OK()
66#include "pycore_interp.h" // _Py_RunGC()
@@ -120,9 +120,6 @@ UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp)
120120#include <stdlib.h>
121121#include <errno.h>
122122
123- #include "pycore_atomic.h"
124-
125-
126123#include "condvar.h"
127124
128125#define MUTEX_INIT (mut ) \
@@ -166,8 +163,7 @@ UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp)
166163
167164static void _gil_initialize (struct _gil_runtime_state * gil )
168165{
169- _Py_atomic_int uninitialized = {-1 };
170- gil -> locked = uninitialized ;
166+ gil -> locked = -1 ;
171167 gil -> interval = DEFAULT_INTERVAL ;
172168}
173169
@@ -176,7 +172,7 @@ static int gil_created(struct _gil_runtime_state *gil)
176172 if (gil == NULL ) {
177173 return 0 ;
178174 }
179- return (_Py_atomic_load_explicit (& gil -> locked , _Py_memory_order_acquire ) >= 0 );
175+ return (_Py_atomic_load_int_acquire (& gil -> locked ) >= 0 );
180176}
181177
182178static void create_gil (struct _gil_runtime_state * gil )
@@ -191,7 +187,7 @@ static void create_gil(struct _gil_runtime_state *gil)
191187#endif
192188 _Py_atomic_store_ptr_relaxed (& gil -> last_holder , 0 );
193189 _Py_ANNOTATE_RWLOCK_CREATE (& gil -> locked );
194- _Py_atomic_store_explicit (& gil -> locked , 0 , _Py_memory_order_release );
190+ _Py_atomic_store_int_release (& gil -> locked , 0 );
195191}
196192
197193static void destroy_gil (struct _gil_runtime_state * gil )
@@ -205,8 +201,7 @@ static void destroy_gil(struct _gil_runtime_state *gil)
205201 COND_FINI (gil -> switch_cond );
206202 MUTEX_FINI (gil -> switch_mutex );
207203#endif
208- _Py_atomic_store_explicit (& gil -> locked , -1 ,
209- _Py_memory_order_release );
204+ _Py_atomic_store_int_release (& gil -> locked , -1 );
210205 _Py_ANNOTATE_RWLOCK_DESTROY (& gil -> locked );
211206}
212207
@@ -247,7 +242,7 @@ drop_gil(PyInterpreterState *interp, PyThreadState *tstate)
247242
248243 MUTEX_LOCK (gil -> mutex );
249244 _Py_ANNOTATE_RWLOCK_RELEASED (& gil -> locked , /*is_write=*/ 1 );
250- _Py_atomic_store_relaxed (& gil -> locked , 0 );
245+ _Py_atomic_store_int_relaxed (& gil -> locked , 0 );
251246 COND_SIGNAL (gil -> cond );
252247 MUTEX_UNLOCK (gil -> mutex );
253248
@@ -313,12 +308,12 @@ take_gil(PyThreadState *tstate)
313308
314309 MUTEX_LOCK (gil -> mutex );
315310
316- if (!_Py_atomic_load_relaxed (& gil -> locked )) {
311+ if (!_Py_atomic_load_int_relaxed (& gil -> locked )) {
317312 goto _ready ;
318313 }
319314
320315 int drop_requested = 0 ;
321- while (_Py_atomic_load_relaxed (& gil -> locked )) {
316+ while (_Py_atomic_load_int_relaxed (& gil -> locked )) {
322317 unsigned long saved_switchnum = gil -> switch_number ;
323318
324319 unsigned long interval = (gil -> interval >= 1 ? gil -> interval : 1 );
@@ -328,7 +323,7 @@ take_gil(PyThreadState *tstate)
328323 /* If we timed out and no switch occurred in the meantime, it is time
329324 to ask the GIL-holding thread to drop it. */
330325 if (timed_out &&
331- _Py_atomic_load_relaxed (& gil -> locked ) &&
326+ _Py_atomic_load_int_relaxed (& gil -> locked ) &&
332327 gil -> switch_number == saved_switchnum )
333328 {
334329 if (_PyThreadState_MustExit (tstate )) {
@@ -358,7 +353,7 @@ take_gil(PyThreadState *tstate)
358353 MUTEX_LOCK (gil -> switch_mutex );
359354#endif
360355 /* We now hold the GIL */
361- _Py_atomic_store_relaxed (& gil -> locked , 1 );
356+ _Py_atomic_store_int_relaxed (& gil -> locked , 1 );
362357 _Py_ANNOTATE_RWLOCK_ACQUIRED (& gil -> locked , /*is_write=*/ 1 );
363358
364359 if (tstate != (PyThreadState * )_Py_atomic_load_ptr_relaxed (& gil -> last_holder )) {
@@ -437,7 +432,7 @@ current_thread_holds_gil(struct _gil_runtime_state *gil, PyThreadState *tstate)
437432 if (((PyThreadState * )_Py_atomic_load_ptr_relaxed (& gil -> last_holder )) != tstate ) {
438433 return 0 ;
439434 }
440- return _Py_atomic_load_relaxed (& gil -> locked );
435+ return _Py_atomic_load_int_relaxed (& gil -> locked );
441436}
442437
443438static void
0 commit comments