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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
5f192afb
Commit
5f192afb
authored
Aug 25, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use scope-bound lock guards to manage cypclass locks
parent
1bb76726
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
11 deletions
+65
-11
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+11
-6
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+1
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+11
-5
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+42
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
5f192afb
...
...
@@ -14068,6 +14068,7 @@ class CoerceToTempNode(CoercionNode):
class
CoerceToLockedTempNode
(
CoerceToTempNode
):
# rlock_only boolean
# guard_code used internally
def
__init__
(
self
,
arg
,
env
=
None
,
rlock_only
=
False
):
self
.
rlock_only
=
rlock_only
...
...
@@ -14089,16 +14090,20 @@ class CoerceToLockedTempNode(CoerceToTempNode):
context
=
code
.
get_string_const
(
StringEncoding
.
EncodedString
(
context
))
else
:
context
=
"NULL"
# Create a scope to use scope bound resource management (RAII).
code
.
putln
(
"{"
)
# Each lock guard has its onw scope, so a prefix is enough to prevent name collisions
guard_code
=
"%sguard"
%
Naming
.
cypclass_lock_guard_prefix
if
self
.
rlock_only
:
code
.
putln
(
"Cy_
RLOCK_CONTEXT(%s, %s);"
%
(
self
.
result
(),
context
))
code
.
putln
(
"Cy_
rlock_guard %s(%s, %s);"
%
(
guard_code
,
self
.
result
(),
context
))
else
:
code
.
putln
(
"Cy_
WLOCK_CONTEXT(%s, %s);"
%
(
self
.
result
(),
context
))
code
.
putln
(
"Cy_
wlock_guard %s(%s, %s);"
%
(
guard_code
,
self
.
result
(),
context
))
def
generate_disposal_code
(
self
,
code
):
if
self
.
rlock_only
:
code
.
putln
(
"Cy_UNRLOCK(%s);"
%
self
.
result
())
else
:
code
.
putln
(
"Cy_UNWLOCK(%s);"
%
self
.
result
())
# Close the scope to release the lock.
code
.
putln
(
"}"
)
super
(
CoerceToLockedTempNode
,
self
).
generate_disposal_code
(
code
)
...
...
Cython/Compiler/Naming.py
View file @
5f192afb
...
...
@@ -58,6 +58,7 @@ convert_func_prefix = pyrex_prefix + "convert_"
closure_scope_prefix
=
pyrex_prefix
+
"scope_"
closure_class_prefix
=
pyrex_prefix
+
"scope_struct_"
lambda_func_prefix
=
pyrex_prefix
+
"lambda_"
cypclass_lock_guard_prefix
=
pyrex_prefix
+
"cy_lock_"
module_is_main
=
pyrex_prefix
+
"module_is_main"
defaults_struct_prefix
=
pyrex_prefix
+
"defaults"
dynamic_args_cname
=
pyrex_prefix
+
"dynamic_args"
...
...
Cython/Compiler/Nodes.py
View file @
5f192afb
...
...
@@ -8579,15 +8579,21 @@ class LockCypclassNode(StatNode):
context
=
code
.
get_string_const
(
EncodedString
(
context
))
else
:
context
=
"NULL"
lock_code
=
"Cy_%s_CONTEXT(%s, %s);"
%
(
self
.
state
[:
-
2
].
upper
(),
self
.
obj
.
result
(),
context
)
code
.
putln
(
lock_code
)
self
.
body
.
generate_execution_code
(
code
)
# Create a scope to use scope bound resource management (RAII).
code
.
putln
(
"{"
)
# Each lock guard has its onw scope, so a prefix is enough to prevent name collisions
guard_code
=
"%sguard"
%
Naming
.
cypclass_lock_guard_prefix
if
self
.
state
==
"rlocked"
:
code
.
putln
(
"Cy_
UNRLOCK(%s);"
%
self
.
obj
.
result
(
))
code
.
putln
(
"Cy_
rlock_guard %s(%s, %s);"
%
(
guard_code
,
self
.
obj
.
result
(),
context
))
elif
self
.
state
==
"wlocked"
:
code
.
putln
(
"Cy_UNWLOCK(%s);"
%
self
.
obj
.
result
())
code
.
putln
(
"Cy_wlock_guard %s(%s ,%s);"
%
(
guard_code
,
self
.
obj
.
result
(),
context
))
self
.
body
.
generate_execution_code
(
code
)
# Close the scope to release the lock.
code
.
putln
(
"}"
)
def
cython_view_utility_code
():
...
...
Cython/Utility/CyObjects.cpp
View file @
5f192afb
...
...
@@ -88,6 +88,48 @@
int
CyObject_TRYWLOCK
();
};
class
Cy_rlock_guard
{
CyObject
*
o
;
public:
Cy_rlock_guard
(
CyObject
*
o
,
const
char
*
context
)
:
o
(
o
)
{
if
(
o
!=
NULL
)
{
o
->
CyObject_RLOCK
(
context
);
}
else
{
fprintf
(
stderr
,
"ERROR: trying to rlock NULL !
\n
"
);
}
}
~
Cy_rlock_guard
()
{
if
(
this
->
o
!=
NULL
)
{
this
->
o
->
CyObject_UNRLOCK
();
}
else
{
fprintf
(
stderr
,
"ERROR: trying to unrlock NULL !
\n
"
);
}
}
};
class
Cy_wlock_guard
{
CyObject
*
o
;
public:
Cy_wlock_guard
(
CyObject
*
o
,
const
char
*
context
)
:
o
(
o
)
{
if
(
o
!=
NULL
)
{
o
->
CyObject_WLOCK
(
context
);
}
else
{
fprintf
(
stderr
,
"ERROR: trying to wlock NULL !
\n
"
);
}
}
~
Cy_wlock_guard
()
{
if
(
this
->
o
!=
NULL
)
{
this
->
o
->
CyObject_UNWLOCK
();
}
else
{
fprintf
(
stderr
,
"ERROR: trying to unwlock NULL !
\n
"
);
}
}
};
/* All this is made available by member injection inside the module scope */
struct
ActhonResultInterface
:
public
CyObject
{
...
...
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