mirror of
https://github.com/golang/go
synced 2024-11-25 21:28:03 -07:00
runtime: remove unused field from Hchan
Remove alignment logic as well, it's not respected by chanbuf() anyway. R=golang-dev, dave, minux.ma, r, iant, rsc CC=golang-dev https://golang.org/cl/9678046
This commit is contained in:
parent
5d637b83a9
commit
8bf57c3dcb
@ -8,7 +8,7 @@
|
|||||||
#include "race.h"
|
#include "race.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
|
||||||
#define MAXALIGN 7
|
#define MAXALIGN 8
|
||||||
#define NOSELGEN 1
|
#define NOSELGEN 1
|
||||||
|
|
||||||
typedef struct WaitQ WaitQ;
|
typedef struct WaitQ WaitQ;
|
||||||
@ -38,8 +38,8 @@ struct Hchan
|
|||||||
uintgo qcount; // total data in the q
|
uintgo qcount; // total data in the q
|
||||||
uintgo dataqsiz; // size of the circular q
|
uintgo dataqsiz; // size of the circular q
|
||||||
uint16 elemsize;
|
uint16 elemsize;
|
||||||
|
uint16 pad; // ensures proper alignment of the buffer that follows Hchan in memory
|
||||||
bool closed;
|
bool closed;
|
||||||
uint8 elemalign;
|
|
||||||
Alg* elemalg; // interface for element type
|
Alg* elemalg; // interface for element type
|
||||||
uintgo sendx; // send index
|
uintgo sendx; // send index
|
||||||
uintgo recvx; // receive index
|
uintgo recvx; // receive index
|
||||||
@ -93,7 +93,6 @@ Hchan*
|
|||||||
runtime·makechan_c(ChanType *t, int64 hint)
|
runtime·makechan_c(ChanType *t, int64 hint)
|
||||||
{
|
{
|
||||||
Hchan *c;
|
Hchan *c;
|
||||||
uintptr n;
|
|
||||||
Type *elem;
|
Type *elem;
|
||||||
|
|
||||||
elem = t->elem;
|
elem = t->elem;
|
||||||
@ -101,26 +100,22 @@ runtime·makechan_c(ChanType *t, int64 hint)
|
|||||||
// compiler checks this but be safe.
|
// compiler checks this but be safe.
|
||||||
if(elem->size >= (1<<16))
|
if(elem->size >= (1<<16))
|
||||||
runtime·throw("makechan: invalid channel element type");
|
runtime·throw("makechan: invalid channel element type");
|
||||||
|
if((sizeof(*c)%MAXALIGN) != 0 || elem->align > MAXALIGN)
|
||||||
|
runtime·throw("makechan: bad alignment");
|
||||||
|
|
||||||
if(hint < 0 || (intgo)hint != hint || (elem->size > 0 && hint > MaxMem / elem->size))
|
if(hint < 0 || (intgo)hint != hint || (elem->size > 0 && hint > MaxMem / elem->size))
|
||||||
runtime·panicstring("makechan: size out of range");
|
runtime·panicstring("makechan: size out of range");
|
||||||
|
|
||||||
// calculate rounded size of Hchan
|
|
||||||
n = sizeof(*c);
|
|
||||||
while(n & MAXALIGN)
|
|
||||||
n++;
|
|
||||||
|
|
||||||
// allocate memory in one call
|
// allocate memory in one call
|
||||||
c = (Hchan*)runtime·mal(n + hint*elem->size);
|
c = (Hchan*)runtime·mal(sizeof(*c) + hint*elem->size);
|
||||||
c->elemsize = elem->size;
|
c->elemsize = elem->size;
|
||||||
c->elemalg = elem->alg;
|
c->elemalg = elem->alg;
|
||||||
c->elemalign = elem->align;
|
|
||||||
c->dataqsiz = hint;
|
c->dataqsiz = hint;
|
||||||
runtime·settype(c, (uintptr)t | TypeInfo_Chan);
|
runtime·settype(c, (uintptr)t | TypeInfo_Chan);
|
||||||
|
|
||||||
if(debug)
|
if(debug)
|
||||||
runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; elemalign=%d; dataqsiz=%D\n",
|
runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; dataqsiz=%D\n",
|
||||||
c, (int64)elem->size, elem->alg, elem->align, (int64)c->dataqsiz);
|
c, (int64)elem->size, elem->alg, (int64)c->dataqsiz);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user