]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] time: avoid data race in abs
authorRob Pike <r@golang.org>
Fri, 21 Sep 2012 19:54:44 +0000 (05:54 +1000)
committerRob Pike <r@golang.org>
Fri, 21 Sep 2012 19:54:44 +0000 (05:54 +1000)
««« backport b2855a1654b6
time: avoid data race in abs
Fixes #3967.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6460115

»»»

src/pkg/time/time.go

index 2461dac06f5cf2cf53ea60f2fbce176ecb36d1ca..d48ca0c269e0815ab7e984f133f1b76be4c44265 100644 (file)
@@ -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 {