From 8bf57c3dcba00951a96de3d8ee58d844253da621 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 6 Jun 2013 23:06:12 +0400 Subject: [PATCH] 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 --- src/pkg/runtime/chan.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/pkg/runtime/chan.c b/src/pkg/runtime/chan.c index 0a01a403d26..403a72dc8af 100644 --- a/src/pkg/runtime/chan.c +++ b/src/pkg/runtime/chan.c @@ -8,7 +8,7 @@ #include "race.h" #include "malloc.h" -#define MAXALIGN 7 +#define MAXALIGN 8 #define NOSELGEN 1 typedef struct WaitQ WaitQ; @@ -38,8 +38,8 @@ struct Hchan uintgo qcount; // total data in the q uintgo dataqsiz; // size of the circular q uint16 elemsize; + uint16 pad; // ensures proper alignment of the buffer that follows Hchan in memory bool closed; - uint8 elemalign; Alg* elemalg; // interface for element type uintgo sendx; // send index uintgo recvx; // receive index @@ -93,7 +93,6 @@ Hchan* runtime·makechan_c(ChanType *t, int64 hint) { Hchan *c; - uintptr n; Type *elem; elem = t->elem; @@ -101,26 +100,22 @@ runtime·makechan_c(ChanType *t, int64 hint) // compiler checks this but be safe. if(elem->size >= (1<<16)) 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)) runtime·panicstring("makechan: size out of range"); - // calculate rounded size of Hchan - n = sizeof(*c); - while(n & MAXALIGN) - n++; - // 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->elemalg = elem->alg; - c->elemalign = elem->align; c->dataqsiz = hint; runtime·settype(c, (uintptr)t | TypeInfo_Chan); if(debug) - runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; elemalign=%d; dataqsiz=%D\n", - c, (int64)elem->size, elem->alg, elem->align, (int64)c->dataqsiz); + runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; dataqsiz=%D\n", + c, (int64)elem->size, elem->alg, (int64)c->dataqsiz); return c; }