Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWEEP: Reviewed usage of atomic numeric type methods #927

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
}
}
}
Loading