extern "C" {
#endif
+#include "pycore_lock.h"
+
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
};
struct _py_func_state {
+#ifdef Py_GIL_DISABLED
+ // Protects next_version
+ PyMutex mutex;
+#endif
+
uint32_t next_version;
// Borrowed references to function and code objects whose
// func_version % FUNC_VERSION_CACHE_SIZE
co->co_ncellvars = ncellvars;
co->co_nfreevars = nfreevars;
PyInterpreterState *interp = _PyInterpreterState_GET();
+#ifdef Py_GIL_DISABLED
+ PyMutex_Lock(&interp->func_state.mutex);
+#endif
co->co_version = interp->func_state.next_version;
if (interp->func_state.next_version != 0) {
interp->func_state.next_version++;
}
+#ifdef Py_GIL_DISABLED
+ PyMutex_Unlock(&interp->func_state.mutex);
+#endif
co->_co_monitoring = NULL;
co->_co_instrumentation_version = 0;
/* not set */
void
_PyFunction_SetVersion(PyFunctionObject *func, uint32_t version)
{
+#ifndef Py_GIL_DISABLED
PyInterpreterState *interp = _PyInterpreterState_GET();
if (func->func_version != 0) {
struct _func_version_cache_item *slot =
// Leave slot->code alone, there may be use for it.
}
}
+#endif
func->func_version = version;
+#ifndef Py_GIL_DISABLED
if (version != 0) {
struct _func_version_cache_item *slot =
interp->func_state.func_version_cache
slot->func = func;
slot->code = func->func_code;
}
+#endif
}
void
_PyFunction_ClearCodeByVersion(uint32_t version)
{
+#ifndef Py_GIL_DISABLED
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _func_version_cache_item *slot =
interp->func_state.func_version_cache
slot->func = NULL;
}
}
+#endif
}
PyFunctionObject *
_PyFunction_LookupByVersion(uint32_t version, PyObject **p_code)
{
+#ifdef Py_GIL_DISABLED
+ return NULL;
+#else
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _func_version_cache_item *slot =
interp->func_state.func_version_cache
return slot->func;
}
return NULL;
+#endif
}
uint32_t
race:_in_weak_set
race:_mi_heap_delayed_free_partial
race:_PyEval_EvalFrameDefault
-race:_PyFunction_SetVersion
race:_PyImport_AcquireLock
race:_PyImport_ReleaseLock
race:_PyInterpreterState_SetNotRunningMain