Use Py_uintptr_t for atomic pointers · Lemooonred/cpython@b02ef71 · GitHub
Skip to content

Commit b02ef71

Browse files
committed
Use Py_uintptr_t for atomic pointers
Issue python#26161: Use Py_uintptr_t instead of void* for atomic pointers in pyatomic.h. Use atomic_uintptr_t when <stdatomic.h> is used. Using void* causes compilation warnings depending on which implementation of atomic types is used.
1 parent efb2413 commit b02ef71

3 files changed

Lines changed: 31 additions & 30 deletions

File tree

Include/pyatomic.h

Lines changed: 3 additions & 3 deletions

Python/ceval_gil.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static _Py_atomic_int gil_locked = {-1};
111111
static unsigned long gil_switch_number = 0;
112112
/* Last PyThreadState holding / having held the GIL. This helps us know
113113
whether anyone else was scheduled after we dropped the GIL. */
114-
static _Py_atomic_address gil_last_holder = {NULL};
114+
static _Py_atomic_address gil_last_holder = {0};
115115

116116
/* This condition variable allows one or several threads to wait until
117117
the GIL is released. In addition, the mutex also protects the above
@@ -142,7 +142,7 @@ static void create_gil(void)
142142
#ifdef FORCE_SWITCHING
143143
COND_INIT(switch_cond);
144144
#endif
145-
_Py_atomic_store_relaxed(&gil_last_holder, NULL);
145+
_Py_atomic_store_relaxed(&gil_last_holder, 0);
146146
_Py_ANNOTATE_RWLOCK_CREATE(&gil_locked);
147147
_Py_atomic_store_explicit(&gil_locked, 0, _Py_memory_order_release);
148148
}
@@ -178,7 +178,7 @@ static void drop_gil(PyThreadState *tstate)
178178
/* Sub-interpreter support: threads might have been switched
179179
under our feet using PyThreadState_Swap(). Fix the GIL last
180180
holder variable so that our heuristics work. */
181-
_Py_atomic_store_relaxed(&gil_last_holder, tstate);
181+
_Py_atomic_store_relaxed(&gil_last_holder, (Py_uintptr_t)tstate);
182182
}
183183

184184
MUTEX_LOCK(gil_mutex);
@@ -240,7 +240,7 @@ static void take_gil(PyThreadState *tstate)
240240
_Py_ANNOTATE_RWLOCK_ACQUIRED(&gil_locked, /*is_write=*/1);
241241

242242
if (tstate != (PyThreadState*)_Py_atomic_load_relaxed(&gil_last_holder)) {
243-
_Py_atomic_store_relaxed(&gil_last_holder, tstate);
243+
_Py_atomic_store_relaxed(&gil_last_holder, (Py_uintptr_t)tstate);
244244
++gil_switch_number;
245245
}
246246

Python/pystate.c

Lines changed: 24 additions & 23 deletions

0 commit comments

Comments
 (0)