]> granicus.if.org Git - python/commitdiff
Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with...
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 15 Jan 2011 11:37:11 +0000 (11:37 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 15 Jan 2011 11:37:11 +0000 (11:37 +0000)
(we need some tests for this)

Python/ceval_gil.h

index 40e45f75f2e77988c70b28dd0e996370cbf0f995..bf7a350791f931dd0d1c2df2726e2b852aeaf681 100644 (file)
@@ -334,12 +334,15 @@ static void recreate_gil(void)
 
 static void drop_gil(PyThreadState *tstate)
 {
-    /* NOTE: tstate is allowed to be NULL. */
     if (!_Py_atomic_load_relaxed(&gil_locked))
         Py_FatalError("drop_gil: GIL is not locked");
-    if (tstate != NULL &&
-        tstate != _Py_atomic_load_relaxed(&gil_last_holder))
-        Py_FatalError("drop_gil: wrong thread state");
+    /* tstate is allowed to be NULL (early interpreter init) */
+    if (tstate != NULL) {
+        /* Sub-interpreter support: threads might have been switched
+           under our feet using PyThreadState_Swap(). Fix the GIL last
+           holder variable so that our heuristics work. */
+        _Py_atomic_store_relaxed(&gil_last_holder, tstate);
+    }
 
     MUTEX_LOCK(gil_mutex);
     _Py_ANNOTATE_RWLOCK_RELEASED(&gil_locked, /*is_write=*/1);