]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove unused field from Hchan
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 6 Jun 2013 19:06:12 +0000 (23:06 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 6 Jun 2013 19:06:12 +0000 (23:06 +0400)
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

index 0a01a403d26970bb642d88970f1dd420c2cb4034..403a72dc8af9cbccbf0d3682e6e0978ea38bd932 100644 (file)
@@ -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;
 }