@@ -386,9 +386,10 @@ def gen_tf_impl(self, m : MethodDef):
386
386
def gen_task_dispatch (self , api ):
387
387
self .println ("virtual task invokeTask(" )
388
388
self .inc_ind ()
389
- self .println ("output pyhdl_if::PyObject retval," )
390
- self .println ("input string method," )
391
- self .println ("input pyhdl_if::PyObject args);" )
389
+ self .println ("output pyhdl_if::PyObject retval," )
390
+ self .println ("inout pyhdl_if::PyGILState_STATE state," )
391
+ self .println ("input string method," )
392
+ self .println ("input pyhdl_if::PyObject args);" )
392
393
self .dec_ind ()
393
394
self .println ()
394
395
self .inc_ind ()
@@ -410,6 +411,7 @@ def gen_task_dispatch(self, api):
410
411
self .py2sv_func (p [1 ]),
411
412
i
412
413
))
414
+ self .println ("pyhdl_if::PyGILState_Release(state); // Release the GIL before invoking the task" )
413
415
self .write ("%s" % self ._ind )
414
416
self .write ("%s" % m .name )
415
417
if len (m .params ) == 0 :
@@ -429,6 +431,9 @@ def gen_task_dispatch(self, api):
429
431
"," if (i + 1 < len (m .params )) else ");"
430
432
))
431
433
self .dec_ind ()
434
+
435
+ self .println ("state = pyhdl_if::PyGILState_Ensure(); // Reacquire the GIL after invoking the task" )
436
+
432
437
if m .rtype is not None :
433
438
self .println ("retval = %s;" % self .sv2py_func (m .rtype , "__retval" ))
434
439
self .dec_ind ()
0 commit comments