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
e9367c94
Commit
e9367c94
authored
Jun 24, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First attempt of non-blocking locks for acthon message activate method
parent
a4ad0e54
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
3 deletions
+77
-3
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+77
-3
No files found.
Cython/Compiler/ModuleNode.py
View file @
e9367c94
...
...
@@ -1322,10 +1322,84 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# because the mode is used for direct calls, when the user have the possibility
# to manually lock or let the compiler handle it.
# Here, the user cannot lock manually, so we're taking the lock automatically.
put_cypclass_op_on_narg_optarg
(
lambda
arg
:
"Cy_RLOCK"
if
arg
.
type
.
is_const
else
"Cy_WLOCK"
,
reified_function_entry
.
type
,
Naming
.
optional_args_cname
,
code
)
#put_cypclass_op_on_narg_optarg(lambda arg: "Cy_RLOCK" if arg.type.is_const else "Cy_WLOCK", reified_function_entry.type, Naming.optional_args_cname, code)
func_type
=
reified_function_entry
.
type
opt_arg_name
=
Naming
.
optional_args_cname
trylock_result
=
"trylock_result"
failed_trylock
=
"failed_trylock"
code
.
putln
(
"int %s = 0;"
%
trylock_result
)
code
.
putln
(
"int %s = 0;"
%
failed_trylock
)
opt_arg_count
=
func_type
.
optional_arg_count
narg_count
=
len
(
func_type
.
args
)
-
opt_arg_count
num_trylock
=
1
op
=
"Cy_TRYRLOCK"
if
reified_function_entry
.
type
.
is_const_method
else
"Cy_TRYWLOCK"
code
.
putln
(
"%s = %s(this->%s) != 0;"
%
(
failed_trylock
,
op
,
target_object_cname
))
code
.
putln
(
"if (!%s) {"
%
failed_trylock
)
code
.
putln
(
"++%s;"
%
trylock_result
)
for
i
,
narg
in
enumerate
(
func_type
.
args
[:
narg_count
]):
if
narg
.
type
.
is_cyp_class
:
try_op
=
"Cy_TRYRLOCK"
if
narg
.
type
.
is_const
else
"Cy_TRYWLOCK"
code
.
putln
(
"%s = %s(this->%s) != 0;"
%
(
failed_trylock
,
try_op
,
narg
.
cname
))
code
.
putln
(
"if (!%s) {"
%
failed_trylock
)
code
.
putln
(
"++%s;"
%
trylock_result
)
num_trylock
+=
1
if
opt_arg_count
:
num_optional_if
=
0
code
.
putln
(
"if (this->%s != NULL) {"
%
opt_arg_name
)
for
opt_idx
,
optarg
in
enumerate
(
func_type
.
args
[
narg_count
:]):
if
optarg
.
type
.
is_cyp_class
:
try_op
=
"Cy_TRYRLOCK"
if
optarg
.
type
.
is_const
else
"Cy_TRYWLOCK"
code
.
putln
(
"if (this->%s->%sn > %s) {"
%
(
opt_arg_name
,
Naming
.
pyrex_prefix
,
opt_idx
,
))
code
.
putln
(
"%s = %s(this->%s->%s) != 0;"
%
(
failed_trylock
,
try_op
,
opt_arg_name
,
func_type
.
opt_arg_cname
(
optarg
.
name
)
))
code
.
putln
(
"if (!%s) {"
%
failed_trylock
)
code
.
putln
(
"++%s;"
%
trylock_result
)
num_optional_if
+=
1
num_trylock
+=
1
for
_
in
range
(
num_optional_if
):
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
# The check for optional_args != NULL
for
_
in
range
(
num_trylock
):
code
.
putln
(
"}"
)
op
=
"Cy_RLOCK"
if
reified_function_entry
.
type
.
is_const_method
else
"Cy_WLOCK"
code
.
putln
(
"%s(this->%s);"
%
(
op
,
target_object_cname
))
if
num_trylock
:
# If there is any lock failure, we unlock all and return 0
code
.
putln
(
"if (%s) {"
%
failed_trylock
)
num_unlock
=
0
# Target object first, then arguments
code
.
putln
(
"if (%s > %s) {"
%
(
trylock_result
,
num_unlock
))
code
.
putln
(
"Cy_UNLOCK(this->%s);"
%
target_object_cname
)
num_unlock
+=
1
for
i
,
narg
in
enumerate
(
func_type
.
args
[:
narg_count
]):
if
narg
.
type
.
is_cyp_class
:
code
.
putln
(
"if (%s > %s) {"
%
(
trylock_result
,
num_unlock
))
code
.
putln
(
"Cy_UNLOCK(this->%s);"
%
narg
.
cname
)
num_unlock
+=
1
if
opt_arg_count
:
code
.
putln
(
"if (this->%s != NULL) {"
%
opt_arg_name
)
for
opt_idx
,
optarg
in
enumerate
(
func_type
.
args
[
narg_count
:]):
if
optarg
.
type
.
is_cyp_class
:
code
.
putln
(
"if (%s > %s) {"
%
(
trylock_result
,
num_unlock
))
code
.
putln
(
"Cy_UNLOCK(this->%s->%s);"
%
(
opt_arg_name
,
func_type
.
opt_arg_cname
(
optarg
.
name
)))
num_unlock
+=
1
for
_
in
range
(
num_unlock
):
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
code
.
putln
(
"return 0;"
)
code
.
putln
(
"}"
)
does_return
=
reified_function_entry
.
type
.
return_type
is
not
PyrexTypes
.
c_void_type
if
does_return
:
...
...
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