goto not_found;
}
+#ifndef Py_GIL_DISABLED
if (var->var_cached != NULL &&
var->var_cached_tsid == ts->id &&
var->var_cached_tsver == ts->context_ver)
*val = var->var_cached;
goto found;
}
+#endif
assert(PyContext_CheckExact(ts->context));
PyHamtObject *vars = ((PyContext *)ts->context)->ctx_vars;
}
if (res == 1) {
assert(found != NULL);
+#ifndef Py_GIL_DISABLED
var->var_cached = found; /* borrow */
var->var_cached_tsid = ts->id;
var->var_cached_tsver = ts->context_ver;
+#endif
*val = found;
goto found;
static int
contextvar_set(PyContextVar *var, PyObject *val)
{
+#ifndef Py_GIL_DISABLED
var->var_cached = NULL;
PyThreadState *ts = _PyThreadState_GET();
+#endif
PyContext *ctx = context_get();
if (ctx == NULL) {
Py_SETREF(ctx->ctx_vars, new_vars);
+#ifndef Py_GIL_DISABLED
var->var_cached = val; /* borrow */
var->var_cached_tsid = ts->id;
var->var_cached_tsver = ts->context_ver;
+#endif
return 0;
}
static int
contextvar_del(PyContextVar *var)
{
+#ifndef Py_GIL_DISABLED
var->var_cached = NULL;
+#endif
PyContext *ctx = context_get();
if (ctx == NULL) {
var->var_default = Py_XNewRef(def);
+#ifndef Py_GIL_DISABLED
var->var_cached = NULL;
var->var_cached_tsid = 0;
var->var_cached_tsver = 0;
+#endif
if (_PyObject_GC_MAY_BE_TRACKED(name) ||
(def != NULL && _PyObject_GC_MAY_BE_TRACKED(def)))
{
Py_CLEAR(self->var_name);
Py_CLEAR(self->var_default);
+#ifndef Py_GIL_DISABLED
self->var_cached = NULL;
self->var_cached_tsid = 0;
self->var_cached_tsver = 0;
+#endif
return 0;
}