From 906eb6295d54a05663a223f1dc379a16148de2d1 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 18 Feb 2020 13:42:31 -0800 Subject: atomicbitops package cleanups - Redocument memory ordering from "no ordering" to "acquire-release". (No functional change: both LOCK WHATEVER on x86, and LDAXR/STLXR loops on ARM64, already have this property.) - Remove IncUnlessZeroInt32 and DecUnlessOneInt32, which were only faster than the equivalent loops using sync/atomic before the Go compiler inlined non-unsafe.Pointer atomics many releases ago. PiperOrigin-RevId: 295811743 --- pkg/atomicbitops/atomicbitops_test.go | 198 ++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 pkg/atomicbitops/atomicbitops_test.go (limited to 'pkg/atomicbitops/atomicbitops_test.go') diff --git a/pkg/atomicbitops/atomicbitops_test.go b/pkg/atomicbitops/atomicbitops_test.go new file mode 100644 index 000000000..73af71bb4 --- /dev/null +++ b/pkg/atomicbitops/atomicbitops_test.go @@ -0,0 +1,198 @@ +// Copyright 2018 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package atomicbitops + +import ( + "runtime" + "testing" + + "gvisor.dev/gvisor/pkg/sync" +) + +const iterations = 100 + +func detectRaces32(val, target uint32, fn func(*uint32, uint32)) bool { + runtime.GOMAXPROCS(100) + for n := 0; n < iterations; n++ { + x := val + var wg sync.WaitGroup + for i := uint32(0); i < 32; i++ { + wg.Add(1) + go func(a *uint32, i uint32) { + defer wg.Done() + fn(a, uint32(1<