summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2023-10-16 22:32:50 (GMT)
committerGitHub <noreply@github.com>2023-10-16 22:32:50 (GMT)
commit86559ddfecefdda265d39e5e5035f72986becd78 (patch)
treef6c5ce93297f9736a887fed9137498570be321f6 /Python
parent06f844eaa0a09b8524ade5734b4f2cc742a0a5c7 (diff)
downloadcpython-86559ddfecefdda265d39e5e5035f72986becd78.zip
cpython-86559ddfecefdda265d39e5e5035f72986becd78.tar.gz
cpython-86559ddfecefdda265d39e5e5035f72986becd78.tar.bz2
gh-109693: Update _gil_runtime_state.locked to use pyatomic.h (gh-110836)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval_gil.c27
-rw-r--r--Python/thread_pthread.h1
2 files changed, 12 insertions, 16 deletions
diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c
index bbb1e78..97ef39e 100644
--- a/Python/ceval_gil.c
+++ b/Python/ceval_gil.c
@@ -1,6 +1,6 @@
#include "Python.h"
-#include "pycore_atomic.h" // _Py_atomic_int
+#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()
@@ -120,9 +120,6 @@ UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp)
#include <stdlib.h>
#include <errno.h>
-#include "pycore_atomic.h"
-
-
#include "condvar.h"
#define MUTEX_INIT(mut) \
@@ -166,8 +163,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 +172,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 +187,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 +201,7 @@ 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_release(&gil->locked, -1);
_Py_ANNOTATE_RWLOCK_DESTROY(&gil->locked);
}
@@ -247,7 +242,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 +308,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 +323,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 +353,7 @@ _ready:
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 +432,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
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index 76a1f77..7a6aef7 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_PURE_HAPPENS_BEFORE_MUTEX
/* Posix threads interface */