diff options
| author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-04-15 00:33:28 +0300 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2016-05-06 16:43:51 +0000 |
| commit | c81a3532fea42df33dea54497dfaa96873c2d976 (patch) | |
| tree | 46da51ae16ddd945e341446aa6fdc7140068bdbc /src/sync/atomic/value.go | |
| parent | 258a4c3daf992958f5d7dc5bccf2c5b41e236959 (diff) | |
| download | go-c81a3532fea42df33dea54497dfaa96873c2d976.tar.xz | |
cmd/vet: check sync.* types' copying
Embed noLock struct into the following types, so `go vet -copylocks` catches
their copying additionally to types containing sync.Mutex:
- sync.Cond
- sync.WaitGroup
- sync.Pool
- atomic.Value
Fixes #14582
Change-Id: Icb543ef5ad10524ad239a15eec8a9b334b0e0660
Reviewed-on: https://go-review.googlesource.com/22015
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/sync/atomic/value.go')
| -rw-r--r-- | src/sync/atomic/value.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/sync/atomic/value.go b/src/sync/atomic/value.go index ab3aa11285..30abf72634 100644 --- a/src/sync/atomic/value.go +++ b/src/sync/atomic/value.go @@ -12,7 +12,11 @@ import ( // Values can be created as part of other data structures. // The zero value for a Value returns nil from Load. // Once Store has been called, a Value must not be copied. +// +// A Value must not be copied after first use. type Value struct { + noCopy noCopy + v interface{} } @@ -83,3 +87,13 @@ func (v *Value) Store(x interface{}) { // Disable/enable preemption, implemented in runtime. func runtime_procPin() func runtime_procUnpin() + +// noCopy may be embedded into structs which must not be copied +// after the first use. +// +// See https://github.com/golang/go/issues/8005#issuecomment-190753527 +// for details. +type noCopy struct{} + +// Lock is a no-op used by -copylocks checker from `go vet`. +func (*noCopy) Lock() {} |
