void WithInlined_Entry() { for (var i = 0; i < NumIterations; ++i) { var incResult = _inlined.Increment(); Assert(incResult.CurrentValue == incResult.PreviousValue + 1); SimulateContention(ContentionLevel.B_Moderate); var addResult = _inlined.Add(10); Assert(addResult.CurrentValue == addResult.PreviousValue + 10); SimulateContention(ContentionLevel.B_Moderate); var subResult = _inlined.Subtract(9); Assert(subResult.CurrentValue == subResult.PreviousValue - 9); SimulateContention(ContentionLevel.B_Moderate); var multResult = _inlined.MultiplyBy(3); Assert(multResult.CurrentValue == multResult.PreviousValue * 3); SimulateContention(ContentionLevel.B_Moderate); var divResult = _inlined.DivideBy(4); Assert(divResult.CurrentValue == divResult.PreviousValue / 4); SimulateContention(ContentionLevel.B_Moderate); var decResult = _inlined.Decrement(); Assert(decResult.CurrentValue == decResult.PreviousValue - 1); SimulateContention(ContentionLevel.B_Moderate); var value = _inlined.Value; var exchVal = _inlined.Exchange(value + 3); _inlined.Value = exchVal.PreviousValue - 3; } }
void WithCustomInt_Entry() { const int Bitmask = 0b101010101; for (var i = 0; i < NumIterations; ++i) { var incResult = _customInt32.Increment(); Assert(incResult.CurrentValue == incResult.PreviousValue + 1); var addResult = _customInt32.Add(10); Assert(addResult.CurrentValue == addResult.PreviousValue + 10); var subResult = _customInt32.Subtract(9); Assert(subResult.CurrentValue == subResult.PreviousValue - 9); var multResult = _customInt32.MultiplyBy(3); Assert(multResult.CurrentValue == multResult.PreviousValue * 3); var divResult = _customInt32.DivideBy(4); Assert(divResult.CurrentValue == divResult.PreviousValue / 4); var decResult = _customInt32.Decrement(); Assert(decResult.CurrentValue == decResult.PreviousValue - 1); var exchangeResult = _customInt32.Exchange(curVal => curVal & Bitmask); Assert(exchangeResult.CurrentValue == (exchangeResult.PreviousValue & Bitmask)); } }