_PyRuntime.imports.pkgcontext, and PyModule_Create*() will
substitute this (if the name actually matches).
*/
+
+#ifdef HAVE_THREAD_LOCAL
+_Py_thread_local const char *pkgcontext = NULL;
+# undef PKGCONTEXT
+# define PKGCONTEXT pkgcontext
+#endif
+
const char *
_PyImport_ResolveNameWithPackageContext(const char *name)
{
+#ifndef HAVE_THREAD_LOCAL
PyThread_acquire_lock(EXTENSIONS.mutex, WAIT_LOCK);
+#endif
if (PKGCONTEXT != NULL) {
const char *p = strrchr(PKGCONTEXT, '.');
if (p != NULL && strcmp(name, p+1) == 0) {
PKGCONTEXT = NULL;
}
}
+#ifndef HAVE_THREAD_LOCAL
PyThread_release_lock(EXTENSIONS.mutex);
+#endif
return name;
}
const char *
_PyImport_SwapPackageContext(const char *newcontext)
{
+#ifndef HAVE_THREAD_LOCAL
PyThread_acquire_lock(EXTENSIONS.mutex, WAIT_LOCK);
+#endif
const char *oldcontext = PKGCONTEXT;
PKGCONTEXT = newcontext;
+#ifndef HAVE_THREAD_LOCAL
PyThread_release_lock(EXTENSIONS.mutex);
+#endif
return oldcontext;
}
extern |
register |
static |
+ _Thread_local |
typedef |
const |
#######################################
# variable declarations
-_STORAGE = 'auto register static extern'.split()
+_STORAGE = 'auto register static extern _Thread_local'.split()
STORAGE_CLASS = rf'(?: \b (?: {" | ".join(_STORAGE)} ) \b )'
TYPE_QUALIFIER = r'(?: \b (?: const | volatile ) \b )'
PTR_QUALIFIER = rf'(?: [*] (?: \s* {TYPE_QUALIFIER} )? )'
line = line[m.end():]
line = re.sub(r'__extension__', '', line)
+ line = re.sub(r'__thread\b', '_Thread_local', line)
while (m := COMPILER_DIRECTIVE_RE.match(line)):
before, _, _, closed = m.groups()
Python/pyfpe.c - PyFPE_counter -
+##-----------------------
+## thread-local variables
+
+Python/import.c - pkgcontext -
+Python/pystate.c - _Py_tss_tstate -
+
##-----------------------
## should be const
# XXX Make them const.