Use Py_uintptr_t for atomic pointers

Issue #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.
This commit is contained in:
Victor Stinner 2016-01-22 14:09:55 +01:00
parent 4b8b86c6d5
commit 244e12088d
3 changed files with 31 additions and 30 deletions

View file

@ -111,7 +111,7 @@ static _Py_atomic_int gil_locked = {-1};
static unsigned long gil_switch_number = 0;
/* Last PyThreadState holding / having held the GIL. This helps us know
whether anyone else was scheduled after we dropped the GIL. */
static _Py_atomic_address gil_last_holder = {NULL};
static _Py_atomic_address gil_last_holder = {0};
/* This condition variable allows one or several threads to wait until
the GIL is released. In addition, the mutex also protects the above
@ -142,7 +142,7 @@ static void create_gil(void)
#ifdef FORCE_SWITCHING
COND_INIT(switch_cond);
#endif
_Py_atomic_store_relaxed(&gil_last_holder, NULL);
_Py_atomic_store_relaxed(&gil_last_holder, 0);
_Py_ANNOTATE_RWLOCK_CREATE(&gil_locked);
_Py_atomic_store_explicit(&gil_locked, 0, _Py_memory_order_release);
}
@ -178,7 +178,7 @@ static void drop_gil(PyThreadState *tstate)
/* Sub-interpreter support: threads might have been switched
under our feet using PyThreadState_Swap(). Fix the GIL last
holder variable so that our heuristics work. */
_Py_atomic_store_relaxed(&gil_last_holder, tstate);
_Py_atomic_store_relaxed(&gil_last_holder, (Py_uintptr_t)tstate);
}
MUTEX_LOCK(gil_mutex);
@ -240,7 +240,7 @@ _ready:
_Py_ANNOTATE_RWLOCK_ACQUIRED(&gil_locked, /*is_write=*/1);
if (tstate != (PyThreadState*)_Py_atomic_load_relaxed(&gil_last_holder)) {
_Py_atomic_store_relaxed(&gil_last_holder, tstate);
_Py_atomic_store_relaxed(&gil_last_holder, (Py_uintptr_t)tstate);
++gil_switch_number;
}