diff options
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Python/import.c b/Python/import.c index 0fc4d1d..17a320b 100644 --- a/Python/import.c +++ b/Python/import.c @@ -147,14 +147,14 @@ _PyImportZip_Init(void) #include "pythread.h" static PyThread_type_lock import_lock = 0; -static long import_lock_thread = -1; +static unsigned long import_lock_thread = PYTHREAD_INVALID_THREAD_ID; static int import_lock_level = 0; void _PyImport_AcquireLock(void) { - long me = PyThread_get_thread_ident(); - if (me == -1) + unsigned long me = PyThread_get_thread_ident(); + if (me == PYTHREAD_INVALID_THREAD_ID) return; /* Too bad */ if (import_lock == NULL) { import_lock = PyThread_allocate_lock(); @@ -165,7 +165,8 @@ _PyImport_AcquireLock(void) import_lock_level++; return; } - if (import_lock_thread != -1 || !PyThread_acquire_lock(import_lock, 0)) + if (import_lock_thread != PYTHREAD_INVALID_THREAD_ID || + !PyThread_acquire_lock(import_lock, 0)) { PyThreadState *tstate = PyEval_SaveThread(); PyThread_acquire_lock(import_lock, 1); @@ -179,15 +180,15 @@ _PyImport_AcquireLock(void) int _PyImport_ReleaseLock(void) { - long me = PyThread_get_thread_ident(); - if (me == -1 || import_lock == NULL) + unsigned long me = PyThread_get_thread_ident(); + if (me == PYTHREAD_INVALID_THREAD_ID || import_lock == NULL) return 0; /* Too bad */ if (import_lock_thread != me) return -1; import_lock_level--; assert(import_lock_level >= 0); if (import_lock_level == 0) { - import_lock_thread = -1; + import_lock_thread = PYTHREAD_INVALID_THREAD_ID; PyThread_release_lock(import_lock); } return 1; @@ -209,7 +210,7 @@ _PyImport_ReInitLock(void) } if (import_lock_level > 1) { /* Forked as a side effect of import */ - long me = PyThread_get_thread_ident(); + unsigned long me = PyThread_get_thread_ident(); /* The following could fail if the lock is already held, but forking as a side-effect of an import is a) rare, b) nuts, and c) difficult to do thanks to the lock only being held when doing individual module @@ -218,7 +219,7 @@ _PyImport_ReInitLock(void) import_lock_thread = me; import_lock_level--; } else { - import_lock_thread = -1; + import_lock_thread = PYTHREAD_INVALID_THREAD_ID; import_lock_level = 0; } } @@ -238,7 +239,7 @@ _imp_lock_held_impl(PyObject *module) /*[clinic end generated code: output=8b89384b5e1963fc input=9b088f9b217d9bdf]*/ { #ifdef WITH_THREAD - return PyBool_FromLong(import_lock_thread != -1); + return PyBool_FromLong(import_lock_thread != PYTHREAD_INVALID_THREAD_ID); #else Py_RETURN_FALSE; #endif |