Commit 3935610e authored by Russ Cox's avatar Russ Cox

chans and maps of interfaces

R=r
DELTA=746  (729 added, 1 deleted, 16 changed)
OCL=20858
CL=20858
parent 50d0695c
......@@ -17,10 +17,10 @@ typedef struct Scase Scase;
struct SudoG
{
G* g; // g and selgen constitute
byte elem[8]; // synch data element
int16 offset; // offset of case number
int32 selgen; // a weak pointer to g
SudoG* link;
byte elem[8]; // synch data element (+ more)
};
struct WaitQ
......@@ -45,7 +45,7 @@ struct Hchan
struct Link
{
Link* link; // asynch queue circular linked list
byte elem[8]; // asynch queue data element
byte elem[8]; // asynch queue data element (+ more)
};
struct Scase
......@@ -65,7 +65,7 @@ struct Select
uint16 tcase; // total count of scase[]
uint16 ncase; // currently filled scase[]
Select* link; // for freelist
Scase scase[1]; // one per case
Scase* scase[1]; // one per case
};
static Select* selfree[20];
......@@ -108,7 +108,7 @@ sys·newchan(uint32 elemsize, uint32 elemalg, uint32 hint,
b = nil;
e = nil;
for(i=0; i<hint; i++) {
d = mal(sizeof(*d));
d = mal(sizeof(*d) + c->elemsize - sizeof(d->elem));
if(e == nil)
e = d;
d->link = b;
......@@ -430,7 +430,11 @@ sys·selectsend(Select *sel, Hchan *c, ...)
if(i >= sel->tcase)
throw("selectsend: too many cases");
sel->ncase = i+1;
cas = &sel->scase[i];
cas = sel->scase[i];
if(cas == nil) {
cas = mal(sizeof *cas + c->elemsize - sizeof(cas->u.elem));
sel->scase[i] = cas;
}
cas->pc = sys·getcallerpc(&sel);
cas->chan = c;
......@@ -473,8 +477,11 @@ sys·selectrecv(Select *sel, Hchan *c, ...)
if(i >= sel->tcase)
throw("selectrecv: too many cases");
sel->ncase = i+1;
cas = &sel->scase[i];
cas = sel->scase[i];
if(cas == nil) {
cas = mal(sizeof *cas);
sel->scase[i] = cas;
}
cas->pc = sys·getcallerpc(&sel);
cas->chan = c;
......@@ -511,8 +518,11 @@ sys·selectdefault(Select *sel, ...)
if(i >= sel->tcase)
throw("selectdefault: too many cases");
sel->ncase = i+1;
cas = &sel->scase[i];
cas = sel->scase[i];
if(cas == nil) {
cas = mal(sizeof *cas);
sel->scase[i] = cas;
}
cas->pc = sys·getcallerpc(&sel);
cas->chan = nil;
......@@ -579,7 +589,7 @@ sys·selectgo(Select *sel)
// pass 1 - look for something already waiting
dfl = nil;
for(i=0; i<sel->ncase; i++) {
cas = &sel->scase[o];
cas = sel->scase[o];
if(cas->send == 2) { // default
dfl = cas;
......@@ -622,7 +632,7 @@ sys·selectgo(Select *sel)
// pass 2 - enqueue on all chans
for(i=0; i<sel->ncase; i++) {
cas = &sel->scase[o];
cas = sel->scase[o];
c = cas->chan;
if(c->dataqsiz > 0) {
......@@ -682,7 +692,7 @@ sys·selectgo(Select *sel)
lock(&chanlock);
sg = g->param;
o = sg->offset;
cas = &sel->scase[o];
cas = sel->scase[o];
c = cas->chan;
if(xxx) {
......@@ -832,7 +842,7 @@ allocsg(Hchan *c)
if(sg != nil) {
c->free = sg->link;
} else
sg = mal(sizeof(*sg));
sg = mal(sizeof(*sg) + c->elemsize - sizeof(sg->elem));
sg->selgen = g->selgen;
sg->g = g;
sg->offset = 0;
......
......@@ -8,6 +8,7 @@
/* Return a pointer to the struct/union of type "type"
whose "field" field is addressed by pointer "p". */
struct hash { /* a hash table; initialize with hash_init() */
uint32 count; /* elements in table - must be first */
......@@ -662,8 +663,8 @@ sys·newmap(uint32 keysize, uint32 valsize,
{
Hmap *h;
if(keyalg >= 3 ||
valalg >= 3) {
if(keyalg >= 4 ||
valalg >= 4) {
prints("0<=");
sys·printint(keyalg);
prints("<");
......
......@@ -644,11 +644,12 @@ pointercopy(uint32 s, void **a, void **b)
}
Alg
algarray[3] =
algarray[4] =
{
{ memhash, memequal, memprint, memcopy }, // 0
{ stringhash, stringequal, stringprint, stringcopy }, // 1
// { pointerhash, pointerequal, pointerprint, pointercopy }, // 2
{ memhash, memequal, memprint, memcopy }, // 2 - treat pointers as ints
{ memhash, memequal, memprint, memcopy }, // 3 - treat interfaces as memory
};
......@@ -220,7 +220,7 @@ struct Func
/*
* external data
*/
extern Alg algarray[3];
extern Alg algarray[4];
extern string emptystring;
G* allg;
int32 goidgen;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment