runtime: use threads slice in parfor instead of unsafe pointer math

parfor originally used a tail array for its thread array.  This got
replaced with a slice allocation in the conversion to Go, but many of
its gnarlier effects remained.  Instead of keeping track of the
pointer to the first element of the slice and using unsafe pointer
math to get at the ith element, just keep the slice around and use
regular slice indexing.  There is no longer any need for padding to
64-bit align the tail array (there hasn't been since the Go
conversion), so remove this unnecessary padding from the parfor
struct.  Finally, since the slice tracks its own length, replace the
nthrmax field with len(thr).

Change-Id: I0020a1815849bca53e3613a8fa46ae4fbae67576
Reviewed-on: https://go-review.googlesource.com/3394
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Austin Clements 2015-01-28 15:25:05 -05:00
parent 6b7b0f9a0c
commit 8e2bb7bb4a
2 changed files with 24 additions and 34 deletions

View file

@ -36,14 +36,13 @@ func LFStackPop(head *uint64) *LFNode {
}
type ParFor struct {
body *byte
done uint32
Nthr uint32
nthrmax uint32
thrseq uint32
Cnt uint32
Ctx *byte
wait bool
body *byte
done uint32
Nthr uint32
thrseq uint32
Cnt uint32
Ctx *byte
wait bool
}
func NewParFor(nthrmax uint32) *ParFor {
@ -69,7 +68,7 @@ func ParForDo(desc *ParFor) {
func ParForIters(desc *ParFor, tid uint32) (uint32, uint32) {
desc1 := (*parfor)(unsafe.Pointer(desc))
pos := desc_thr_index(desc1, tid).pos
pos := desc1.thr[tid].pos
return uint32(pos), uint32(pos >> 32)
}