Commit 9687773f authored by Stefan Behnel's avatar Stefan Behnel

thread initialisation when using with gil/nogil (by Lisandro)

parent 7424de83
...@@ -1604,6 +1604,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1604,6 +1604,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env.generate_library_function_declarations(code) env.generate_library_function_declarations(code)
self.generate_filename_init_call(code) self.generate_filename_init_call(code)
code.putln("/*--- Threads initialization code ---*/")
code.putln("#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS")
code.putln("#ifdef WITH_THREAD")
code.putln("PyEval_InitThreads();")
code.putln("#endif")
code.putln("#endif")
code.putln("/*--- Initialize various global constants etc. ---*/") code.putln("/*--- Initialize various global constants etc. ---*/")
code.putln(code.error_goto_if_neg("__Pyx_InitGlobals()", self.pos)) code.putln(code.error_goto_if_neg("__Pyx_InitGlobals()", self.pos))
......
...@@ -1075,6 +1075,7 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1075,6 +1075,7 @@ class FuncDefNode(StatNode, BlockNode):
# ----- GIL acquisition # ----- GIL acquisition
acquire_gil = self.need_gil_acquisition(lenv) acquire_gil = self.need_gil_acquisition(lenv)
if acquire_gil: if acquire_gil:
env.use_utility_code(py23_init_threads_utility_code)
code.putln("PyGILState_STATE _save = PyGILState_Ensure();") code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
# ----- Automatic lead-ins for certain special functions # ----- Automatic lead-ins for certain special functions
if not lenv.nogil: if not lenv.nogil:
...@@ -4528,6 +4529,7 @@ class GILStatNode(TryFinallyStatNode): ...@@ -4528,6 +4529,7 @@ class GILStatNode(TryFinallyStatNode):
finally_clause = GILExitNode(pos, state = state)) finally_clause = GILExitNode(pos, state = state))
def analyse_expressions(self, env): def analyse_expressions(self, env):
env.use_utility_code(py23_init_threads_utility_code)
was_nogil = env.nogil was_nogil = env.nogil
env.nogil = 1 env.nogil = 1
TryFinallyStatNode.analyse_expressions(self, env) TryFinallyStatNode.analyse_expressions(self, env)
...@@ -5621,3 +5623,16 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) ...@@ -5621,3 +5623,16 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb)
""") """)
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
py23_init_threads_utility_code = UtilityCode(
proto="""
#ifndef __PYX_FORCE_INIT_THREADS
#define __PYX_FORCE_INIT_THREADS 0
#if PY_VERSION_HEX < 0x02040000
#undef __PYX_FORCE_INIT_THREADS
#define __PYX_FORCE_INIT_THREADS 1
#endif
#endif
""")
#------------------------------------------------------------------------------------
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment