Ticket #185: python-gil-pruning.patch
File python-gil-pruning.patch, 2.8 KB (added by , 16 years ago) |
---|
-
Source/Modules/python.cxx
188 188 if (bb) { 189 189 Append(f, bb); 190 190 } else { 191 Append(f, "{ PyEval_AcquireLock(); PyEval_ReleaseLock(); } // Will deadlock if GIL already held by this thread.\n"); 191 192 Append(f, "SWIG_PYTHON_THREAD_BEGIN_BLOCK;\n"); 192 193 } 193 194 } … … 200 201 Append(f, eb); 201 202 } else { 202 203 Append(f, "SWIG_PYTHON_THREAD_END_BLOCK;\n"); 204 Append(f, "{ PyEval_AcquireLock(); PyEval_ReleaseLock(); } // Will deadlock if GIL already held by this thread.\n"); 203 205 } 204 206 } 205 207 } … … 1497 1499 Wrapper_add_local(f, "argc", "int argc"); 1498 1500 Printf(tmp, "PyObject *argv[%d]", maxargs + 1); 1499 1501 Wrapper_add_local(f, "argv", tmp); 1500 if (allow_thread )1501 thread_begin_block(n, f->code);1502 if (allow_thread && !GetFlag(n, "feature:nothreadblock")) 1503 Append(f->code, "(void)PyThreadState_Get(); // Aborts if GIL not held\n"); 1502 1504 1503 1505 if (!fastunpack) { 1504 1506 Wrapper_add_local(f, "ii", "int ii"); … … 1517 1519 1518 1520 if (allow_thread) { 1519 1521 String *ret = NewStringEmpty(); 1520 thread_end_block(n, ret); 1522 if (allow_thread && !GetFlag(n, "feature:nothreadblock")) 1523 Append(ret, "(void)PyThreadState_Get(); // Aborts if GIL not held\n"); 1521 1524 Append(ret, "return "); 1522 1525 Replaceall(dispatch, "return ", ret); 1523 1526 Delete(ret); … … 1525 1528 1526 1529 Printv(f->code, dispatch, "\n", NIL); 1527 1530 1528 if (allow_thread )1529 thread_end_block(n, f->code);1531 if (allow_thread && !GetFlag(n, "feature:nothreadblock")) 1532 Append(f->code, "(void)PyThreadState_Get(); // Aborts if GIL not held\n"); 1530 1533 1531 1534 if (GetFlag(n, "feature:python:maybecall")) { 1532 1535 Append(f->code, "fail:\n"); … … 1634 1637 kwargs = NewString(""); 1635 1638 1636 1639 int allow_thread = threads_enable(n); 1637 if (allow_thread )1638 thread_begin_block(n, f->code);1640 if (allow_thread && !GetFlag(n, "feature:nothreadblock")) 1641 Append(f->code, "(void)PyThreadState_Get(); // Aborts if GIL not held\n"); 1639 1642 1640 1643 Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0"); 1641 1644 … … 2066 2069 } 2067 2070 } 2068 2071 2069 if (allow_thread )2070 thread_end_block(n, f->code);2072 if (allow_thread && !GetFlag(n, "feature:nothreadblock")) 2073 Append(f->code, "(void)PyThreadState_Get(); // Aborts if GIL not held\n"); 2071 2074 Append(f->code, " return resultobj;\n"); 2072 2075 2073 2076 /* Error handling code */ … … 2076 2079 if (need_cleanup) { 2077 2080 Printv(f->code, cleanup, NIL); 2078 2081 } 2079 if (allow_thread )2080 thread_end_block(n, f->code);2082 if (allow_thread && !GetFlag(n, "feature:nothreadblock")) 2083 Append(f->code, "(void)PyThreadState_Get(); // Aborts if GIL not held\n"); 2081 2084 Printv(f->code, ctab4, "return NULL;\n", NIL); 2082 2085 2083 2086