Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
653cef1b
Commit
653cef1b
authored
Aug 26, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Close() and Closed() to ChanValue
R=r DELTA=60 (56 added, 3 deleted, 1 changed) OCL=33868 CL=33872
parent
06c2c894
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
5 deletions
+58
-5
all_test.go
src/pkg/reflect/all_test.go
+19
-0
value.go
src/pkg/reflect/value.go
+14
-0
chan.c
src/pkg/runtime/chan.c
+14
-4
reflect.cgo
src/pkg/runtime/reflect.cgo
+8
-0
runtime.h
src/pkg/runtime/runtime.h
+3
-1
No files found.
src/pkg/reflect/all_test.go
View file @
653cef1b
...
...
@@ -726,6 +726,25 @@ func TestChan(t *testing.T) {
t
.
Errorf
(
"TrySend 6, recv %d"
,
i
);
}
}
// Close
c
<-
123
;
cv
.
Close
();
if
cv
.
Closed
()
{
t
.
Errorf
(
"closed too soon - 1"
);
}
if
i
:=
cv
.
Recv
()
.
(
*
IntValue
)
.
Get
();
i
!=
123
{
t
.
Errorf
(
"send 123 then close; Recv %d"
,
i
);
}
if
cv
.
Closed
()
{
t
.
Errorf
(
"closed too soon - 2"
);
}
if
i
:=
cv
.
Recv
()
.
(
*
IntValue
)
.
Get
();
i
!=
0
{
t
.
Errorf
(
"after close Recv %d"
,
i
);
}
if
!
cv
.
Closed
()
{
t
.
Errorf
(
"not closed"
);
}
}
// check creation of unbuffered channel
...
...
src/pkg/reflect/value.go
View file @
653cef1b
...
...
@@ -634,6 +634,20 @@ func (v *ChanValue) Get() uintptr {
func
makechan
(
typ
*
runtime
.
ChanType
,
size
uint32
)
(
ch
*
byte
)
func
chansend
(
ch
,
val
*
byte
,
pres
*
bool
)
func
chanrecv
(
ch
,
val
*
byte
,
pres
*
bool
)
func
chanclosed
(
ch
*
byte
)
bool
func
chanclose
(
ch
*
byte
)
// Closed returns the result of closed(c) on the underlying channel.
func
(
v
*
ChanValue
)
Closed
()
bool
{
ch
:=
*
(
**
byte
)(
v
.
addr
);
return
chanclosed
(
ch
);
}
// Close closes the channel.
func
(
v
*
ChanValue
)
Close
()
{
ch
:=
*
(
**
byte
)(
v
.
addr
);
chanclose
(
ch
);
}
// internal send; non-blocking if b != nil
func
(
v
*
ChanValue
)
send
(
x
Value
,
b
*
bool
)
{
...
...
src/pkg/runtime/chan.c
View file @
653cef1b
...
...
@@ -905,14 +905,24 @@ sys·closechan(Hchan *c)
unlock
(
&
chanlock
);
}
void
chanclose
(
Hchan
*
c
)
{
sys
·
closechan
(
c
);
}
bool
chanclosed
(
Hchan
*
c
)
{
return
(
c
->
closed
&
Rclosed
)
!=
0
;
}
// closedchan(sel *byte) bool;
void
sys
·
closedchan
(
Hchan
*
c
,
bool
closed
)
{
// test Rclosed
closed
=
0
;
if
(
c
->
closed
&
Rclosed
)
closed
=
1
;
closed
=
chanclosed
(
c
);
FLUSH
(
&
closed
);
}
...
...
src/pkg/runtime/reflect.cgo
View file @
653cef1b
...
...
@@ -78,6 +78,14 @@ func chanrecv(ch *byte, val *byte, pres *bool) {
chanrecv((Hchan*)ch, val, pres);
}
func chanclose(ch *byte) {
chanclose((Hchan*)ch);
}
func chanclosed(ch *byte) (r bool) {
r = chanclosed((Hchan*)ch);
}
/*
* Go wrappers around the functions in iface.c
...
...
src/pkg/runtime/runtime.h
View file @
653cef1b
...
...
@@ -73,7 +73,7 @@ typedef struct Hchan Hchan;
* amd64: allocated downwards from R15
* x86: allocated upwards from 0(FS)
* arm: allocated upwards from R9
*
*
* every C file linked into a Go program must include runtime.h
* so that the C compiler knows to avoid other uses of these registers.
* the Go compilers know to avoid them.
...
...
@@ -491,5 +491,7 @@ Hmap* makemap(uint32, uint32, uint32, uint32, uint32);
Hchan
*
makechan
(
uint32
,
uint32
,
uint32
);
void
chansend
(
Hchan
*
,
void
*
,
bool
*
);
void
chanrecv
(
Hchan
*
,
void
*
,
bool
*
);
void
chanclose
(
Hchan
*
);
bool
chanclosed
(
Hchan
*
);
void
ifaceE2I
(
struct
InterfaceType
*
,
Eface
,
Iface
*
);
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