2008-07-13 15:29:46 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "runtime.h"
|
2009-09-08 14:46:54 -06:00
|
|
|
#include "type.h"
|
2008-07-13 15:29:46 -06:00
|
|
|
|
2011-03-22 19:41:17 -06:00
|
|
|
#define MAXALIGN 7
|
|
|
|
|
2008-07-14 15:33:39 -06:00
|
|
|
static int32 debug = 0;
|
2008-07-13 15:29:46 -06:00
|
|
|
|
2008-07-14 15:33:39 -06:00
|
|
|
typedef struct Link Link;
|
2008-07-20 21:13:07 -06:00
|
|
|
typedef struct WaitQ WaitQ;
|
|
|
|
typedef struct SudoG SudoG;
|
2008-07-24 16:57:30 -06:00
|
|
|
typedef struct Select Select;
|
|
|
|
typedef struct Scase Scase;
|
2008-07-20 21:13:07 -06:00
|
|
|
|
|
|
|
struct SudoG
|
|
|
|
{
|
|
|
|
G* g; // g and selgen constitute
|
2009-12-18 13:25:53 -07:00
|
|
|
uint32 selgen; // a weak pointer to g
|
2009-01-24 16:58:44 -07:00
|
|
|
int16 offset; // offset of case number
|
|
|
|
int8 isfree; // offset of case number
|
2008-07-20 21:13:07 -06:00
|
|
|
SudoG* link;
|
2008-12-09 17:16:07 -07:00
|
|
|
byte elem[8]; // synch data element (+ more)
|
2008-07-20 21:13:07 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct WaitQ
|
|
|
|
{
|
|
|
|
SudoG* first;
|
|
|
|
SudoG* last;
|
|
|
|
};
|
2008-07-13 15:29:46 -06:00
|
|
|
|
|
|
|
struct Hchan
|
|
|
|
{
|
2009-08-20 12:12:04 -06:00
|
|
|
uint32 qcount; // total data in the q
|
|
|
|
uint32 dataqsiz; // size of the circular q
|
2009-03-12 18:55:11 -06:00
|
|
|
uint16 elemsize;
|
2011-03-11 12:47:26 -07:00
|
|
|
bool closed;
|
2009-09-08 14:46:54 -06:00
|
|
|
uint8 elemalign;
|
2008-07-14 15:33:39 -06:00
|
|
|
Alg* elemalg; // interface for element type
|
|
|
|
Link* senddataq; // pointer for sender
|
|
|
|
Link* recvdataq; // pointer for receiver
|
|
|
|
WaitQ recvq; // list of recv waiters
|
|
|
|
WaitQ sendq; // list of send waiters
|
2008-07-20 21:13:07 -06:00
|
|
|
SudoG* free; // freelist
|
2009-12-04 11:57:01 -07:00
|
|
|
Lock;
|
2008-07-14 15:33:39 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Link
|
|
|
|
{
|
2008-07-24 16:57:30 -06:00
|
|
|
Link* link; // asynch queue circular linked list
|
2008-12-09 17:16:07 -07:00
|
|
|
byte elem[8]; // asynch queue data element (+ more)
|
2008-07-13 15:29:46 -06:00
|
|
|
};
|
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// Scase.kind
|
|
|
|
CaseRecv,
|
|
|
|
CaseSend,
|
|
|
|
CaseDefault,
|
|
|
|
};
|
|
|
|
|
2008-07-24 16:57:30 -06:00
|
|
|
struct Scase
|
|
|
|
{
|
|
|
|
Hchan* chan; // chan
|
|
|
|
byte* pc; // return pc
|
2011-03-11 12:47:26 -07:00
|
|
|
uint16 kind;
|
2008-07-24 16:57:30 -06:00
|
|
|
uint16 so; // vararg of selected bool
|
2008-07-25 12:58:26 -06:00
|
|
|
union {
|
2011-03-11 12:47:26 -07:00
|
|
|
byte elem[2*sizeof(void*)]; // element (send)
|
|
|
|
struct {
|
|
|
|
byte* elemp; // pointer to element (recv)
|
|
|
|
bool* receivedp; // pointer to received bool (recv2)
|
|
|
|
} recv;
|
2008-07-25 12:58:26 -06:00
|
|
|
} u;
|
2008-07-24 16:57:30 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Select
|
|
|
|
{
|
|
|
|
uint16 tcase; // total count of scase[]
|
|
|
|
uint16 ncase; // currently filled scase[]
|
2008-07-26 15:21:21 -06:00
|
|
|
Select* link; // for freelist
|
2011-01-20 07:20:47 -07:00
|
|
|
uint16* order;
|
2008-12-09 17:16:07 -07:00
|
|
|
Scase* scase[1]; // one per case
|
2008-07-24 16:57:30 -06:00
|
|
|
};
|
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
static void dequeueg(WaitQ*, Hchan*);
|
2008-07-24 16:57:30 -06:00
|
|
|
static SudoG* dequeue(WaitQ*, Hchan*);
|
|
|
|
static void enqueue(WaitQ*, SudoG*);
|
|
|
|
static SudoG* allocsg(Hchan*);
|
|
|
|
static void freesg(Hchan*, SudoG*);
|
2011-01-20 07:20:47 -07:00
|
|
|
static uint32 fastrandn(uint32);
|
2010-02-08 22:41:54 -07:00
|
|
|
static void destroychan(Hchan*);
|
2008-07-20 21:13:07 -06:00
|
|
|
|
2009-07-08 16:00:54 -06:00
|
|
|
Hchan*
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·makechan_c(Type *elem, int64 hint)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
|
|
|
Hchan *c;
|
2011-03-22 19:41:17 -06:00
|
|
|
int32 i, m, n;
|
|
|
|
Link *d, *b, *e;
|
|
|
|
byte *by;
|
2008-07-13 15:29:46 -06:00
|
|
|
|
2010-05-01 14:15:42 -06:00
|
|
|
if(hint < 0 || (int32)hint != hint || hint > ((uintptr)-1) / elem->size)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("makechan: size out of range");
|
2010-05-01 14:15:42 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(elem->alg >= nelem(runtime·algarray)) {
|
|
|
|
runtime·printf("chan(alg=%d)\n", elem->alg);
|
|
|
|
runtime·throw("runtime.makechan: unsupported elem type");
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
|
|
|
|
2011-03-22 19:41:17 -06:00
|
|
|
// calculate rounded sizes of Hchan and Link
|
|
|
|
n = sizeof(*c);
|
|
|
|
while(n & MAXALIGN)
|
|
|
|
n++;
|
|
|
|
m = sizeof(*d) + elem->size - sizeof(d->elem);
|
|
|
|
while(m & MAXALIGN)
|
|
|
|
m++;
|
|
|
|
|
|
|
|
// allocate memory in one call
|
|
|
|
by = runtime·mal(n + hint*m);
|
|
|
|
|
|
|
|
c = (Hchan*)by;
|
|
|
|
by += n;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·addfinalizer(c, destroychan, 0);
|
2008-07-13 15:29:46 -06:00
|
|
|
|
2009-09-08 14:46:54 -06:00
|
|
|
c->elemsize = elem->size;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
c->elemalg = &runtime·algarray[elem->alg];
|
2009-09-08 14:46:54 -06:00
|
|
|
c->elemalign = elem->align;
|
2008-07-14 15:33:39 -06:00
|
|
|
|
|
|
|
if(hint > 0) {
|
|
|
|
|
|
|
|
// make a circular q
|
|
|
|
b = nil;
|
|
|
|
e = nil;
|
|
|
|
for(i=0; i<hint; i++) {
|
2011-03-22 19:41:17 -06:00
|
|
|
d = (Link*)by;
|
|
|
|
by += m;
|
2008-07-14 15:33:39 -06:00
|
|
|
if(e == nil)
|
|
|
|
e = d;
|
|
|
|
d->link = b;
|
|
|
|
b = d;
|
|
|
|
}
|
|
|
|
e->link = b;
|
|
|
|
c->recvdataq = b;
|
|
|
|
c->senddataq = b;
|
|
|
|
c->qcount = 0;
|
|
|
|
c->dataqsiz = hint;
|
|
|
|
}
|
2008-07-13 15:29:46 -06:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%d; elemalign=%d; dataqsiz=%d\n",
|
2010-04-01 12:56:18 -06:00
|
|
|
c, (int64)elem->size, elem->alg, elem->align, c->dataqsiz);
|
2009-07-08 16:00:54 -06:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-02-08 22:41:54 -07:00
|
|
|
static void
|
|
|
|
destroychan(Hchan *c)
|
|
|
|
{
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·destroylock(&c->Lock);
|
2010-02-08 22:41:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-01 14:15:42 -06:00
|
|
|
// makechan(elem *Type, hint int64) (hchan *chan any);
|
2009-07-08 16:00:54 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·makechan(Type *elem, int64 hint, Hchan *ret)
|
2009-07-08 16:00:54 -06:00
|
|
|
{
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
ret = runtime·makechan_c(elem, hint);
|
2009-07-08 16:00:54 -06:00
|
|
|
FLUSH(&ret);
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
/*
|
|
|
|
* generic single channel send/recv
|
|
|
|
* if the bool pointer is nil,
|
|
|
|
* then the full exchange will
|
|
|
|
* occur. if pres is not nil,
|
|
|
|
* then the protocol will not
|
|
|
|
* sleep but return if it could
|
2010-04-01 12:56:18 -06:00
|
|
|
* not complete.
|
|
|
|
*
|
|
|
|
* sleep can wake up with g->param == nil
|
|
|
|
* when a channel involved in the sleep has
|
|
|
|
* been closed. it is easiest to loop and re-run
|
|
|
|
* the operation; we'll see that it's now closed.
|
2008-07-26 15:21:21 -06:00
|
|
|
*/
|
2008-07-13 15:29:46 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·chansend(Hchan *c, byte *ep, bool *pres)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-07-26 15:21:21 -06:00
|
|
|
SudoG *sg;
|
|
|
|
G* gp;
|
2008-07-13 15:29:46 -06:00
|
|
|
|
2010-07-13 18:27:26 -06:00
|
|
|
if(c == nil)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("send to nil channel");
|
2010-07-13 18:27:26 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(runtime·gcwaiting)
|
|
|
|
runtime·gosched();
|
2010-01-09 10:47:45 -07:00
|
|
|
|
2008-07-13 15:29:46 -06:00
|
|
|
if(debug) {
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("chansend: chan=%p; elem=", c);
|
2008-07-26 15:21:21 -06:00
|
|
|
c->elemalg->print(c->elemsize, ep);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·prints("\n");
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
2008-07-26 15:21:21 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2009-03-23 19:50:35 -06:00
|
|
|
loop:
|
2011-03-11 12:47:26 -07:00
|
|
|
if(c->closed)
|
2009-03-23 19:50:35 -06:00
|
|
|
goto closed;
|
2009-03-13 17:47:54 -06:00
|
|
|
|
2008-07-14 15:33:39 -06:00
|
|
|
if(c->dataqsiz > 0)
|
|
|
|
goto asynch;
|
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = dequeue(&c->recvq, c);
|
|
|
|
if(sg != nil) {
|
|
|
|
if(ep != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, ep);
|
2008-07-20 21:13:07 -06:00
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
gp = sg->g;
|
|
|
|
gp->param = sg;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·ready(gp);
|
2008-07-26 15:21:21 -06:00
|
|
|
|
|
|
|
if(pres != nil)
|
|
|
|
*pres = true;
|
2008-07-14 15:33:39 -06:00
|
|
|
return;
|
|
|
|
}
|
2008-07-20 21:13:07 -06:00
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
if(pres != nil) {
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2008-07-26 15:21:21 -06:00
|
|
|
*pres = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sg = allocsg(c);
|
|
|
|
if(ep != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, ep);
|
|
|
|
g->param = nil;
|
2008-07-14 15:33:39 -06:00
|
|
|
g->status = Gwaiting;
|
2008-07-26 15:21:21 -06:00
|
|
|
enqueue(&c->sendq, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·gosched();
|
2008-07-26 15:21:21 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = g->param;
|
2009-03-23 19:50:35 -06:00
|
|
|
if(sg == nil)
|
|
|
|
goto loop;
|
2008-07-26 15:21:21 -06:00
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2008-07-14 15:33:39 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
asynch:
|
2011-03-11 12:47:26 -07:00
|
|
|
if(c->closed)
|
2009-03-13 17:47:54 -06:00
|
|
|
goto closed;
|
|
|
|
|
|
|
|
if(c->qcount >= c->dataqsiz) {
|
2008-09-26 12:47:04 -06:00
|
|
|
if(pres != nil) {
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2008-09-26 12:47:04 -06:00
|
|
|
*pres = false;
|
|
|
|
return;
|
|
|
|
}
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = allocsg(c);
|
2008-07-14 18:41:38 -06:00
|
|
|
g->status = Gwaiting;
|
2008-07-26 15:21:21 -06:00
|
|
|
enqueue(&c->sendq, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·gosched();
|
2008-09-19 21:43:30 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2009-03-13 17:47:54 -06:00
|
|
|
goto asynch;
|
2008-07-14 18:41:38 -06:00
|
|
|
}
|
2008-07-26 15:21:21 -06:00
|
|
|
if(ep != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, c->senddataq->elem, ep);
|
2008-07-14 18:41:38 -06:00
|
|
|
c->senddataq = c->senddataq->link;
|
|
|
|
c->qcount++;
|
2008-07-26 15:21:21 -06:00
|
|
|
|
|
|
|
sg = dequeue(&c->recvq, c);
|
|
|
|
if(sg != nil) {
|
|
|
|
gp = sg->g;
|
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·ready(gp);
|
2008-09-19 21:43:30 -06:00
|
|
|
} else
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2008-09-26 12:47:04 -06:00
|
|
|
if(pres != nil)
|
|
|
|
*pres = true;
|
2009-03-13 17:47:54 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
closed:
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
spec, runtime, tests: send on closed channel panics
Close of closed channel panics.
Receive from closed channel never panics,
even if done repeatedly.
Fixes #1349.
Fixes #1419.
R=gri, iant, ken2, r, gri1, r2, iant2, rog, albert.strasheim, niemeyer, ejsherry
CC=golang-dev
https://golang.org/cl/3989042
2011-01-21 13:07:13 -07:00
|
|
|
runtime·panicstring("send on closed channel");
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
2008-07-13 17:20:27 -06:00
|
|
|
|
2009-07-08 16:00:54 -06:00
|
|
|
void
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·chanrecv(Hchan* c, byte *ep, bool *selected, bool *received)
|
2008-07-15 22:07:59 -06:00
|
|
|
{
|
2008-07-26 15:21:21 -06:00
|
|
|
SudoG *sg;
|
|
|
|
G *gp;
|
2008-07-16 12:46:33 -06:00
|
|
|
|
2010-07-13 18:27:26 -06:00
|
|
|
if(c == nil)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("receive from nil channel");
|
2010-07-13 18:27:26 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(runtime·gcwaiting)
|
|
|
|
runtime·gosched();
|
2010-01-09 10:47:45 -07:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("chanrecv: chan=%p\n", c);
|
2008-07-26 15:21:21 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2011-01-18 13:59:19 -07:00
|
|
|
|
2009-03-23 19:50:35 -06:00
|
|
|
loop:
|
2008-07-15 22:07:59 -06:00
|
|
|
if(c->dataqsiz > 0)
|
|
|
|
goto asynch;
|
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
if(c->closed)
|
2009-03-13 17:47:54 -06:00
|
|
|
goto closed;
|
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = dequeue(&c->sendq, c);
|
|
|
|
if(sg != nil) {
|
2011-01-30 14:07:57 -07:00
|
|
|
if(ep != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, ep, sg->elem);
|
2010-04-06 17:58:52 -06:00
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, nil);
|
2008-07-20 21:13:07 -06:00
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
gp = sg->g;
|
|
|
|
gp->param = sg;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·ready(gp);
|
2008-07-15 22:07:59 -06:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
if(selected != nil)
|
|
|
|
*selected = true;
|
|
|
|
if(received != nil)
|
|
|
|
*received = true;
|
2008-07-15 22:07:59 -06:00
|
|
|
return;
|
|
|
|
}
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
if(selected != nil) {
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2011-03-11 12:47:26 -07:00
|
|
|
*selected = false;
|
2008-07-14 15:33:39 -06:00
|
|
|
return;
|
|
|
|
}
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = allocsg(c);
|
|
|
|
g->param = nil;
|
2008-07-14 15:33:39 -06:00
|
|
|
g->status = Gwaiting;
|
2008-07-26 15:21:21 -06:00
|
|
|
enqueue(&c->recvq, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·gosched();
|
2008-07-26 15:21:21 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = g->param;
|
2009-03-23 19:50:35 -06:00
|
|
|
if(sg == nil)
|
|
|
|
goto loop;
|
2009-03-13 17:47:54 -06:00
|
|
|
|
2011-01-30 14:07:57 -07:00
|
|
|
if(ep != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, ep, sg->elem);
|
2010-04-06 17:58:52 -06:00
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, nil);
|
2011-03-11 12:47:26 -07:00
|
|
|
if(received != nil)
|
|
|
|
*received = true;
|
2008-07-26 15:21:21 -06:00
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2008-07-14 15:33:39 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
asynch:
|
2009-03-13 17:47:54 -06:00
|
|
|
if(c->qcount <= 0) {
|
2011-03-11 12:47:26 -07:00
|
|
|
if(c->closed)
|
2009-03-13 17:47:54 -06:00
|
|
|
goto closed;
|
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
if(selected != nil) {
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2011-03-11 12:47:26 -07:00
|
|
|
*selected = false;
|
2008-09-26 12:47:04 -06:00
|
|
|
return;
|
|
|
|
}
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = allocsg(c);
|
2008-07-14 18:41:38 -06:00
|
|
|
g->status = Gwaiting;
|
2008-07-26 15:21:21 -06:00
|
|
|
enqueue(&c->recvq, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·gosched();
|
2009-03-13 17:47:54 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2009-03-13 17:47:54 -06:00
|
|
|
goto asynch;
|
2008-07-14 18:41:38 -06:00
|
|
|
}
|
2011-01-30 14:07:57 -07:00
|
|
|
if(ep != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, ep, c->recvdataq->elem);
|
2010-04-06 17:58:52 -06:00
|
|
|
c->elemalg->copy(c->elemsize, c->recvdataq->elem, nil);
|
2008-07-14 18:41:38 -06:00
|
|
|
c->recvdataq = c->recvdataq->link;
|
|
|
|
c->qcount--;
|
2008-07-26 15:21:21 -06:00
|
|
|
sg = dequeue(&c->sendq, c);
|
|
|
|
if(sg != nil) {
|
|
|
|
gp = sg->g;
|
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·ready(gp);
|
2011-03-11 12:47:26 -07:00
|
|
|
} else
|
|
|
|
runtime·unlock(c);
|
2009-03-13 17:47:54 -06:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
if(selected != nil)
|
|
|
|
*selected = true;
|
|
|
|
if(received != nil)
|
|
|
|
*received = true;
|
2009-03-13 17:47:54 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
closed:
|
2011-01-30 14:07:57 -07:00
|
|
|
if(ep != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, ep, nil);
|
2011-03-11 12:47:26 -07:00
|
|
|
if(selected != nil)
|
|
|
|
*selected = true;
|
|
|
|
if(received != nil)
|
|
|
|
*received = false;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2008-07-13 17:20:27 -06:00
|
|
|
}
|
|
|
|
|
2008-07-26 15:21:21 -06:00
|
|
|
// chansend1(hchan *chan any, elem any);
|
2010-03-04 16:34:25 -07:00
|
|
|
#pragma textflag 7
|
2008-07-13 17:20:27 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·chansend1(Hchan* c, ...)
|
2008-07-26 15:21:21 -06:00
|
|
|
{
|
|
|
|
int32 o;
|
|
|
|
byte *ae;
|
|
|
|
|
2010-09-19 21:28:12 -06:00
|
|
|
if(c == nil)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("send to nil channel");
|
2010-09-19 21:28:12 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
o = runtime·rnd(sizeof(c), c->elemalign);
|
2008-07-26 15:21:21 -06:00
|
|
|
ae = (byte*)&c + o;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·chansend(c, ae, nil);
|
2008-07-26 15:21:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// chanrecv1(hchan *chan any) (elem any);
|
2010-03-04 16:34:25 -07:00
|
|
|
#pragma textflag 7
|
2008-07-26 15:21:21 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·chanrecv1(Hchan* c, ...)
|
2008-07-26 15:21:21 -06:00
|
|
|
{
|
|
|
|
int32 o;
|
|
|
|
byte *ae;
|
2008-07-20 21:13:07 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
o = runtime·rnd(sizeof(c), Structrnd);
|
2008-07-26 15:21:21 -06:00
|
|
|
ae = (byte*)&c + o;
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-01-18 13:59:19 -07:00
|
|
|
runtime·chanrecv(c, ae, nil, nil);
|
2008-07-26 15:21:21 -06:00
|
|
|
}
|
2008-07-14 15:33:39 -06:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
// chanrecv2(hchan *chan any) (elem any, received bool);
|
2011-01-18 13:59:19 -07:00
|
|
|
#pragma textflag 7
|
|
|
|
void
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·chanrecv2(Hchan* c, ...)
|
2011-01-18 13:59:19 -07:00
|
|
|
{
|
|
|
|
int32 o;
|
|
|
|
byte *ae, *ac;
|
2011-01-30 14:07:57 -07:00
|
|
|
|
|
|
|
if(c == nil)
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·panicstring("receive from nil channel");
|
2011-01-18 13:59:19 -07:00
|
|
|
|
|
|
|
o = runtime·rnd(sizeof(c), Structrnd);
|
|
|
|
ae = (byte*)&c + o;
|
|
|
|
o = runtime·rnd(o+c->elemsize, 1);
|
|
|
|
ac = (byte*)&c + o;
|
|
|
|
|
|
|
|
runtime·chanrecv(c, ae, nil, ac);
|
2008-07-26 15:21:21 -06:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:07:57 -07:00
|
|
|
// func selectnbsend(c chan any, elem any) bool
|
|
|
|
//
|
|
|
|
// compiler implements
|
|
|
|
//
|
|
|
|
// select {
|
|
|
|
// case c <- v:
|
|
|
|
// ... foo
|
|
|
|
// default:
|
|
|
|
// ... bar
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// as
|
|
|
|
//
|
|
|
|
// if c != nil && selectnbsend(c, v) {
|
|
|
|
// ... foo
|
|
|
|
// } else {
|
|
|
|
// ... bar
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
#pragma textflag 7
|
|
|
|
void
|
|
|
|
runtime·selectnbsend(Hchan *c, ...)
|
|
|
|
{
|
|
|
|
int32 o;
|
|
|
|
byte *ae, *ap;
|
|
|
|
|
|
|
|
o = runtime·rnd(sizeof(c), c->elemalign);
|
|
|
|
ae = (byte*)&c + o;
|
|
|
|
o = runtime·rnd(o+c->elemsize, Structrnd);
|
|
|
|
ap = (byte*)&c + o;
|
|
|
|
|
|
|
|
runtime·chansend(c, ae, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
// func selectnbrecv(elem *any, c chan any) bool
|
|
|
|
//
|
|
|
|
// compiler implements
|
|
|
|
//
|
|
|
|
// select {
|
|
|
|
// case v = <-c:
|
|
|
|
// ... foo
|
|
|
|
// default:
|
|
|
|
// ... bar
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// as
|
|
|
|
//
|
|
|
|
// if c != nil && selectnbrecv(&v, c) {
|
|
|
|
// ... foo
|
|
|
|
// } else {
|
|
|
|
// ... bar
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
#pragma textflag 7
|
|
|
|
void
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·selectnbrecv(byte *v, Hchan *c, bool selected)
|
2011-01-30 14:07:57 -07:00
|
|
|
{
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·chanrecv(c, v, &selected, nil);
|
|
|
|
}
|
|
|
|
|
|
|
|
// func selectnbrecv2(elem *any, ok *bool, c chan any) bool
|
|
|
|
//
|
|
|
|
// compiler implements
|
|
|
|
//
|
|
|
|
// select {
|
|
|
|
// case v = <-c:
|
|
|
|
// ... foo
|
|
|
|
// default:
|
|
|
|
// ... bar
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// as
|
|
|
|
//
|
|
|
|
// if c != nil && selectnbrecv(&v, c) {
|
|
|
|
// ... foo
|
|
|
|
// } else {
|
|
|
|
// ... bar
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
#pragma textflag 7
|
|
|
|
void
|
|
|
|
runtime·selectnbrecv2(byte *v, bool *received, Hchan *c, bool selected)
|
|
|
|
{
|
|
|
|
runtime·chanrecv(c, v, &selected, received);
|
2011-01-30 14:07:57 -07:00
|
|
|
}
|
|
|
|
|
2011-02-22 15:40:40 -07:00
|
|
|
static void newselect(int32, Select**);
|
|
|
|
|
2008-07-24 16:57:30 -06:00
|
|
|
// newselect(size uint32) (sel *byte);
|
2010-03-04 16:34:25 -07:00
|
|
|
#pragma textflag 7
|
2008-07-24 16:57:30 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·newselect(int32 size, ...)
|
2008-07-24 16:57:30 -06:00
|
|
|
{
|
2011-02-22 15:40:40 -07:00
|
|
|
int32 o;
|
2009-06-30 21:02:07 -06:00
|
|
|
Select **selp;
|
2008-07-24 16:57:30 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
o = runtime·rnd(sizeof(size), Structrnd);
|
2009-06-30 21:02:07 -06:00
|
|
|
selp = (Select**)((byte*)&size + o);
|
2011-02-22 15:40:40 -07:00
|
|
|
newselect(size, selp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
newselect(int32 size, Select **selp)
|
|
|
|
{
|
|
|
|
int32 n;
|
|
|
|
Select *sel;
|
|
|
|
|
2008-07-24 16:57:30 -06:00
|
|
|
n = 0;
|
|
|
|
if(size > 1)
|
|
|
|
n = size-1;
|
2008-07-26 15:21:21 -06:00
|
|
|
|
2011-01-20 07:20:47 -07:00
|
|
|
sel = runtime·mal(sizeof(*sel) + n*sizeof(sel->scase[0]) + size*sizeof(sel->order[0]));
|
2008-07-26 15:21:21 -06:00
|
|
|
|
2008-07-24 16:57:30 -06:00
|
|
|
sel->tcase = size;
|
|
|
|
sel->ncase = 0;
|
2011-01-20 07:20:47 -07:00
|
|
|
sel->order = (void*)(sel->scase + size);
|
2009-06-30 21:02:07 -06:00
|
|
|
*selp = sel;
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("newselect s=%p size=%d\n", sel, size);
|
2008-07-24 16:57:30 -06:00
|
|
|
}
|
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
// cut in half to give stack a chance to split
|
|
|
|
static void selectsend(Select **selp, Hchan *c, void *pc);
|
|
|
|
|
2008-07-24 16:57:30 -06:00
|
|
|
// selectsend(sel *byte, hchan *chan any, elem any) (selected bool);
|
2010-03-04 16:34:25 -07:00
|
|
|
#pragma textflag 7
|
2008-07-24 16:57:30 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·selectsend(Select *sel, Hchan *c, ...)
|
2008-07-24 16:57:30 -06:00
|
|
|
{
|
2008-07-25 16:55:12 -06:00
|
|
|
// nil cases do not compete
|
2008-07-24 16:57:30 -06:00
|
|
|
if(c == nil)
|
|
|
|
return;
|
2011-03-23 09:28:24 -06:00
|
|
|
|
|
|
|
selectsend(&sel, c, runtime·getcallerpc(&sel));
|
|
|
|
}
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
static void
|
|
|
|
selectsend(Select **selp, Hchan *c, void *pc)
|
|
|
|
{
|
|
|
|
int32 i, eo;
|
|
|
|
Scase *cas;
|
|
|
|
byte *ae;
|
|
|
|
Select *sel;
|
|
|
|
|
|
|
|
sel = *selp;
|
2008-07-24 16:57:30 -06:00
|
|
|
i = sel->ncase;
|
|
|
|
if(i >= sel->tcase)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("selectsend: too many cases");
|
2008-07-24 16:57:30 -06:00
|
|
|
sel->ncase = i+1;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
cas = runtime·mal(sizeof *cas + c->elemsize - sizeof(cas->u.elem));
|
2009-10-28 19:23:53 -06:00
|
|
|
sel->scase[i] = cas;
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
cas->pc = pc;
|
2008-07-24 16:57:30 -06:00
|
|
|
cas->chan = c;
|
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
eo = runtime·rnd(sizeof(sel), sizeof(c));
|
|
|
|
eo = runtime·rnd(eo+sizeof(c), c->elemsize);
|
|
|
|
cas->so = runtime·rnd(eo+c->elemsize, Structrnd);
|
2011-03-11 12:47:26 -07:00
|
|
|
cas->kind = CaseSend;
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
ae = (byte*)selp + eo;
|
2008-07-25 12:58:26 -06:00
|
|
|
c->elemalg->copy(c->elemsize, cas->u.elem, ae);
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·printf("selectsend s=%p pc=%p chan=%p so=%d\n",
|
|
|
|
sel, cas->pc, cas->chan, cas->so);
|
2008-07-24 16:57:30 -06:00
|
|
|
}
|
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
// cut in half to give stack a chance to split
|
|
|
|
static void selectrecv(Select *sel, Hchan *c, void *pc, void *elem, bool*, int32 so);
|
|
|
|
|
2008-07-24 16:57:30 -06:00
|
|
|
// selectrecv(sel *byte, hchan *chan any, elem *any) (selected bool);
|
2010-03-04 16:34:25 -07:00
|
|
|
#pragma textflag 7
|
2008-07-24 16:57:30 -06:00
|
|
|
void
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·selectrecv(Select *sel, Hchan *c, void *elem, bool selected)
|
2008-07-24 16:57:30 -06:00
|
|
|
{
|
2008-07-25 16:55:12 -06:00
|
|
|
// nil cases do not compete
|
2008-07-25 12:58:26 -06:00
|
|
|
if(c == nil)
|
|
|
|
return;
|
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
selectrecv(sel, c, runtime·getcallerpc(&sel), elem, nil, (byte*)&selected - (byte*)&sel);
|
2011-03-11 12:47:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// selectrecv2(sel *byte, hchan *chan any, elem *any, received *bool) (selected bool);
|
|
|
|
#pragma textflag 7
|
|
|
|
void
|
|
|
|
runtime·selectrecv2(Select *sel, Hchan *c, void *elem, bool *received, bool selected)
|
|
|
|
{
|
|
|
|
// nil cases do not compete
|
|
|
|
if(c == nil)
|
|
|
|
return;
|
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
selectrecv(sel, c, runtime·getcallerpc(&sel), elem, received, (byte*)&selected - (byte*)&sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selectrecv(Select *sel, Hchan *c, void *pc, void *elem, bool *received, int32 so)
|
|
|
|
{
|
|
|
|
int32 i;
|
|
|
|
Scase *cas;
|
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
i = sel->ncase;
|
|
|
|
if(i >= sel->tcase)
|
|
|
|
runtime·throw("selectrecv: too many cases");
|
|
|
|
sel->ncase = i+1;
|
|
|
|
cas = runtime·mal(sizeof *cas);
|
|
|
|
sel->scase[i] = cas;
|
2011-03-23 09:28:24 -06:00
|
|
|
cas->pc = pc;
|
2011-03-11 12:47:26 -07:00
|
|
|
cas->chan = c;
|
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
cas->so = so;
|
2011-03-11 12:47:26 -07:00
|
|
|
cas->kind = CaseRecv;
|
|
|
|
cas->u.recv.elemp = elem;
|
2011-03-23 09:28:24 -06:00
|
|
|
cas->u.recv.receivedp = nil;
|
2011-03-11 12:47:26 -07:00
|
|
|
cas->u.recv.receivedp = received;
|
2008-07-25 12:58:26 -06:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
2011-03-23 09:28:24 -06:00
|
|
|
runtime·printf("selectrecv s=%p pc=%p chan=%p so=%d\n",
|
|
|
|
sel, cas->pc, cas->chan, cas->so);
|
2008-07-24 16:57:30 -06:00
|
|
|
}
|
|
|
|
|
2011-03-23 09:28:24 -06:00
|
|
|
// cut in half to give stack a chance to split
|
2011-03-11 12:47:26 -07:00
|
|
|
static void selectdefault(Select*, void*, int32);
|
2011-02-22 15:40:40 -07:00
|
|
|
|
|
|
|
// selectdefault(sel *byte) (selected bool);
|
2010-03-04 16:34:25 -07:00
|
|
|
#pragma textflag 7
|
2008-11-05 19:04:24 -07:00
|
|
|
void
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·selectdefault(Select *sel, bool selected)
|
2008-11-05 19:04:24 -07:00
|
|
|
{
|
2011-03-11 12:47:26 -07:00
|
|
|
selectdefault(sel, runtime·getcallerpc(&sel), (byte*)&selected - (byte*)&sel);
|
2011-02-22 15:40:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-11 12:47:26 -07:00
|
|
|
selectdefault(Select *sel, void *callerpc, int32 so)
|
2011-02-22 15:40:40 -07:00
|
|
|
{
|
2008-11-05 22:50:28 -07:00
|
|
|
int32 i;
|
2008-11-05 19:04:24 -07:00
|
|
|
Scase *cas;
|
2008-12-09 17:16:07 -07:00
|
|
|
|
2008-11-05 19:04:24 -07:00
|
|
|
i = sel->ncase;
|
|
|
|
if(i >= sel->tcase)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("selectdefault: too many cases");
|
2008-11-05 19:04:24 -07:00
|
|
|
sel->ncase = i+1;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
cas = runtime·mal(sizeof *cas);
|
2009-10-28 19:23:53 -06:00
|
|
|
sel->scase[i] = cas;
|
2011-02-22 19:10:02 -07:00
|
|
|
cas->pc = callerpc;
|
2008-11-05 22:50:28 -07:00
|
|
|
cas->chan = nil;
|
2008-11-05 19:04:24 -07:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
cas->so = so;
|
|
|
|
cas->kind = CaseDefault;
|
2008-11-05 19:04:24 -07:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·printf("selectdefault s=%p pc=%p so=%d\n",
|
|
|
|
sel, cas->pc, cas->so);
|
2008-11-05 19:04:24 -07:00
|
|
|
}
|
|
|
|
|
2009-10-28 19:23:53 -06:00
|
|
|
static void
|
|
|
|
freesel(Select *sel)
|
|
|
|
{
|
|
|
|
uint32 i;
|
|
|
|
|
|
|
|
for(i=0; i<sel->ncase; i++)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·free(sel->scase[i]);
|
|
|
|
runtime·free(sel);
|
2009-10-28 19:23:53 -06:00
|
|
|
}
|
|
|
|
|
2009-12-04 11:57:01 -07:00
|
|
|
static void
|
|
|
|
sellock(Select *sel)
|
|
|
|
{
|
|
|
|
uint32 i;
|
|
|
|
Hchan *c;
|
|
|
|
|
|
|
|
c = nil;
|
|
|
|
for(i=0; i<sel->ncase; i++) {
|
|
|
|
if(sel->scase[i]->chan != c) {
|
|
|
|
c = sel->scase[i]->chan;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2009-12-04 11:57:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selunlock(Select *sel)
|
|
|
|
{
|
|
|
|
uint32 i;
|
|
|
|
Hchan *c;
|
|
|
|
|
|
|
|
c = nil;
|
|
|
|
for(i=sel->ncase; i>0; i--) {
|
|
|
|
if(sel->scase[i-1]->chan && sel->scase[i-1]->chan != c) {
|
|
|
|
c = sel->scase[i-1]->chan;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2009-12-04 11:57:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:07:57 -07:00
|
|
|
void
|
|
|
|
runtime·block(void)
|
|
|
|
{
|
|
|
|
g->status = Gwaiting; // forever
|
|
|
|
runtime·gosched();
|
|
|
|
}
|
|
|
|
|
2011-02-22 19:10:02 -07:00
|
|
|
static void* selectgo(Select**);
|
2011-02-22 15:40:40 -07:00
|
|
|
|
2008-07-24 16:57:30 -06:00
|
|
|
// selectgo(sel *byte);
|
2010-10-20 13:54:17 -06:00
|
|
|
//
|
|
|
|
// overwrites return pc on stack to signal which case of the select
|
|
|
|
// to run, so cannot appear at the top of a split stack.
|
|
|
|
#pragma textflag 7
|
2008-07-24 16:57:30 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·selectgo(Select *sel)
|
2008-07-24 16:57:30 -06:00
|
|
|
{
|
2011-02-22 19:10:02 -07:00
|
|
|
runtime·setcallerpc(&sel, selectgo(&sel));
|
2011-02-22 15:40:40 -07:00
|
|
|
}
|
|
|
|
|
2011-02-22 19:10:02 -07:00
|
|
|
static void*
|
2011-02-22 15:40:40 -07:00
|
|
|
selectgo(Select **selp)
|
|
|
|
{
|
|
|
|
Select *sel;
|
2011-01-20 07:20:47 -07:00
|
|
|
uint32 o, i, j;
|
2008-11-05 18:57:18 -07:00
|
|
|
Scase *cas, *dfl;
|
2008-07-24 16:57:30 -06:00
|
|
|
Hchan *c;
|
2008-07-25 16:55:12 -06:00
|
|
|
SudoG *sg;
|
|
|
|
G *gp;
|
2008-08-05 15:18:47 -06:00
|
|
|
byte *as;
|
2011-02-22 19:10:02 -07:00
|
|
|
void *pc;
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-02-22 15:40:40 -07:00
|
|
|
sel = *selp;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(runtime·gcwaiting)
|
|
|
|
runtime·gosched();
|
2010-01-09 10:47:45 -07:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("select: sel=%p\n", sel);
|
2008-07-25 12:58:26 -06:00
|
|
|
|
2011-01-30 14:07:57 -07:00
|
|
|
// The compiler rewrites selects that statically have
|
|
|
|
// only 0 or 1 cases plus default into simpler constructs.
|
|
|
|
// The only way we can end up with such small sel->ncase
|
|
|
|
// values here is for a larger select in which most channels
|
|
|
|
// have been nilled out. The general code handles those
|
|
|
|
// cases correctly, and they are rare enough not to bother
|
|
|
|
// optimizing (and needing to test).
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-01-20 07:20:47 -07:00
|
|
|
// generate permuted order
|
|
|
|
for(i=0; i<sel->ncase; i++)
|
|
|
|
sel->order[i] = i;
|
|
|
|
for(i=1; i<sel->ncase; i++) {
|
|
|
|
o = sel->order[i];
|
|
|
|
j = fastrandn(i+1);
|
|
|
|
sel->order[i] = sel->order[j];
|
|
|
|
sel->order[j] = o;
|
2008-07-24 16:57:30 -06:00
|
|
|
}
|
2008-07-25 16:55:12 -06:00
|
|
|
|
2009-12-04 11:57:01 -07:00
|
|
|
// sort the cases by Hchan address to get the locking order.
|
|
|
|
for(i=1; i<sel->ncase; i++) {
|
|
|
|
cas = sel->scase[i];
|
2009-12-04 14:31:18 -07:00
|
|
|
for(j=i; j>0 && sel->scase[j-1]->chan >= cas->chan; j--)
|
|
|
|
sel->scase[j] = sel->scase[j-1];
|
2009-12-04 11:57:01 -07:00
|
|
|
sel->scase[j] = cas;
|
|
|
|
}
|
|
|
|
sellock(sel);
|
2008-09-09 12:50:14 -06:00
|
|
|
|
2009-01-24 16:58:44 -07:00
|
|
|
loop:
|
2008-07-25 16:55:12 -06:00
|
|
|
// pass 1 - look for something already waiting
|
2008-11-05 18:57:18 -07:00
|
|
|
dfl = nil;
|
2008-07-24 16:57:30 -06:00
|
|
|
for(i=0; i<sel->ncase; i++) {
|
2011-01-20 07:20:47 -07:00
|
|
|
o = sel->order[i];
|
2008-12-09 17:16:07 -07:00
|
|
|
cas = sel->scase[o];
|
2008-07-24 16:57:30 -06:00
|
|
|
c = cas->chan;
|
2010-04-01 12:56:18 -06:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
switch(cas->kind) {
|
|
|
|
case CaseRecv:
|
2010-04-01 12:56:18 -06:00
|
|
|
if(c->dataqsiz > 0) {
|
|
|
|
if(c->qcount > 0)
|
|
|
|
goto asyncrecv;
|
|
|
|
} else {
|
|
|
|
sg = dequeue(&c->sendq, c);
|
|
|
|
if(sg != nil)
|
|
|
|
goto syncrecv;
|
2008-07-26 15:21:21 -06:00
|
|
|
}
|
2011-03-11 12:47:26 -07:00
|
|
|
if(c->closed)
|
2009-03-23 19:50:35 -06:00
|
|
|
goto rclose;
|
2010-04-01 12:56:18 -06:00
|
|
|
break;
|
2008-07-25 12:58:26 -06:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
case CaseSend:
|
|
|
|
if(c->closed)
|
2009-03-23 19:50:35 -06:00
|
|
|
goto sclose;
|
2010-04-01 12:56:18 -06:00
|
|
|
if(c->dataqsiz > 0) {
|
|
|
|
if(c->qcount < c->dataqsiz)
|
|
|
|
goto asyncsend;
|
|
|
|
} else {
|
|
|
|
sg = dequeue(&c->recvq, c);
|
|
|
|
if(sg != nil)
|
|
|
|
goto syncsend;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
case CaseDefault:
|
2010-04-01 12:56:18 -06:00
|
|
|
dfl = cas;
|
|
|
|
break;
|
2008-07-25 16:55:12 -06:00
|
|
|
}
|
|
|
|
}
|
2008-12-09 17:16:07 -07:00
|
|
|
|
2008-11-05 18:57:18 -07:00
|
|
|
if(dfl != nil) {
|
|
|
|
cas = dfl;
|
|
|
|
goto retc;
|
|
|
|
}
|
2008-12-09 17:16:07 -07:00
|
|
|
|
2008-07-25 12:58:26 -06:00
|
|
|
|
2008-07-25 16:55:12 -06:00
|
|
|
// pass 2 - enqueue on all chans
|
|
|
|
for(i=0; i<sel->ncase; i++) {
|
2011-01-20 07:20:47 -07:00
|
|
|
o = sel->order[i];
|
2008-12-09 17:16:07 -07:00
|
|
|
cas = sel->scase[o];
|
2008-07-25 16:55:12 -06:00
|
|
|
c = cas->chan;
|
2010-04-01 12:56:18 -06:00
|
|
|
sg = allocsg(c);
|
|
|
|
sg->offset = o;
|
2008-07-26 15:21:21 -06:00
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
switch(cas->kind) {
|
|
|
|
case CaseRecv:
|
2008-11-06 18:50:28 -07:00
|
|
|
enqueue(&c->recvq, sg);
|
2010-04-01 12:56:18 -06:00
|
|
|
break;
|
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
case CaseSend:
|
2011-01-28 15:17:38 -07:00
|
|
|
if(c->dataqsiz == 0)
|
2010-04-01 12:56:18 -06:00
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, cas->u.elem);
|
2008-07-25 16:55:12 -06:00
|
|
|
enqueue(&c->sendq, sg);
|
2010-04-01 12:56:18 -06:00
|
|
|
break;
|
2008-11-06 18:50:28 -07:00
|
|
|
}
|
2008-07-24 16:57:30 -06:00
|
|
|
}
|
|
|
|
|
2009-01-24 16:58:44 -07:00
|
|
|
g->param = nil;
|
2008-07-25 16:55:12 -06:00
|
|
|
g->status = Gwaiting;
|
2009-12-04 11:57:01 -07:00
|
|
|
selunlock(sel);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·gosched();
|
2008-07-25 16:55:12 -06:00
|
|
|
|
2009-12-04 11:57:01 -07:00
|
|
|
sellock(sel);
|
2008-07-25 16:55:12 -06:00
|
|
|
sg = g->param;
|
2010-04-01 12:56:18 -06:00
|
|
|
|
|
|
|
// pass 3 - dequeue from unsuccessful chans
|
|
|
|
// otherwise they stack up on quiet channels
|
|
|
|
for(i=0; i<sel->ncase; i++) {
|
2011-01-20 07:20:47 -07:00
|
|
|
if(sg == nil || i != sg->offset) {
|
|
|
|
cas = sel->scase[i];
|
2010-04-01 12:56:18 -06:00
|
|
|
c = cas->chan;
|
2011-03-11 12:47:26 -07:00
|
|
|
if(cas->kind == CaseSend)
|
2010-04-01 12:56:18 -06:00
|
|
|
dequeueg(&c->sendq, c);
|
|
|
|
else
|
|
|
|
dequeueg(&c->recvq, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-24 16:58:44 -07:00
|
|
|
if(sg == nil)
|
|
|
|
goto loop;
|
|
|
|
|
2008-07-25 16:55:12 -06:00
|
|
|
o = sg->offset;
|
2008-12-09 17:16:07 -07:00
|
|
|
cas = sel->scase[o];
|
2008-07-25 16:55:12 -06:00
|
|
|
c = cas->chan;
|
|
|
|
|
2009-01-24 16:58:44 -07:00
|
|
|
if(c->dataqsiz > 0) {
|
|
|
|
// prints("shouldnt happen\n");
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
if(debug)
|
2011-03-11 12:47:26 -07:00
|
|
|
runtime·printf("wait-return: sel=%p c=%p cas=%p kind=%d o=%d\n",
|
|
|
|
sel, c, cas, cas->kind, o);
|
|
|
|
|
|
|
|
if(cas->kind == CaseRecv) {
|
|
|
|
if(cas->u.recv.receivedp != nil)
|
|
|
|
*cas->u.recv.receivedp = true;
|
|
|
|
if(cas->u.recv.elemp != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, cas->u.recv.elemp, sg->elem);
|
2010-04-06 18:33:43 -06:00
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, nil);
|
2008-07-26 15:21:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
freesg(c, sg);
|
|
|
|
goto retc;
|
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
asyncrecv:
|
|
|
|
// can receive from buffer
|
2011-03-11 12:47:26 -07:00
|
|
|
if(cas->u.recv.receivedp != nil)
|
|
|
|
*cas->u.recv.receivedp = true;
|
|
|
|
if(cas->u.recv.elemp != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, cas->u.recv.elemp, c->recvdataq->elem);
|
2010-04-06 18:33:43 -06:00
|
|
|
c->elemalg->copy(c->elemsize, c->recvdataq->elem, nil);
|
2008-09-19 21:43:30 -06:00
|
|
|
c->recvdataq = c->recvdataq->link;
|
|
|
|
c->qcount--;
|
|
|
|
sg = dequeue(&c->sendq, c);
|
|
|
|
if(sg != nil) {
|
|
|
|
gp = sg->g;
|
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·ready(gp);
|
2008-09-19 21:43:30 -06:00
|
|
|
}
|
|
|
|
goto retc;
|
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
asyncsend:
|
|
|
|
// can send to buffer
|
2008-09-19 21:43:30 -06:00
|
|
|
if(cas->u.elem != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, c->senddataq->elem, cas->u.elem);
|
|
|
|
c->senddataq = c->senddataq->link;
|
|
|
|
c->qcount++;
|
|
|
|
sg = dequeue(&c->recvq, c);
|
|
|
|
if(sg != nil) {
|
|
|
|
gp = sg->g;
|
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·ready(gp);
|
2008-09-19 21:43:30 -06:00
|
|
|
}
|
|
|
|
goto retc;
|
2008-08-05 15:18:47 -06:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
syncrecv:
|
|
|
|
// can receive from sleeping sender (sg)
|
|
|
|
if(debug)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("syncrecv: sel=%p c=%p o=%d\n", sel, c, o);
|
2011-03-11 12:47:26 -07:00
|
|
|
if(cas->u.recv.receivedp != nil)
|
|
|
|
*cas->u.recv.receivedp = true;
|
|
|
|
if(cas->u.recv.elemp != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, cas->u.recv.elemp, sg->elem);
|
2010-04-06 18:33:43 -06:00
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, nil);
|
2008-07-25 16:55:12 -06:00
|
|
|
gp = sg->g;
|
|
|
|
gp->param = sg;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·ready(gp);
|
2008-07-25 16:55:12 -06:00
|
|
|
goto retc;
|
|
|
|
|
2009-03-23 19:50:35 -06:00
|
|
|
rclose:
|
2010-04-01 12:56:18 -06:00
|
|
|
// read at end of closed channel
|
2011-03-11 12:47:26 -07:00
|
|
|
if(cas->u.recv.receivedp != nil)
|
|
|
|
*cas->u.recv.receivedp = false;
|
|
|
|
if(cas->u.recv.elemp != nil)
|
|
|
|
c->elemalg->copy(c->elemsize, cas->u.recv.elemp, nil);
|
2009-03-23 19:50:35 -06:00
|
|
|
goto retc;
|
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
syncsend:
|
|
|
|
// can send to sleeping receiver (sg)
|
|
|
|
if(debug)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("syncsend: sel=%p c=%p o=%d\n", sel, c, o);
|
2011-03-11 12:47:26 -07:00
|
|
|
if(c->closed)
|
2009-03-23 19:50:35 -06:00
|
|
|
goto sclose;
|
2008-07-26 15:21:21 -06:00
|
|
|
c->elemalg->copy(c->elemsize, sg->elem, cas->u.elem);
|
2008-07-25 16:55:12 -06:00
|
|
|
gp = sg->g;
|
|
|
|
gp->param = sg;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·ready(gp);
|
2008-07-24 16:57:30 -06:00
|
|
|
|
|
|
|
retc:
|
2009-12-04 11:57:01 -07:00
|
|
|
selunlock(sel);
|
2008-07-26 15:21:21 -06:00
|
|
|
|
2010-04-01 12:56:18 -06:00
|
|
|
// return to pc corresponding to chosen case
|
2011-02-22 19:10:02 -07:00
|
|
|
pc = cas->pc;
|
2011-02-22 15:40:40 -07:00
|
|
|
as = (byte*)selp + cas->so;
|
2009-10-28 19:23:53 -06:00
|
|
|
freesel(sel);
|
2008-07-24 16:57:30 -06:00
|
|
|
*as = true;
|
2011-02-22 19:10:02 -07:00
|
|
|
return pc;
|
spec, runtime, tests: send on closed channel panics
Close of closed channel panics.
Receive from closed channel never panics,
even if done repeatedly.
Fixes #1349.
Fixes #1419.
R=gri, iant, ken2, r, gri1, r2, iant2, rog, albert.strasheim, niemeyer, ejsherry
CC=golang-dev
https://golang.org/cl/3989042
2011-01-21 13:07:13 -07:00
|
|
|
|
|
|
|
sclose:
|
|
|
|
// send on closed channel
|
|
|
|
selunlock(sel);
|
|
|
|
runtime·panicstring("send on closed channel");
|
2011-02-22 19:10:02 -07:00
|
|
|
return nil; // not reached
|
2008-07-24 16:57:30 -06:00
|
|
|
}
|
|
|
|
|
2009-03-12 18:55:11 -06:00
|
|
|
// closechan(sel *byte);
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·closechan(Hchan *c)
|
2009-03-12 18:55:11 -06:00
|
|
|
{
|
2009-03-13 17:47:54 -06:00
|
|
|
SudoG *sg;
|
|
|
|
G* gp;
|
2009-03-12 18:55:11 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(runtime·gcwaiting)
|
|
|
|
runtime·gosched();
|
2010-01-09 10:47:45 -07:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(c);
|
2011-03-11 12:47:26 -07:00
|
|
|
if(c->closed) {
|
spec, runtime, tests: send on closed channel panics
Close of closed channel panics.
Receive from closed channel never panics,
even if done repeatedly.
Fixes #1349.
Fixes #1419.
R=gri, iant, ken2, r, gri1, r2, iant2, rog, albert.strasheim, niemeyer, ejsherry
CC=golang-dev
https://golang.org/cl/3989042
2011-01-21 13:07:13 -07:00
|
|
|
runtime·unlock(c);
|
|
|
|
runtime·panicstring("close of closed channel");
|
|
|
|
}
|
|
|
|
|
2011-03-11 12:47:26 -07:00
|
|
|
c->closed = true;
|
2009-03-13 17:47:54 -06:00
|
|
|
|
|
|
|
// release all readers
|
|
|
|
for(;;) {
|
|
|
|
sg = dequeue(&c->recvq, c);
|
|
|
|
if(sg == nil)
|
|
|
|
break;
|
|
|
|
gp = sg->g;
|
|
|
|
gp->param = nil;
|
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·ready(gp);
|
2009-03-13 17:47:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// release all writers
|
|
|
|
for(;;) {
|
|
|
|
sg = dequeue(&c->sendq, c);
|
|
|
|
if(sg == nil)
|
|
|
|
break;
|
|
|
|
gp = sg->g;
|
|
|
|
gp->param = nil;
|
|
|
|
freesg(c, sg);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·ready(gp);
|
2009-03-13 17:47:54 -06:00
|
|
|
}
|
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(c);
|
2009-03-12 18:55:11 -06:00
|
|
|
}
|
|
|
|
|
2009-08-26 11:47:18 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·chanclose(Hchan *c)
|
2009-08-26 11:47:18 -06:00
|
|
|
{
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·closechan(c);
|
2009-08-26 11:47:18 -06:00
|
|
|
}
|
|
|
|
|
2009-08-26 13:42:22 -06:00
|
|
|
int32
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·chanlen(Hchan *c)
|
2009-08-26 13:42:22 -06:00
|
|
|
{
|
|
|
|
return c->qcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·chancap(Hchan *c)
|
2009-08-26 13:42:22 -06:00
|
|
|
{
|
|
|
|
return c->dataqsiz;
|
|
|
|
}
|
|
|
|
|
2008-07-20 21:13:07 -06:00
|
|
|
static SudoG*
|
|
|
|
dequeue(WaitQ *q, Hchan *c)
|
|
|
|
{
|
|
|
|
SudoG *sgp;
|
|
|
|
|
|
|
|
loop:
|
|
|
|
sgp = q->first;
|
|
|
|
if(sgp == nil)
|
|
|
|
return nil;
|
|
|
|
q->first = sgp->link;
|
|
|
|
|
|
|
|
// if sgp is stale, ignore it
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(!runtime·cas(&sgp->g->selgen, sgp->selgen, sgp->selgen + 1)) {
|
2008-07-25 16:55:12 -06:00
|
|
|
//prints("INVALID PSEUDOG POINTER\n");
|
2008-07-20 21:13:07 -06:00
|
|
|
freesg(c, sgp);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sgp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-04-01 12:56:18 -06:00
|
|
|
dequeueg(WaitQ *q, Hchan *c)
|
|
|
|
{
|
|
|
|
SudoG **l, *sgp;
|
|
|
|
|
|
|
|
for(l=&q->first; (sgp=*l) != nil; l=&sgp->link) {
|
|
|
|
if(sgp->g == g) {
|
|
|
|
*l = sgp->link;
|
|
|
|
freesg(c, sgp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-07-20 21:13:07 -06:00
|
|
|
enqueue(WaitQ *q, SudoG *sgp)
|
|
|
|
{
|
|
|
|
sgp->link = nil;
|
|
|
|
if(q->first == nil) {
|
|
|
|
q->first = sgp;
|
|
|
|
q->last = sgp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
q->last->link = sgp;
|
|
|
|
q->last = sgp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SudoG*
|
|
|
|
allocsg(Hchan *c)
|
|
|
|
{
|
|
|
|
SudoG* sg;
|
|
|
|
|
|
|
|
sg = c->free;
|
|
|
|
if(sg != nil) {
|
|
|
|
c->free = sg->link;
|
|
|
|
} else
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
sg = runtime·mal(sizeof(*sg) + c->elemsize - sizeof(sg->elem));
|
2008-07-20 21:13:07 -06:00
|
|
|
sg->selgen = g->selgen;
|
|
|
|
sg->g = g;
|
2008-07-26 15:21:21 -06:00
|
|
|
sg->offset = 0;
|
2009-01-24 16:58:44 -07:00
|
|
|
sg->isfree = 0;
|
2008-07-26 15:21:21 -06:00
|
|
|
|
2008-07-20 21:13:07 -06:00
|
|
|
return sg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
freesg(Hchan *c, SudoG *sg)
|
|
|
|
{
|
2009-03-13 17:47:54 -06:00
|
|
|
if(sg != nil) {
|
|
|
|
if(sg->isfree)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("chan.freesg: already free");
|
2009-03-13 17:47:54 -06:00
|
|
|
sg->isfree = 1;
|
|
|
|
sg->link = c->free;
|
|
|
|
c->free = sg;
|
|
|
|
}
|
2008-07-20 21:13:07 -06:00
|
|
|
}
|
2008-07-24 16:57:30 -06:00
|
|
|
|
|
|
|
static uint32
|
|
|
|
fastrand1(void)
|
|
|
|
{
|
|
|
|
static uint32 x = 0x49f6428aUL;
|
|
|
|
|
|
|
|
x += x;
|
|
|
|
if(x & 0x80000000L)
|
|
|
|
x ^= 0x88888eefUL;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32
|
2011-01-20 07:20:47 -07:00
|
|
|
fastrandn(uint32 n)
|
2008-07-24 16:57:30 -06:00
|
|
|
{
|
2011-01-20 07:20:47 -07:00
|
|
|
uint32 max, r;
|
2008-07-24 16:57:30 -06:00
|
|
|
|
2011-01-20 07:20:47 -07:00
|
|
|
if(n <= 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = fastrand1();
|
|
|
|
if(r < (1ULL<<31)-n) // avoid computing max in common case
|
|
|
|
return r%n;
|
|
|
|
|
|
|
|
max = (1ULL<<31)/n * n;
|
|
|
|
while(r >= max)
|
|
|
|
r = fastrand1();
|
|
|
|
return r%n;
|
2008-07-24 16:57:30 -06:00
|
|
|
}
|