Skip to content

Commit 6ec0e6f

Browse files
paulirwinclaude
andcommitted
Rename CountDownLatch to CountdownLatch with Wait/Signal methods, #1284
Align the latch's naming with .NET's CountdownEvent: rename the type CountDownLatch -> CountdownLatch, Await()/Await(TimeSpan) -> Wait()/Wait(TimeSpan), and CountDown() -> Signal(). Upstream-Java references in comments are left as-is. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ac308dd commit 6ec0e6f

25 files changed

Lines changed: 265 additions & 265 deletions

src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,15 +630,15 @@ internal class AnalysisThread : ThreadJob
630630
internal readonly bool simple;
631631
internal readonly bool offsetsAreCorrect;
632632
internal readonly RandomIndexWriter iw;
633-
private readonly CountDownLatch latch;
633+
private readonly CountdownLatch latch;
634634

635635
// NOTE: not volatile because we don't want the tests to
636636
// add memory barriers (ie alter how threads
637637
// interact)... so this is just "best effort":
638638
public bool Failed { get; set; }
639639
public Exception FirstException { get; set; } = null;
640640

641-
internal AnalysisThread(long seed, CountDownLatch latch, Analyzer a, int iterations, int maxWordLength,
641+
internal AnalysisThread(long seed, CountdownLatch latch, Analyzer a, int iterations, int maxWordLength,
642642
bool useCharFilter, bool simple, bool offsetsAreCorrect, RandomIndexWriter iw)
643643
{
644644
this.seed = seed;
@@ -657,7 +657,7 @@ public override void Run()
657657
bool success = false;
658658
try
659659
{
660-
if (latch != null) latch.Await();
660+
if (latch != null) latch.Wait();
661661
// see the part in checkRandomData where it replays the same text again
662662
// to verify reproducability/reuse: hopefully this would catch thread hazards.
663663
CheckRandomData(new J2N.Randomizer(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
@@ -711,7 +711,7 @@ public static void CheckRandomData(Random random, Analyzer a, int iterations, in
711711
// now test with multiple threads: note we do the EXACT same thing we did before in each thread,
712712
// so this should only really fail from another thread if its an actual thread problem
713713
int numThreads = TestUtil.NextInt32(random, 2, 4);
714-
using var startingGun = new CountDownLatch(1);
714+
using var startingGun = new CountdownLatch(1);
715715
var threads = new AnalysisThread[numThreads];
716716
for (int i = 0; i < threads.Length; i++)
717717
{
@@ -723,7 +723,7 @@ public static void CheckRandomData(Random random, Analyzer a, int iterations, in
723723
thread.Start();
724724
}
725725

726-
startingGun.CountDown();
726+
startingGun.Signal();
727727
foreach (var t in threads)
728728
{
729729
try

src/Lucene.Net.TestFramework/Index/BaseDocValuesFormatTestCase.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,13 +3244,13 @@ public virtual void TestThreads()
32443244
using DirectoryReader ir = DirectoryReader.Open(dir);
32453245
int numThreads = TestUtil.NextInt32(Random, 2, 7);
32463246
ThreadJob[] threads = new ThreadJob[numThreads];
3247-
using CountDownLatch startingGun = new CountDownLatch(1);
3247+
using CountdownLatch startingGun = new CountdownLatch(1);
32483248
for (int i = 0; i < threads.Length; i++)
32493249
{
32503250
threads[i] = new ThreadAnonymousClass(ir, startingGun);
32513251
threads[i].Start();
32523252
}
3253-
startingGun.CountDown();
3253+
startingGun.Signal();
32543254
foreach (ThreadJob t in threads)
32553255
{
32563256
t.Join();
@@ -3260,9 +3260,9 @@ public virtual void TestThreads()
32603260
private sealed class ThreadAnonymousClass : ThreadJob
32613261
{
32623262
private readonly DirectoryReader ir;
3263-
private readonly CountDownLatch startingGun;
3263+
private readonly CountdownLatch startingGun;
32643264

3265-
public ThreadAnonymousClass(DirectoryReader ir, CountDownLatch startingGun)
3265+
public ThreadAnonymousClass(DirectoryReader ir, CountdownLatch startingGun)
32663266
{
32673267
this.ir = ir;
32683268
this.startingGun = startingGun;
@@ -3272,7 +3272,7 @@ public override void Run()
32723272
{
32733273
try
32743274
{
3275-
startingGun.Await();
3275+
startingGun.Wait();
32763276
BytesRef scratch = new BytesRef(); // LUCENENET: Moved outside of the loop for performance
32773277
foreach (AtomicReaderContext context in ir.Leaves)
32783278
{
@@ -3380,13 +3380,13 @@ public virtual void TestThreads2()
33803380
using DirectoryReader ir = DirectoryReader.Open(dir);
33813381
int numThreads = TestUtil.NextInt32(Random, 2, 7);
33823382
ThreadJob[] threads = new ThreadJob[numThreads];
3383-
using CountDownLatch startingGun = new CountDownLatch(1);
3383+
using CountdownLatch startingGun = new CountdownLatch(1);
33843384
for (int i = 0; i < threads.Length; i++)
33853385
{
33863386
threads[i] = new ThreadAnonymousClass2(ir, startingGun);
33873387
threads[i].Start();
33883388
}
3389-
startingGun.CountDown();
3389+
startingGun.Signal();
33903390
foreach (ThreadJob t in threads)
33913391
{
33923392
t.Join();
@@ -3396,9 +3396,9 @@ public virtual void TestThreads2()
33963396
private sealed class ThreadAnonymousClass2 : ThreadJob
33973397
{
33983398
private readonly DirectoryReader ir;
3399-
private readonly CountDownLatch startingGun;
3399+
private readonly CountdownLatch startingGun;
34003400

3401-
public ThreadAnonymousClass2(DirectoryReader ir, CountDownLatch startingGun)
3401+
public ThreadAnonymousClass2(DirectoryReader ir, CountdownLatch startingGun)
34023402
{
34033403
this.ir = ir;
34043404
this.startingGun = startingGun;
@@ -3408,7 +3408,7 @@ public override void Run()
34083408
{
34093409
try
34103410
{
3411-
startingGun.Await();
3411+
startingGun.Wait();
34123412
foreach (AtomicReaderContext context in ir.Leaves)
34133413
{
34143414
AtomicReader r = context.AtomicReader;

src/Lucene.Net.Tests/Index/TestBagOfPositions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public virtual void Test()
117117
// else just positions
118118

119119
ThreadJob[] threads = new ThreadJob[threadCount];
120-
CountDownLatch startingGun = new CountDownLatch(1);
120+
CountdownLatch startingGun = new CountdownLatch(1);
121121

122122
for (int threadID = 0; threadID < threadCount; threadID++)
123123
{
@@ -128,7 +128,7 @@ public virtual void Test()
128128
threads[threadID] = new ThreadAnonymousClass(maxTermsPerDoc, postings, iw, startingGun, threadRandom, document, field);
129129
threads[threadID].Start();
130130
}
131-
startingGun.CountDown();
131+
startingGun.Signal();
132132
foreach (ThreadJob t in threads)
133133
{
134134
t.Join();
@@ -160,12 +160,12 @@ private sealed class ThreadAnonymousClass : ThreadJob
160160
private readonly int maxTermsPerDoc;
161161
private readonly ConcurrentQueue<string> postings;
162162
private readonly RandomIndexWriter iw;
163-
private readonly CountDownLatch startingGun;
163+
private readonly CountdownLatch startingGun;
164164
private readonly Random threadRandom;
165165
private readonly Document document;
166166
private readonly Field field;
167167

168-
public ThreadAnonymousClass(int maxTermsPerDoc, ConcurrentQueue<string> postings, RandomIndexWriter iw, CountDownLatch startingGun, Random threadRandom, Document document, Field field)
168+
public ThreadAnonymousClass(int maxTermsPerDoc, ConcurrentQueue<string> postings, RandomIndexWriter iw, CountdownLatch startingGun, Random threadRandom, Document document, Field field)
169169
{
170170
this.maxTermsPerDoc = maxTermsPerDoc;
171171
this.postings = postings;
@@ -180,7 +180,7 @@ public override void Run()
180180
{
181181
try
182182
{
183-
startingGun.Await();
183+
startingGun.Wait();
184184
while (!postings.IsEmpty)
185185
{
186186
StringBuilder text = new StringBuilder();

src/Lucene.Net.Tests/Index/TestBagOfPostings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public virtual void Test()
9696
}
9797

9898
ThreadJob[] threads = new ThreadJob[threadCount];
99-
CountDownLatch startingGun = new CountDownLatch(1);
99+
CountdownLatch startingGun = new CountdownLatch(1);
100100

101101
for (int threadID = 0; threadID < threadCount; threadID++)
102102
{
103103
threads[threadID] = new ThreadAnonymousClass(maxTermsPerDoc, postings, iw, startingGun);
104104
threads[threadID].Start();
105105
}
106-
startingGun.CountDown();
106+
startingGun.Signal();
107107
foreach (ThreadJob t in threads)
108108
{
109109
t.Join();
@@ -141,9 +141,9 @@ private sealed class ThreadAnonymousClass : ThreadJob
141141
private readonly int maxTermsPerDoc;
142142
private readonly ConcurrentQueue<string> postings;
143143
private readonly RandomIndexWriter iw;
144-
private readonly CountDownLatch startingGun;
144+
private readonly CountdownLatch startingGun;
145145

146-
public ThreadAnonymousClass(int maxTermsPerDoc, ConcurrentQueue<string> postings, RandomIndexWriter iw, CountDownLatch startingGun)
146+
public ThreadAnonymousClass(int maxTermsPerDoc, ConcurrentQueue<string> postings, RandomIndexWriter iw, CountdownLatch startingGun)
147147
{
148148
this.maxTermsPerDoc = maxTermsPerDoc;
149149
this.postings = postings;
@@ -158,7 +158,7 @@ public override void Run()
158158
Document document = new Document();
159159
Field field = NewTextField("field", "", Field.Store.NO);
160160
document.Add(field);
161-
startingGun.Await();
161+
startingGun.Wait();
162162
while (!postings.IsEmpty)
163163
{
164164
StringBuilder text = new StringBuilder();

src/Lucene.Net.Tests/Index/TestBinaryDocValuesUpdates.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ public virtual void TestStressMultiThreading()
12011201
writer.AddDocument(doc);
12021202
}
12031203

1204-
CountDownLatch done = new CountDownLatch(numThreads);
1204+
CountdownLatch done = new CountdownLatch(numThreads);
12051205
AtomicInt32 numUpdates = new AtomicInt32(AtLeast(100));
12061206

12071207
// same thread updates a field as well as reopens
@@ -1217,7 +1217,7 @@ public virtual void TestStressMultiThreading()
12171217
{
12181218
t.Start();
12191219
}
1220-
done.Await();
1220+
done.Wait();
12211221
writer.Dispose();
12221222

12231223
DirectoryReader reader = DirectoryReader.Open(dir);
@@ -1254,12 +1254,12 @@ private sealed class ThreadAnonymousClass : ThreadJob
12541254
{
12551255
private readonly IndexWriter writer;
12561256
private readonly int numDocs;
1257-
private readonly CountDownLatch done;
1257+
private readonly CountdownLatch done;
12581258
private readonly AtomicInt32 numUpdates;
12591259
private readonly string f;
12601260
private readonly string cf;
12611261

1262-
public ThreadAnonymousClass(string str, IndexWriter writer, int numDocs, CountDownLatch done, AtomicInt32 numUpdates, string f, string cf)
1262+
public ThreadAnonymousClass(string str, IndexWriter writer, int numDocs, CountdownLatch done, AtomicInt32 numUpdates, string f, string cf)
12631263
: base(str)
12641264
{
12651265
this.writer = writer;
@@ -1366,7 +1366,7 @@ public override void Run()
13661366
}
13671367
}
13681368
}
1369-
done.CountDown();
1369+
done.Signal();
13701370
}
13711371
}
13721372
}

src/Lucene.Net.Tests/Index/TestConcurrentMergeScheduler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public virtual void TestMaxMergeCount()
289289

290290
int maxMergeCount = TestUtil.NextInt32(Random, 1, 5);
291291
int maxMergeThreads = TestUtil.NextInt32(Random, 1, maxMergeCount);
292-
CountDownLatch enoughMergesWaiting = new CountDownLatch(maxMergeCount);
292+
CountdownLatch enoughMergesWaiting = new CountdownLatch(maxMergeCount);
293293
AtomicInt32 runningMergeCount = new AtomicInt32(0);
294294
AtomicBoolean failed = new AtomicBoolean();
295295

@@ -327,11 +327,11 @@ public virtual void TestMaxMergeCount()
327327
private sealed class ConcurrentMergeSchedulerAnonymousClass : ConcurrentMergeScheduler
328328
{
329329
private readonly int maxMergeCount;
330-
private readonly CountDownLatch enoughMergesWaiting;
330+
private readonly CountdownLatch enoughMergesWaiting;
331331
private readonly AtomicInt32 runningMergeCount;
332332
private readonly AtomicBoolean failed;
333333

334-
public ConcurrentMergeSchedulerAnonymousClass(int maxMergeCount, CountDownLatch enoughMergesWaiting, AtomicInt32 runningMergeCount, AtomicBoolean failed)
334+
public ConcurrentMergeSchedulerAnonymousClass(int maxMergeCount, CountdownLatch enoughMergesWaiting, AtomicInt32 runningMergeCount, AtomicBoolean failed)
335335
{
336336
this.maxMergeCount = maxMergeCount;
337337
this.enoughMergesWaiting = enoughMergesWaiting;
@@ -349,14 +349,14 @@ protected internal override void DoMerge(MergePolicy.OneMerge merge)
349349
try
350350
{
351351
Assert.IsTrue(count <= maxMergeCount, "count=" + count + " vs maxMergeCount=" + maxMergeCount);
352-
enoughMergesWaiting.CountDown();
352+
enoughMergesWaiting.Signal();
353353

354354
// Stall this merge until we see exactly
355355
// maxMergeCount merges waiting
356356
while (true)
357357
{
358358
// wait for 10 milliseconds
359-
if (enoughMergesWaiting.Await(new TimeSpan(0, 0, 0, 0, 10)) || failed)
359+
if (enoughMergesWaiting.Wait(new TimeSpan(0, 0, 0, 0, 10)) || failed)
360360
{
361361
break;
362362
}

src/Lucene.Net.Tests/Index/TestDocValuesIndexing.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ public virtual void TestMixedTypesDifferentThreads()
514514
Directory dir = NewDirectory();
515515
IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)));
516516

517-
CountDownLatch startingGun = new CountDownLatch(1);
517+
CountdownLatch startingGun = new CountdownLatch(1);
518518
AtomicBoolean hitExc = new AtomicBoolean();
519519
ThreadJob[] threads = new ThreadJob[3];
520520
for (int i = 0; i < 3; i++)
@@ -539,7 +539,7 @@ public virtual void TestMixedTypesDifferentThreads()
539539
threads[i].Start();
540540
}
541541

542-
startingGun.CountDown();
542+
startingGun.Signal();
543543

544544
foreach (ThreadJob t in threads)
545545
{
@@ -553,11 +553,11 @@ public virtual void TestMixedTypesDifferentThreads()
553553
private sealed class ThreadAnonymousClass : ThreadJob
554554
{
555555
private readonly IndexWriter w;
556-
private readonly CountDownLatch startingGun;
556+
private readonly CountdownLatch startingGun;
557557
private readonly AtomicBoolean hitExc;
558558
private readonly Document doc;
559559

560-
public ThreadAnonymousClass(IndexWriter w, CountDownLatch startingGun, AtomicBoolean hitExc, Document doc)
560+
public ThreadAnonymousClass(IndexWriter w, CountdownLatch startingGun, AtomicBoolean hitExc, Document doc)
561561
{
562562
this.w = w;
563563
this.startingGun = startingGun;
@@ -569,7 +569,7 @@ public override void Run()
569569
{
570570
try
571571
{
572-
startingGun.Await();
572+
startingGun.Wait();
573573
w.AddDocument(doc);
574574
}
575575
catch (Exception iae) when (iae.IsIllegalArgumentException())

src/Lucene.Net.Tests/Index/TestDocValuesWithThreads.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public virtual void Test()
7878

7979
int numThreads = TestUtil.NextInt32(Random, 2, 5);
8080
IList<ThreadJob> threads = new JCG.List<ThreadJob>();
81-
CountDownLatch startingGun = new CountDownLatch(1);
81+
CountdownLatch startingGun = new CountdownLatch(1);
8282
for (int t = 0; t < numThreads; t++)
8383
{
8484
Random threadRandom = new J2N.Randomizer(Random.NextInt64());
@@ -87,7 +87,7 @@ public virtual void Test()
8787
threads.Add(thread);
8888
}
8989

90-
startingGun.CountDown();
90+
startingGun.Signal();
9191

9292
foreach (ThreadJob thread in threads)
9393
{
@@ -105,10 +105,10 @@ private sealed class ThreadAnonymousClass : ThreadJob
105105
private readonly IList<BytesRef> sorted;
106106
private readonly int numDocs;
107107
private readonly AtomicReader ar;
108-
private readonly CountDownLatch startingGun;
108+
private readonly CountdownLatch startingGun;
109109
private readonly Random threadRandom;
110110

111-
public ThreadAnonymousClass(IList<long> numbers, IList<BytesRef> binary, IList<BytesRef> sorted, int numDocs, AtomicReader ar, CountDownLatch startingGun, Random threadRandom)
111+
public ThreadAnonymousClass(IList<long> numbers, IList<BytesRef> binary, IList<BytesRef> sorted, int numDocs, AtomicReader ar, CountdownLatch startingGun, Random threadRandom)
112112
{
113113
this.numbers = numbers;
114114
this.binary = binary;
@@ -128,7 +128,7 @@ public override void Run()
128128
//BinaryDocValues bdv = ar.GetBinaryDocValues("bytes");
129129
BinaryDocValues bdv = FieldCache.DEFAULT.GetTerms(ar, "bytes", false);
130130
SortedDocValues sdv = FieldCache.DEFAULT.GetTermsIndex(ar, "sorted");
131-
startingGun.Await();
131+
startingGun.Wait();
132132
int iters = AtLeast(1000);
133133
BytesRef scratch = new BytesRef();
134134
BytesRef scratch2 = new BytesRef();

0 commit comments

Comments
 (0)