Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
63ec6c08
Commit
63ec6c08
authored
Feb 29, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved refnanny GIL handling code for nogil functions into a C macro
parent
bef95224
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
18 deletions
+24
-18
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+5
-2
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+13
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-14
No files found.
Cython/Compiler/Code.py
View file @
63ec6c08
...
...
@@ -1845,8 +1845,11 @@ class CCodeWriter(object):
def
put_declare_refcount_context
(
self
):
self
.
putln
(
'__Pyx_RefNannyDeclarations'
)
def
put_setup_refcount_context
(
self
,
name
):
self
.
putln
(
'__Pyx_RefNannySetupContext("%s");'
%
name
)
def
put_setup_refcount_context
(
self
,
name
,
acquire_gil
=
False
):
if
acquire_gil
:
from
Cython.Compiler
import
Nodes
self
.
globalstate
.
use_utility_code
(
Nodes
.
force_init_threads_utility_code
)
self
.
putln
(
'__Pyx_RefNannySetupContext("%s", %d);'
%
(
name
,
acquire_gil
and
1
or
0
))
def
put_finish_refcount_context
(
self
):
self
.
putln
(
"__Pyx_RefNannyFinishContext();"
)
...
...
Cython/Compiler/ModuleNode.py
View file @
63ec6c08
...
...
@@ -2742,8 +2742,19 @@ proto="""
static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
#define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#define __Pyx_RefNannySetupContext(name)
\
#ifdef WITH_THREAD
#define __Pyx_RefNannySetupContext(name, acquire_gil)
\
if (acquire_gil) {
\
PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
\
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);
\
PyGILState_Release(__pyx_gilstate_save);
\
} else {
\
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);
\
}
#else
#define __Pyx_RefNannySetupContext(name, acquire_gil)
\
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
#define __Pyx_RefNannyFinishContext()
\
__Pyx_RefNanny->FinishContext(&__pyx_refnanny)
#define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
...
...
@@ -2756,7 +2767,7 @@ proto="""
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
#define __Pyx_RefNannyDeclarations
#define __Pyx_RefNannySetupContext(name)
#define __Pyx_RefNannySetupContext(name
, acquire_gil
)
#define __Pyx_RefNannyFinishContext()
#define __Pyx_INCREF(r) Py_INCREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r)
...
...
Cython/Compiler/Nodes.py
View file @
63ec6c08
...
...
@@ -1504,22 +1504,14 @@ class FuncDefNode(StatNode, BlockNode):
if
acquire_gil
or
acquire_gil_for_var_decls_only
:
code
.
put_ensure_gil
()
elif
lenv
.
nogil
and
lenv
.
has_with_gil_block
:
code
.
declare_gilstate
()
# ----- set up refnanny
if
use_refnanny
:
if
acquire_gil_for_refnanny_only
:
code
.
declare_gilstate
()
code
.
putln
(
"#if CYTHON_REFNANNY"
)
code
.
put_ensure_gil
(
declare_gilstate
=
False
)
code
.
putln
(
"#endif /* CYTHON_REFNANNY */"
)
tempvardecl_code
.
put_declare_refcount_context
()
code
.
put_setup_refcount_context
(
self
.
entry
.
name
)
if
acquire_gil_for_refnanny_only
:
code
.
putln
(
"#if CYTHON_REFNANNY"
)
code
.
put_release_ensured_gil
()
code
.
putln
(
"#endif /* CYTHON_REFNANNY */"
)
code
.
put_setup_refcount_context
(
self
.
entry
.
name
,
acquire_gil
=
acquire_gil_for_refnanny_only
)
# ----- Automatic lead-ins for certain special functions
if
is_getbuffer_slot
:
...
...
@@ -1775,8 +1767,8 @@ class FuncDefNode(StatNode, BlockNode):
# GIL holding funcion
code
.
put_finish_refcount_context
()
if
(
acquire_gil
or
acquire_gil_for_var_decls_only
or
acquire_gil_for_refnanny_only
):
if
acquire_gil
or
(
lenv
.
nogil
and
lenv
.
has_with_gil_block
):
# release the GIL (note that with-gil blocks acquire it on exit in their EnsureGILNode)
code
.
put_release_ensured_gil
()
if
not
self
.
return_type
.
is_void
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment