Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pygolang
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
Carlos Ramos Carreño
pygolang
Commits
c92a4830
Commit
c92a4830
authored
Sep 13, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libgolang: tests: waitBlocked: Allow to specify for how many receivers/senders should be blocked
This will be needed in the next patch.
parent
44737253
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
15 deletions
+13
-15
golang/_golang_test.pyx
golang/_golang_test.pyx
+7
-7
golang/runtime/libgolang_test.cpp
golang/runtime/libgolang_test.cpp
+6
-8
No files found.
golang/_golang_test.pyx
View file @
c92a4830
...
...
@@ -47,9 +47,9 @@ def pylen_sendq(pychan pych not None): # -> int
# runtime/libgolang_test.cpp
cdef
extern
from
*
:
"""
extern void waitBlocked(golang::_chan *ch,
bool rx, bool
tx);
extern void waitBlocked(golang::_chan *ch,
int nrx, int n
tx);
"""
void
waitBlocked
(
_chan
*
,
bint
rx
,
bint
tx
)
nogil
except
+
topyexc
void
waitBlocked
(
_chan
*
,
int
nrx
,
int
n
tx
)
nogil
except
+
topyexc
# pywaitBlocked waits till a receive or send pychan operation blocks waiting on the channel.
#
...
...
@@ -58,17 +58,17 @@ def pywaitBlocked(pychanop):
if
pychanop
.
__self__
.
__class__
is
not
pychan
:
pypanic
(
"wait blocked: %r is method of a non-chan: %r"
%
(
pychanop
,
pychanop
.
__self__
.
__class__
))
cdef
pychan
pych
=
pychanop
.
__self__
cdef
bint
recv
=
False
cdef
bint
send
=
False
cdef
int
nrecv
=
0
cdef
int
nsend
=
0
if
pychanop
.
__name__
==
"recv"
:
# XXX better check PyCFunction directly
recv
=
True
nrecv
=
1
elif
pychanop
.
__name__
==
"send"
:
# XXX better check PyCFunction directly
send
=
True
nsend
=
1
else
:
pypanic
(
"wait blocked: unexpected chan method: %r"
%
(
pychanop
,))
with
nogil
:
waitBlocked
(
pych
.
ch
.
_rawchan
(),
recv
,
send
)
waitBlocked
(
pych
.
ch
.
_rawchan
(),
nrecv
,
n
send
)
# `with pypanicWhenBlocked` hooks into libgolang _blockforever to raise panic with
...
...
golang/runtime/libgolang_test.cpp
View file @
c92a4830
...
...
@@ -144,17 +144,15 @@ void _test_chan_cpp() {
//chan<chan<int>> zzz;
}
// waitBlocked waits until
either a receive (if rx) or send (if tx) operation
//
blocks
waiting on the channel.
void
waitBlocked
(
_chan
*
ch
,
bool
rx
,
bool
tx
)
{
// waitBlocked waits until
at least nrx recv and ntx send operations block
// waiting on the channel.
void
waitBlocked
(
_chan
*
ch
,
int
nrx
,
int
n
tx
)
{
if
(
ch
==
NULL
)
panic
(
"wait blocked: called on nil channel"
);
double
t0
=
time
::
now
();
while
(
1
)
{
if
(
rx
&&
(
_tchanrecvqlen
(
ch
)
!=
0
))
return
;
if
(
tx
&&
(
_tchansendqlen
(
ch
)
!=
0
))
if
((
_tchanrecvqlen
(
ch
)
>=
nrx
)
&&
(
_tchansendqlen
(
ch
)
>=
ntx
))
return
;
double
now
=
time
::
now
();
...
...
@@ -165,10 +163,10 @@ void waitBlocked(_chan *ch, bool rx, bool tx) {
}
template
<
typename
T
>
void
waitBlocked_RX
(
chan
<
T
>
ch
)
{
waitBlocked
(
ch
.
_rawchan
(),
/*
rx=*/
true
,
/*
tx=*/
0
);
waitBlocked
(
ch
.
_rawchan
(),
/*
nrx=*/
1
,
/*n
tx=*/
0
);
}
template
<
typename
T
>
void
waitBlocked_TX
(
chan
<
T
>
ch
)
{
waitBlocked
(
ch
.
_rawchan
(),
/*
rx=*/
0
,
/*tx=*/
true
);
waitBlocked
(
ch
.
_rawchan
(),
/*
nrx=*/
0
,
/*ntx=*/
1
);
}
// usestack_and_call pushes C-stack down and calls f from that.
...
...
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