[pypy-commit] cffi default: Add the dance of releasing the GIL.

arigo noreply at buildbot.pypy.org
Tue Jul 31 23:14:54 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r751:97aec18c45e7
Date: 2012-07-31 23:14 +0200
http://bitbucket.org/cffi/cffi/changeset/97aec18c45e7/

Log:	Add the dance of releasing the GIL.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1805,10 +1805,12 @@
 
     resultdata = buffer + cif_descr->exchange_offset_arg[0];
 
+    Py_BEGIN_ALLOW_THREADS
     restore_errno();
     ffi_call(&cif_descr->cif, (void (*)(void))(cd->c_data),
              resultdata, buffer_array);
     save_errno();
+    Py_END_ALLOW_THREADS
 
     if (fresult->ct_flags & (CT_PRIMITIVE_CHAR | CT_PRIMITIVE_SIGNED |
                              CT_PRIMITIVE_UNSIGNED)) {
@@ -3494,6 +3496,9 @@
 {
     save_errno();
     {
+#ifdef WITH_THREAD
+    PyGILState_STATE state = PyGILState_Ensure();
+#endif
     PyObject *cb_args = (PyObject *)userdata;
     CTypeDescrObject *ct = (CTypeDescrObject *)PyTuple_GET_ITEM(cb_args, 0);
     PyObject *signature = ct->ct_stuff;
@@ -3528,6 +3533,9 @@
     Py_XDECREF(py_args);
     Py_XDECREF(py_res);
     Py_DECREF(cb_args);
+#ifdef WITH_THREAD
+    PyGILState_Release(state);
+#endif
     restore_errno();
     return;
 
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -368,11 +368,13 @@
                                        'return NULL')
             prnt()
         #
+        prnt('  Py_BEGIN_ALLOW_THREADS')
         prnt('  _cffi_restore_errno();')
         prnt('  { %s%s(%s); }' % (
             result_code, name,
             ', '.join(['x%d' % i for i in range(len(tp.args))])))
         prnt('  _cffi_save_errno();')
+        prnt('  Py_END_ALLOW_THREADS')
         prnt()
         #
         if result_code:


More information about the pypy-commit mailing list