From: Rob Pike Date: Fri, 21 Sep 2012 19:54:44 +0000 (+1000) Subject: [release-branch.go1] time: avoid data race in abs X-Git-Tag: go1.0.3~77 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=01b381f33701d8bdc773fedabc12574db00113e1;p=gostls13.git [release-branch.go1] time: avoid data race in abs ««« backport b2855a1654b6 time: avoid data race in abs Fixes #3967. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6460115 »»» --- diff --git a/src/pkg/time/time.go b/src/pkg/time/time.go index 2461dac06f..d48ca0c269 100644 --- a/src/pkg/time/time.go +++ b/src/pkg/time/time.go @@ -241,10 +241,10 @@ func (t Time) IsZero() bool { // It is called when computing a presentation property like Month or Hour. func (t Time) abs() uint64 { l := t.loc - if l == nil { - l = &utcLoc + // Avoid function calls when possible. + if l == nil || l == &localLoc { + l = l.get() } - // Avoid function call if we hit the local time cache. sec := t.sec + internalToUnix if l != &utcLoc { if l.cacheZone != nil && l.cacheStart <= sec && sec < l.cacheEnd {