]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: put lockorder before pollorder in Select memory block.
authorIan Lance Taylor <iant@golang.org>
Sat, 11 Feb 2012 05:24:14 +0000 (21:24 -0800)
committerIan Lance Taylor <iant@golang.org>
Sat, 11 Feb 2012 05:24:14 +0000 (21:24 -0800)
Otherwise lockorder may be misaligned, since lockorder is a
list of pointers and pollorder is a list of uint16.
Discovered running gccgo (which uses a modified copy of this
code) on SPARC.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5655054

src/pkg/runtime/chan.c

index bea1a34f8f0e6116d70ea503fcb4b4d73063ebfb..ef27144ef322b82fea8ac3427792a0c377e4dea4 100644 (file)
@@ -586,6 +586,10 @@ newselect(int32 size, Select **selp)
        if(size > 1)
                n = size-1;
 
+       // allocate all the memory we need in a single allocation
+       // start with Select with size cases
+       // then lockorder with size entries
+       // then pollorder with size entries
        sel = runtimeĀ·mal(sizeof(*sel) +
                n*sizeof(sel->scase[0]) +
                size*sizeof(sel->lockorder[0]) +
@@ -593,8 +597,8 @@ newselect(int32 size, Select **selp)
 
        sel->tcase = size;
        sel->ncase = 0;
-       sel->pollorder = (void*)(sel->scase + size);
-       sel->lockorder = (void*)(sel->pollorder + size);
+       sel->lockorder = (void*)(sel->scase + size);
+       sel->pollorder = (void*)(sel->lockorder + size);
        *selp = sel;
 
        if(debug)