mirror of
https://github.com/python/cpython.git
synced 2025-09-22 16:33:26 +00:00
Add sanity assertions in some import lock code (issue #15599).
This commit is contained in:
parent
5b89840d9c
commit
202b60640b
2 changed files with 3 additions and 0 deletions
|
@ -68,6 +68,7 @@ class Finder:
|
||||||
# Simulate some thread-unsafe behaviour. If calls to find_module()
|
# Simulate some thread-unsafe behaviour. If calls to find_module()
|
||||||
# are properly serialized, `x` will end up the same as `numcalls`.
|
# are properly serialized, `x` will end up the same as `numcalls`.
|
||||||
# Otherwise not.
|
# Otherwise not.
|
||||||
|
assert imp.lock_held()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.numcalls += 1
|
self.numcalls += 1
|
||||||
x = self.x
|
x = self.x
|
||||||
|
|
|
@ -169,6 +169,7 @@ _PyImport_AcquireLock(void)
|
||||||
PyThread_acquire_lock(import_lock, 1);
|
PyThread_acquire_lock(import_lock, 1);
|
||||||
PyEval_RestoreThread(tstate);
|
PyEval_RestoreThread(tstate);
|
||||||
}
|
}
|
||||||
|
assert(import_lock_level == 0);
|
||||||
import_lock_thread = me;
|
import_lock_thread = me;
|
||||||
import_lock_level = 1;
|
import_lock_level = 1;
|
||||||
}
|
}
|
||||||
|
@ -182,6 +183,7 @@ _PyImport_ReleaseLock(void)
|
||||||
if (import_lock_thread != me)
|
if (import_lock_thread != me)
|
||||||
return -1;
|
return -1;
|
||||||
import_lock_level--;
|
import_lock_level--;
|
||||||
|
assert(import_lock_level >= 0);
|
||||||
if (import_lock_level == 0) {
|
if (import_lock_level == 0) {
|
||||||
import_lock_thread = -1;
|
import_lock_thread = -1;
|
||||||
PyThread_release_lock(import_lock);
|
PyThread_release_lock(import_lock);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue