Skip to content

Commit

Permalink
noCopy implements sync.Locker (#1216)
Browse files Browse the repository at this point in the history
noCopy is used by -copylocks checker from `go vet`.
see golang/go#8005 (comment) for details.
but it doesn't work from Go 1.11, because of golang/go@c2eba53 and golang/go#26165
-copylock now works with structs that implement sync.Locker.
So, noCopy should implement sync.Locker.
  • Loading branch information
shogo82148 committed May 26, 2021
1 parent 9942e21 commit 4b65372
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,12 @@ type noCopy struct{}
// Lock is a no-op used by -copylocks checker from `go vet`.
func (*noCopy) Lock() {}

// Unlock is a no-op used by -copylocks checker from `go vet`.
// noCopy should implement sync.Locker from Go 1.11
// https://github.com/golang/go/commit/c2eba53e7f80df21d51285879d51ab81bcfbf6bc
// https://github.com/golang/go/issues/26165
func (*noCopy) Unlock() {}

// atomicBool is a wrapper around uint32 for usage as a boolean value with
// atomic access.
type atomicBool struct {
Expand Down
4 changes: 3 additions & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ func TestAtomicBool(t *testing.T) {
t.Fatal("Expected value to be false")
}

ab._noCopy.Lock() // we've "tested" it ¯\_(ツ)_/¯
// we've "tested" them ¯\_(ツ)_/¯
ab._noCopy.Lock()
defer ab._noCopy.Unlock()
}

func TestAtomicError(t *testing.T) {
Expand Down

0 comments on commit 4b65372

Please sign in to comment.