public void CheckNoCustomEqualityForUnmanagedVals() { var initialVal = new DummyImmutableValAlphaOnlyEquatable(10, 20); var atomic = new LockFreeValue <DummyImmutableValAlphaOnlyEquatable>(initialVal); Assert.False(atomic.TryExchange(new DummyImmutableValAlphaOnlyEquatable(), new DummyImmutableValAlphaOnlyEquatable(initialVal.Alpha, initialVal.Bravo + 20)).ValueWasSet); }
void WithAtomicVal_EntryA() { while (_atomicValRemainingThreadCount > 0) { var curVal = _atomicVal.Value; _atomicVal.TryExchange(new Vector2(curVal.Y, curVal.X), curVal); BenchmarkUtils.SimulateContention(ContentionLevel); } }
void WithAtomicValUnmanaged_Entry() { for (var i = 0; i < NumIterations; i++) { var prevVal = _atomicValUnmanaged.Exchange(new Vector2(i, i)).PreviousValue; var curVal = _atomicValUnmanaged.TryExchange(new Vector2(prevVal.X + 2, prevVal.Y + 2), new Vector2(i, i)).CurrentValue; BenchmarkUtils.SimulateContention(ContentionLevel); prevVal = _atomicValUnmanaged.Exchange(new Vector2(curVal.X + 1, curVal.Y + 1)).PreviousValue; curVal = _atomicValUnmanaged.TryExchange(new Vector2(prevVal.X + 2, prevVal.Y + 2), new Vector2(i, i)).CurrentValue; BenchmarkUtils.SimulateContention(ContentionLevel); prevVal = _atomicValUnmanaged.Exchange(new Vector2(curVal.X + 1, curVal.Y + 1)).PreviousValue; _atomicValUnmanaged.TryExchange(new Vector2(prevVal.X + 2, prevVal.Y + 2), new Vector2(i, i)); BenchmarkUtils.SimulateContention(ContentionLevel); } }
void WithAtomicValUnmanaged_Entry() { var result = 0L; for (var i = 0; i < NumIterations; i++) { if (_atomicValUnmanaged.Value.L < i) { result += _atomicValUnmanaged.Get().L; } else { result -= _atomicValUnmanaged.Get().L; } BenchmarkUtils.SimulateContention(ContentionLevel); var curVal = _atomicValUnmanaged.Get(); BenchmarkUtils.SimulateContention(ContentionLevel); if (curVal.L >= _atomicValUnmanaged.Get().L) { if (_atomicValUnmanaged.Get().X > _atomicValUnmanaged.Get().Y) { result += (long)_atomicValUnmanaged.Get().Y; } else { result += (long)_atomicValUnmanaged.Get().X; } } else { if (_atomicValUnmanaged.Get().X > _atomicValUnmanaged.Get().Y) { result += (long)_atomicValUnmanaged.Get().X; } else { result += (long)_atomicValUnmanaged.Get().Y; } } if (_atomicValUnmanaged.Value.L < i) { result += _atomicValUnmanaged.Get().L; } else { result -= _atomicValUnmanaged.Get().L; } curVal = _atomicValUnmanaged.Get(); if (curVal.L >= _atomicValUnmanaged.Get().L) { if (_atomicValUnmanaged.Get().X > _atomicValUnmanaged.Get().Y) { result += (long)_atomicValUnmanaged.Get().Y; } else { result += (long)_atomicValUnmanaged.Get().X; } } else { if (_atomicValUnmanaged.Get().X > _atomicValUnmanaged.Get().Y) { result += (long)_atomicValUnmanaged.Get().X; } else { result += (long)_atomicValUnmanaged.Get().Y; } } BenchmarkUtils.SimulateContention(ContentionLevel); if (i % IterationsPerBarrier == 0) { if (_atomicValUnmanaged.Get().X < curVal.L) { result += _atomicValUnmanaged.TryExchange(new Vector2(curVal.L - 1L), curVal).CurrentValue.L; } else { result += _atomicValUnmanaged.TryExchange(new Vector2(curVal.L + 1L), curVal).CurrentValue.L; } _atomicValUnmanagedSyncBarrier.SignalAndWait(); } BenchmarkUtils.SimulateContention(ContentionLevel); } if (result == 0L) { Console.Beep(1000, 100); } }