cython-devel
changeset 1875:9a1f6f7c260a
thread initialisation when using with gil/nogil (by Lisandro)
| author | Stefan Behnel <scoder@users.berlios.de> |
|---|---|
| date | Thu Mar 19 10:50:40 2009 +0100 (2 years ago) |
| parents | 77bcc42bfb9d |
| children | a0c171b4cc68 |
| files | Cython/Compiler/ModuleNode.py Cython/Compiler/Nodes.py |
line diff
1.1 --- a/Cython/Compiler/ModuleNode.py Wed Mar 18 23:14:59 2009 -0700
1.2 +++ b/Cython/Compiler/ModuleNode.py Thu Mar 19 10:50:40 2009 +0100
1.3 @@ -1604,6 +1604,13 @@
1.4 env.generate_library_function_declarations(code)
1.5 self.generate_filename_init_call(code)
1.6
1.7 + code.putln("/*--- Threads initialization code ---*/")
1.8 + code.putln("#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS")
1.9 + code.putln("#ifdef WITH_THREAD")
1.10 + code.putln("PyEval_InitThreads();")
1.11 + code.putln("#endif")
1.12 + code.putln("#endif")
1.13 +
1.14 code.putln("/*--- Initialize various global constants etc. ---*/")
1.15 code.putln(code.error_goto_if_neg("__Pyx_InitGlobals()", self.pos))
1.16
2.1 --- a/Cython/Compiler/Nodes.py Wed Mar 18 23:14:59 2009 -0700
2.2 +++ b/Cython/Compiler/Nodes.py Thu Mar 19 10:50:40 2009 +0100
2.3 @@ -1075,6 +1075,7 @@
2.4 # ----- GIL acquisition
2.5 acquire_gil = self.need_gil_acquisition(lenv)
2.6 if acquire_gil:
2.7 + env.use_utility_code(py23_init_threads_utility_code)
2.8 code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
2.9 # ----- Automatic lead-ins for certain special functions
2.10 if not lenv.nogil:
2.11 @@ -4528,6 +4529,7 @@
2.12 finally_clause = GILExitNode(pos, state = state))
2.13
2.14 def analyse_expressions(self, env):
2.15 + env.use_utility_code(py23_init_threads_utility_code)
2.16 was_nogil = env.nogil
2.17 env.nogil = 1
2.18 TryFinallyStatNode.analyse_expressions(self, env)
2.19 @@ -5621,3 +5623,16 @@
2.20 """)
2.21
2.22 #------------------------------------------------------------------------------------
2.23 +
2.24 +py23_init_threads_utility_code = UtilityCode(
2.25 +proto="""
2.26 +#ifndef __PYX_FORCE_INIT_THREADS
2.27 +#define __PYX_FORCE_INIT_THREADS 0
2.28 +#if PY_VERSION_HEX < 0x02040000
2.29 +#undef __PYX_FORCE_INIT_THREADS
2.30 +#define __PYX_FORCE_INIT_THREADS 1
2.31 +#endif
2.32 +#endif
2.33 +""")
2.34 +
2.35 +#------------------------------------------------------------------------------------
