]> Cypherpunks repositories - gostls13.git/commitdiff
time: avoid data race in abs
authorRob Pike <r@golang.org>
Wed, 22 Aug 2012 21:36:23 +0000 (14:36 -0700)
committerRob Pike <r@golang.org>
Wed, 22 Aug 2012 21:36:23 +0000 (14:36 -0700)
Fixes #3967.

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

src/pkg/time/time.go

index f898284621955d092393bb8ec44aab9d53dc17a5..ef966c3ef0e395db0a579ca7295cc9d8a71144d2 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 {