Files
codeql/csharp/ql/src/Documentation/XmldocMethod.cs
2018-08-02 17:53:23 +01:00

22 lines
705 B
C#

/// <summary>
/// Increments the value of the counter.
/// </summary>
///
/// <param name="incrementBy">The amount to increment.</param>
/// <exception cref="System.OverflowException">If the counter would overflow.</exception>
/// <returns>The new value of the counter.</returns>
///
/// <remarks>This method is threadsafe.</remarks>
public int Increment(int incrementBy = 1)
{
int oldValue, newValue;
do
{
oldValue = currentValue;
newValue = oldValue + incrementBy;
if (newValue < 0) throw new OverflowException("Counter value is out of range");
}
while (oldValue != Interlocked.CompareExchange(ref currentValue, newValue, oldValue));
return newValue;
}