From f6307d44167e9c110a1db442f7a33deb365e89a8 Mon Sep 17 00:00:00 2001
From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Date: Sun, 15 Jan 2023 20:39:26 +0530
Subject: GH-100892: consolidate `HEAD_LOCK/HEAD_UNLOCK` macros (#100953)

---
 Include/internal/pycore_pystate.h | 6 ++++++
 Modules/_threadmodule.c           | 5 -----
 Python/ceval.c                    | 5 -----
 Python/pystate.c                  | 4 ----
 4 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index 3d6d400..736c2b3 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -162,6 +162,12 @@ PyAPI_FUNC(int) _PyState_AddModule(
 
 PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);
 
+#define HEAD_LOCK(runtime) \
+    PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
+#define HEAD_UNLOCK(runtime) \
+    PyThread_release_lock((runtime)->interpreters.mutex)
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 4fbf0e5..80f467a 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -839,11 +839,6 @@ local_traverse(localobject *self, visitproc visit, void *arg)
     return 0;
 }
 
-#define HEAD_LOCK(runtime) \
-    PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
-#define HEAD_UNLOCK(runtime) \
-    PyThread_release_lock((runtime)->interpreters.mutex)
-
 static int
 local_clear(localobject *self)
 {
diff --git a/Python/ceval.c b/Python/ceval.c
index 7deee76..ecbe2f9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -97,11 +97,6 @@
 #define _Py_atomic_load_relaxed_int32(ATOMIC_VAL) _Py_atomic_load_relaxed(ATOMIC_VAL)
 #endif
 
-#define HEAD_LOCK(runtime) \
-    PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
-#define HEAD_UNLOCK(runtime) \
-    PyThread_release_lock((runtime)->interpreters.mutex)
-
 /* Forward declarations */
 static PyObject *trace_call_function(
     PyThreadState *tstate, PyObject *callable, PyObject **stack,
diff --git a/Python/pystate.c b/Python/pystate.c
index f2f571f..bf9b8db 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -231,10 +231,6 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
 }
 #endif
 
-#define HEAD_LOCK(runtime) \
-    PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
-#define HEAD_UNLOCK(runtime) \
-    PyThread_release_lock((runtime)->interpreters.mutex)
 
 /* Forward declaration */
 static void _PyGILState_NoteThreadState(
-- 
cgit v0.12