mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
finish ChanValue: Len and Cap.
R=r DELTA=45 (45 added, 0 deleted, 0 changed) OCL=33873 CL=33881
This commit is contained in:
parent
653cef1ba0
commit
de7920e6fd
5 changed files with 45 additions and 0 deletions
|
|
@ -757,6 +757,17 @@ func TestChan(t *testing.T) {
|
||||||
if cv.TryRecv() != nil {
|
if cv.TryRecv() != nil {
|
||||||
t.Errorf("TryRecv on sync chan succeeded");
|
t.Errorf("TryRecv on sync chan succeeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// len/cap
|
||||||
|
cv = MakeChan(Typeof(c).(*ChanType), 10);
|
||||||
|
c = cv.Interface().(chan int);
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
c <- i;
|
||||||
|
}
|
||||||
|
if l, m := cv.Len(), cv.Cap(); l != len(c) || m != cap(c) {
|
||||||
|
t.Errorf("Len/Cap = %d/%d want %d/%d", l, m, len(c), cap(c));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Difficult test for function call because of
|
// Difficult test for function call because of
|
||||||
|
|
|
||||||
|
|
@ -636,6 +636,8 @@ func chansend(ch, val *byte, pres *bool)
|
||||||
func chanrecv(ch, val *byte, pres *bool)
|
func chanrecv(ch, val *byte, pres *bool)
|
||||||
func chanclosed(ch *byte) bool
|
func chanclosed(ch *byte) bool
|
||||||
func chanclose(ch *byte)
|
func chanclose(ch *byte)
|
||||||
|
func chanlen(ch *byte) int32
|
||||||
|
func chancap(ch *byte) int32
|
||||||
|
|
||||||
// Closed returns the result of closed(c) on the underlying channel.
|
// Closed returns the result of closed(c) on the underlying channel.
|
||||||
func (v *ChanValue) Closed() bool {
|
func (v *ChanValue) Closed() bool {
|
||||||
|
|
@ -649,6 +651,16 @@ func (v *ChanValue) Close() {
|
||||||
chanclose(ch);
|
chanclose(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *ChanValue) Len() int {
|
||||||
|
ch := *(**byte)(v.addr);
|
||||||
|
return int(chanlen(ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *ChanValue) Cap() int {
|
||||||
|
ch := *(**byte)(v.addr);
|
||||||
|
return int(chancap(ch));
|
||||||
|
}
|
||||||
|
|
||||||
// internal send; non-blocking if b != nil
|
// internal send; non-blocking if b != nil
|
||||||
func (v *ChanValue) send(x Value, b *bool) {
|
func (v *ChanValue) send(x Value, b *bool) {
|
||||||
t := v.Type().(*ChanType);
|
t := v.Type().(*ChanType);
|
||||||
|
|
|
||||||
|
|
@ -917,6 +917,18 @@ chanclosed(Hchan *c)
|
||||||
return (c->closed & Rclosed) != 0;
|
return (c->closed & Rclosed) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
chanlen(Hchan *c)
|
||||||
|
{
|
||||||
|
return c->qcount;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
chancap(Hchan *c)
|
||||||
|
{
|
||||||
|
return c->dataqsiz;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// closedchan(sel *byte) bool;
|
// closedchan(sel *byte) bool;
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,14 @@ func chanclosed(ch *byte) (r bool) {
|
||||||
r = chanclosed((Hchan*)ch);
|
r = chanclosed((Hchan*)ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func chanlen(ch *byte) (r int32) {
|
||||||
|
r = chanlen((Hchan*)ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
func chancap(ch *byte) (r int32) {
|
||||||
|
r = chancap((Hchan*)ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Go wrappers around the functions in iface.c
|
* Go wrappers around the functions in iface.c
|
||||||
|
|
|
||||||
|
|
@ -493,5 +493,7 @@ void chansend(Hchan*, void*, bool*);
|
||||||
void chanrecv(Hchan*, void*, bool*);
|
void chanrecv(Hchan*, void*, bool*);
|
||||||
void chanclose(Hchan*);
|
void chanclose(Hchan*);
|
||||||
bool chanclosed(Hchan*);
|
bool chanclosed(Hchan*);
|
||||||
|
int32 chanlen(Hchan*);
|
||||||
|
int32 chancap(Hchan*);
|
||||||
|
|
||||||
void ifaceE2I(struct InterfaceType*, Eface, Iface*);
|
void ifaceE2I(struct InterfaceType*, Eface, Iface*);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue