Commit 4bb5a33e authored by Robert Bradshaw's avatar Robert Bradshaw

Conditionally use FastGil utility code.

parent c986610a
......@@ -2074,6 +2074,10 @@ class CCodeWriter(object):
"""
self.globalstate.use_utility_code(
UtilityCode.load_cached("ForceInitThreads", "ModuleSetupCode.c"))
if self.globalstate.directives['fast_gil']:
self.globalstate.use_utility_code(UtilityCode.load_cached("FastGil", "ModuleSetupCode.c"))
else:
self.globalstate.use_utility_code(UtilityCode.load_cached("NoFastGil", "ModuleSetupCode.c"))
self.putln("#ifdef WITH_THREAD")
if not variable:
variable = '__pyx_gilstate_save'
......@@ -2086,6 +2090,10 @@ class CCodeWriter(object):
"""
Releases the GIL, corresponds to `put_ensure_gil`.
"""
if self.globalstate.directives['fast_gil']:
self.globalstate.use_utility_code(UtilityCode.load_cached("FastGil", "ModuleSetupCode.c"))
else:
self.globalstate.use_utility_code(UtilityCode.load_cached("NoFastGil", "ModuleSetupCode.c"))
if not variable:
variable = '__pyx_gilstate_save'
self.putln("#ifdef WITH_THREAD")
......@@ -2097,6 +2105,10 @@ class CCodeWriter(object):
Acquire the GIL. The thread's thread state must have been initialized
by a previous `put_release_gil`
"""
if self.globalstate.directives['fast_gil']:
self.globalstate.use_utility_code(UtilityCode.load_cached("FastGil", "ModuleSetupCode.c"))
else:
self.globalstate.use_utility_code(UtilityCode.load_cached("NoFastGil", "ModuleSetupCode.c"))
self.putln("#ifdef WITH_THREAD")
self.putln("__Pyx_FastGIL_Forget();")
if variable:
......@@ -2106,6 +2118,10 @@ class CCodeWriter(object):
def put_release_gil(self, variable=None):
"Release the GIL, corresponds to `put_acquire_gil`."
if self.globalstate.directives['fast_gil']:
self.globalstate.use_utility_code(UtilityCode.load_cached("FastGil", "ModuleSetupCode.c"))
else:
self.globalstate.use_utility_code(UtilityCode.load_cached("NoFastGil", "ModuleSetupCode.c"))
self.putln("#ifdef WITH_THREAD")
self.putln("PyThreadState *_save;")
self.putln("Py_UNBLOCK_THREADS")
......
......@@ -719,10 +719,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if has_np_pythran(env):
env.use_utility_code(UtilityCode.load_cached("PythranConversion", "CppSupport.cpp"))
if env.directives['fast_gil']:
env.use_utility_code(UtilityCode.load_cached("FastGil", "ModuleSetupCode.c"))
else:
env.use_utility_code(UtilityCode.load_cached("NoFastGil", "ModuleSetupCode.c"))
def generate_extern_c_macro_definition(self, code):
name = Naming.extern_c_macro
......@@ -2155,7 +2151,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("%s = PyUnicode_FromStringAndSize(\"\", 0); %s" % (
Naming.empty_unicode, code.error_goto_if_null(Naming.empty_unicode, self.pos)))
code.putln("__Pyx_FastGilFuncInit();");
for ext_type in ('CyFunction', 'FusedFunction', 'Coroutine', 'Generator', 'StopAsyncIteration'):
code.putln("#ifdef __Pyx_%s_USED" % ext_type)
code.put_error_if_neg(self.pos, "__pyx_%s_init()" % ext_type)
......
......@@ -176,7 +176,7 @@ _directive_defaults = {
'unraisable_tracebacks': True,
'old_style_globals': False,
'np_pythran': False,
'fast_gil': False, # TODO(robertwb): Consider changing the default before releasing.
'fast_gil': True, # TODO(robertwb): Consider changing the default before releasing.
# set __file__ and/or __path__ to known source/target path at import time (instead of not having them available)
'set_initial_path' : None, # SOURCEFILE or "/full/path/to/module"
......
......@@ -864,6 +864,11 @@ static int __Pyx_RegisterCleanup(void) {
}
#endif
/////////////// FastGil.init ///////////////
#ifdef WITH_THREAD
__Pyx_FastGilFuncInit();
#endif
/////////////// NoFastGil.proto ///////////////
#define __Pyx_PyGILState_Ensure PyGILState_Ensure
......
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