diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-01-14 00:05:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-01-14 00:05:42 +0000 |
commit | c2047754c300b68c05d65faa8dc2925fe67b71b4 (patch) | |
tree | e183ae81a1f48a02945cb6de463a70c5be1b06f6 /libgo/go/context/context.go | |
parent | 829afb8f05602bb31c9c597b24df7377fed4f059 (diff) | |
download | gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.zip gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.gz gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.bz2 |
libgo: update to Go 1.8 release candidate 1
Compiler changes:
* Change map assignment to use mapassign and assign value directly.
* Change string iteration to use decoderune, faster for ASCII strings.
* Change makeslice to take int, and use makeslice64 for larger values.
* Add new noverflow field to hmap struct used for maps.
Unresolved problems, to be fixed later:
* Commented out test in go/types/sizes_test.go that doesn't compile.
* Commented out reflect.TestStructOf test for padding after zero-sized field.
Reviewed-on: https://go-review.googlesource.com/35231
gotools/:
Updates for Go 1.8rc1.
* Makefile.am (go_cmd_go_files): Add bug.go.
(s-zdefaultcc): Write defaultPkgConfig.
* Makefile.in: Rebuild.
From-SVN: r244456
Diffstat (limited to 'libgo/go/context/context.go')
-rw-r--r-- | libgo/go/context/context.go | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/libgo/go/context/context.go b/libgo/go/context/context.go index f8ce9cc..0aa7c24 100644 --- a/libgo/go/context/context.go +++ b/libgo/go/context/context.go @@ -159,9 +159,9 @@ var DeadlineExceeded error = deadlineExceededError{} type deadlineExceededError struct{} -func (deadlineExceededError) Error() string { return "context deadline exceeded" } - -func (deadlineExceededError) Timeout() bool { return true } +func (deadlineExceededError) Error() string { return "context deadline exceeded" } +func (deadlineExceededError) Timeout() bool { return true } +func (deadlineExceededError) Temporary() bool { return true } // An emptyCtx is never canceled, has no values, and has no deadline. It is not // struct{}, since vars of this type must have distinct addresses. @@ -252,9 +252,9 @@ func propagateCancel(parent Context, child canceler) { child.cancel(false, p.err) } else { if p.children == nil { - p.children = make(map[canceler]bool) + p.children = make(map[canceler]struct{}) } - p.children[child] = true + p.children[child] = struct{}{} } p.mu.Unlock() } else { @@ -314,8 +314,8 @@ type cancelCtx struct { done chan struct{} // closed by the first cancel call. mu sync.Mutex - children map[canceler]bool // set to nil by the first cancel call - err error // set to non-nil by the first cancel call + children map[canceler]struct{} // set to nil by the first cancel call + err error // set to non-nil by the first cancel call } func (c *cancelCtx) Done() <-chan struct{} { @@ -376,7 +376,7 @@ func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) { deadline: deadline, } propagateCancel(parent, c) - d := deadline.Sub(time.Now()) + d := time.Until(deadline) if d <= 0 { c.cancel(true, DeadlineExceeded) // deadline has already passed return c, func() { c.cancel(true, Canceled) } @@ -406,7 +406,7 @@ func (c *timerCtx) Deadline() (deadline time.Time, ok bool) { } func (c *timerCtx) String() string { - return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, c.deadline.Sub(time.Now())) + return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, time.Until(c.deadline)) } func (c *timerCtx) cancel(removeFromParent bool, err error) { @@ -443,7 +443,13 @@ func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) { // Use context Values only for request-scoped data that transits processes and // APIs, not for passing optional parameters to functions. // -// The provided key must be comparable. +// The provided key must be comparable and should not be of type +// string or any other built-in type to avoid collisions between +// packages using context. Users of WithValue should define their own +// types for keys. To avoid allocating when assigning to an +// interface{}, context keys often have concrete type +// struct{}. Alternatively, exported context key variables' static +// type should be a pointer or interface. func WithValue(parent Context, key, val interface{}) Context { if key == nil { panic("nil key") |