1
1
2
2
#include "Python.h"
3
- #include "pycore_atomic.h" // _Py_atomic_int
3
+ #include "pycore_atomic.h" // _Py_ANNOTATE_RWLOCK_CREATE
4
4
#include "pycore_ceval.h" // _PyEval_SignalReceived()
5
5
#include "pycore_initconfig.h" // _PyStatus_OK()
6
6
#include "pycore_interp.h" // _Py_RunGC()
@@ -120,9 +120,6 @@ UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp)
120
120
#include <stdlib.h>
121
121
#include <errno.h>
122
122
123
- #include "pycore_atomic.h"
124
-
125
-
126
123
#include "condvar.h"
127
124
128
125
#define MUTEX_INIT (mut ) \
@@ -166,8 +163,7 @@ UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp)
166
163
167
164
static void _gil_initialize (struct _gil_runtime_state * gil )
168
165
{
169
- _Py_atomic_int uninitialized = {-1 };
170
- gil -> locked = uninitialized ;
166
+ gil -> locked = -1 ;
171
167
gil -> interval = DEFAULT_INTERVAL ;
172
168
}
173
169
@@ -176,7 +172,7 @@ static int gil_created(struct _gil_runtime_state *gil)
176
172
if (gil == NULL ) {
177
173
return 0 ;
178
174
}
179
- return (_Py_atomic_load_explicit (& gil -> locked , _Py_memory_order_acquire ) >= 0 );
175
+ return (_Py_atomic_load_int_acquire (& gil -> locked ) >= 0 );
180
176
}
181
177
182
178
static void create_gil (struct _gil_runtime_state * gil )
@@ -191,7 +187,7 @@ static void create_gil(struct _gil_runtime_state *gil)
191
187
#endif
192
188
_Py_atomic_store_ptr_relaxed (& gil -> last_holder , 0 );
193
189
_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 );
195
191
}
196
192
197
193
static void destroy_gil (struct _gil_runtime_state * gil )
@@ -205,8 +201,7 @@ static void destroy_gil(struct _gil_runtime_state *gil)
205
201
COND_FINI (gil -> switch_cond );
206
202
MUTEX_FINI (gil -> switch_mutex );
207
203
#endif
208
- _Py_atomic_store_explicit (& gil -> locked , -1 ,
209
- _Py_memory_order_release );
204
+ _Py_atomic_store_int_release (& gil -> locked , -1 );
210
205
_Py_ANNOTATE_RWLOCK_DESTROY (& gil -> locked );
211
206
}
212
207
@@ -247,7 +242,7 @@ drop_gil(PyInterpreterState *interp, PyThreadState *tstate)
247
242
248
243
MUTEX_LOCK (gil -> mutex );
249
244
_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 );
251
246
COND_SIGNAL (gil -> cond );
252
247
MUTEX_UNLOCK (gil -> mutex );
253
248
@@ -313,12 +308,12 @@ take_gil(PyThreadState *tstate)
313
308
314
309
MUTEX_LOCK (gil -> mutex );
315
310
316
- if (!_Py_atomic_load_relaxed (& gil -> locked )) {
311
+ if (!_Py_atomic_load_int_relaxed (& gil -> locked )) {
317
312
goto _ready ;
318
313
}
319
314
320
315
int drop_requested = 0 ;
321
- while (_Py_atomic_load_relaxed (& gil -> locked )) {
316
+ while (_Py_atomic_load_int_relaxed (& gil -> locked )) {
322
317
unsigned long saved_switchnum = gil -> switch_number ;
323
318
324
319
unsigned long interval = (gil -> interval >= 1 ? gil -> interval : 1 );
@@ -328,7 +323,7 @@ take_gil(PyThreadState *tstate)
328
323
/* If we timed out and no switch occurred in the meantime, it is time
329
324
to ask the GIL-holding thread to drop it. */
330
325
if (timed_out &&
331
- _Py_atomic_load_relaxed (& gil -> locked ) &&
326
+ _Py_atomic_load_int_relaxed (& gil -> locked ) &&
332
327
gil -> switch_number == saved_switchnum )
333
328
{
334
329
if (_PyThreadState_MustExit (tstate )) {
@@ -358,7 +353,7 @@ take_gil(PyThreadState *tstate)
358
353
MUTEX_LOCK (gil -> switch_mutex );
359
354
#endif
360
355
/* We now hold the GIL */
361
- _Py_atomic_store_relaxed (& gil -> locked , 1 );
356
+ _Py_atomic_store_int_relaxed (& gil -> locked , 1 );
362
357
_Py_ANNOTATE_RWLOCK_ACQUIRED (& gil -> locked , /*is_write=*/ 1 );
363
358
364
359
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)
437
432
if (((PyThreadState * )_Py_atomic_load_ptr_relaxed (& gil -> last_holder )) != tstate ) {
438
433
return 0 ;
439
434
}
440
- return _Py_atomic_load_relaxed (& gil -> locked );
435
+ return _Py_atomic_load_int_relaxed (& gil -> locked );
441
436
}
442
437
443
438
static void
0 commit comments