Skip to content

Commit

Permalink
SWEEP: Reviewed usage of atomic numeric type methods (#927)
Browse files Browse the repository at this point in the history
* SWEEP: Reviewed all applications of .AddAndGet() methods from atomic numeric classes

* SWEEP: Reviewed all applications of .GetAndAdd() methods from atomic numeric classes

* SWEEP: Reviewed all applications of .IncrementAndGet(), .GetAndIncrement(), .DecrementAndGet(), and .GetAndDecrement() from atomic numeric classes. Closes #917.
  • Loading branch information
NightOwl888 committed Mar 11, 2024
1 parent 4356997 commit 63e1053
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Lucene.Net.Replicator/LocalReplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -189,7 +190,7 @@ public virtual SessionToken CheckForUpdate(string currentVersion)
// currentVersion is either null or older than latest published revision
currentRevision.IncRef();

string sessionID = sessionToken.IncrementAndGet().ToString();
string sessionID = sessionToken.IncrementAndGet().ToString(CultureInfo.InvariantCulture);
SessionToken token = new SessionToken(sessionID, currentRevision.Revision);
sessions[sessionID] = new ReplicationSession(token, currentRevision);
return token;
Expand Down Expand Up @@ -329,4 +330,4 @@ public virtual void Release(string sessionId)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public override long GetCost()
// Holds all indexes created, keyed by the ID assigned in fieldsConsumer
private readonly IDictionary<int, RAMPostings> state = new Dictionary<int, RAMPostings>();

private readonly AtomicInt64 nextID = new AtomicInt64();
private readonly AtomicInt32 nextID = new AtomicInt32();

private readonly string RAM_ONLY_NAME = "RAMOnly";
private const int VERSION_START = 0;
Expand All @@ -582,7 +582,7 @@ public override long GetCost()

public override FieldsConsumer FieldsConsumer(SegmentWriteState writeState)
{
int id = (int)nextID.GetAndIncrement();
int id = nextID.GetAndIncrement();

// TODO -- ok to do this up front instead of
// on close....? should be ok?
Expand Down Expand Up @@ -659,4 +659,4 @@ public override FieldsProducer FieldsProducer(SegmentReadState readState)
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public override IndexOutput CreateOutput(string name, IOContext context)
{
if (existing != null)
{
ramdir.m_sizeInBytes.AddAndGet(-existing.GetSizeInBytes()); // LUCENENET: GetAndAdd in Lucene, but we are not using the value
ramdir.m_sizeInBytes.GetAndAdd(-existing.GetSizeInBytes());
existing.directory = null;
}
ramdir.m_fileMap[name] = file;
Expand Down Expand Up @@ -1558,4 +1558,4 @@ protected FakeIOException(SerializationInfo info, StreamingContext context)
}
#endif
}
}
}
2 changes: 1 addition & 1 deletion src/Lucene.Net.Tests/Search/TestBooleanOr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public virtual void TestBooleanScorerMax()
while (end.Value < docCount)
{
int inc = TestUtil.NextInt32(Random, 1, 1000);
end.AddAndGet(inc);
end.GetAndAdd(inc);
scorer.Score(c, end);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net/Store/RAMFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected internal byte[] AddBuffer(int size)
UninterruptableMonitor.Exit(this);
}

directory?.m_sizeInBytes.AddAndGet(size);
directory?.m_sizeInBytes.GetAndAdd(size);
return buffer;
}

Expand Down Expand Up @@ -146,4 +146,4 @@ public virtual long GetSizeInBytes()
}
}
}
}
}

0 comments on commit 63e1053

Please sign in to comment.