diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2024-11-15 19:22:16 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-11-18 18:52:54 +0000 |
| commit | 53b2b64b649b26c7bb3397bec5d86d3b203eb015 (patch) | |
| tree | beb5bfed693fe9226fb5fbe8b5525788654f1cb9 /src/sync | |
| parent | 5a0f2a7a7c5658f4f3065c265cee61ec1bde9691 (diff) | |
| download | go-53b2b64b649b26c7bb3397bec5d86d3b203eb015.tar.xz | |
sync: add explicit noCopy fields to Map, Mutex, and Once
Following CLs will refactor Mutex and change the internals of Map. This
ends up breaking tests in x/tools for the copylock vet check, because
the error message changes. Let's insulate ourselves from such things
permanently by adding an explicit noCopy field. We'll update the vet
check to accept that as the problem, rather than depend on less explicit
internals.
We capture Once here too to clean up the error message as well.
Change-Id: Iead985fc8ec9ef3ea5ff615f26dde17bb03aeadb
Reviewed-on: https://go-review.googlesource.com/c/go/+/627777
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Tim King <taking@google.com>
Diffstat (limited to 'src/sync')
| -rw-r--r-- | src/sync/map.go | 2 | ||||
| -rw-r--r-- | src/sync/mutex.go | 2 | ||||
| -rw-r--r-- | src/sync/once.go | 2 |
3 files changed, 6 insertions, 0 deletions
diff --git a/src/sync/map.go b/src/sync/map.go index 33bc8141ab..4f1395110a 100644 --- a/src/sync/map.go +++ b/src/sync/map.go @@ -36,6 +36,8 @@ import ( // // [the Go memory model]: https://go.dev/ref/mem type Map struct { + _ noCopy + mu Mutex // read contains the portion of the map's contents that are safe for diff --git a/src/sync/mutex.go b/src/sync/mutex.go index e4ed47c75c..cd50fcbbb5 100644 --- a/src/sync/mutex.go +++ b/src/sync/mutex.go @@ -34,6 +34,8 @@ func fatal(string) // // [the Go memory model]: https://go.dev/ref/mem type Mutex struct { + _ noCopy + state int32 sema uint32 } diff --git a/src/sync/once.go b/src/sync/once.go index 168c7bbdd3..90840b19b5 100644 --- a/src/sync/once.go +++ b/src/sync/once.go @@ -18,6 +18,8 @@ import ( // // [the Go memory model]: https://go.dev/ref/mem type Once struct { + _ noCopy + // done indicates whether the action has been performed. // It is first in the struct because it is used in the hot path. // The hot path is inlined at every call site. |
