8000 Make pkgcontext a thread-local variable. · python/cpython@83bbb3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 83bbb3a

Browse files
Make pkgcontext a thread-local variable.
1 parent b97e14a commit 83bbb3a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Python/import.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,28 +703,43 @@ _PyImport_ClearModulesByIndex(PyInterpreterState *interp)
703703
_PyRuntime.imports.pkgcontext, and PyModule_Create*() will
704704
substitute this (if the name actually matches).
705705
*/
706+
707+
#ifdef HAVE_THREAD_LOCAL
708+
_Py_thread_local const char *pkgcontext = NULL;
709+
# undef PKGCONTEXT
710+
# define PKGCONTEXT pkgcontext
711+
#endif
712+
706713
const char *
707714
_PyImport_ResolveNameWithPackageContext(const char *name)
708715
{
716+
#ifndef HAVE_THREAD_LOCAL
709717
PyThread_acquire_lock(EXTENSIONS.mutex, WAIT_LOCK);
718+
#endif
710719
if (PKGCONTEXT != NULL) {
711720
const char *p = strrchr(PKGCONTEXT, '.');
712721
if (p != NULL && strcmp(name, p+1) == 0) {
713722
name = PKGCONTEXT;
714723
PKGCONTEXT = NULL;
715724
}
716725
}
726+
#ifndef HAVE_THREAD_LOCAL
717727
PyThread_release_lock(EXTENSIONS.mutex);
728+
#endif
718729
return name;
719730
}
720731

721732
const char *
722733
_PyImport_SwapPackageContext(const char *newcontext)
723734
{
735+
#ifndef HAVE_THREAD_LOCAL
724736
PyThread_acquire_lock(EXTENSIONS.mutex, WAIT_LOCK);
737+
#endif
725738
const char *oldcontext = PKGCONTEXT;
726739
PKGCONTEXT = newcontext;
740+
#ifndef HAVE_THREAD_LOCAL
727741
PyThread_release_lock(EXTENSIONS.mutex);
742+
#endif
728743
return oldcontext;
729744
}
730745

0 commit comments

Comments
 (0)
0