Skip to content

Commit

Permalink
Added Dispose(b) to ControlledRealTimeReopenThread
Browse files Browse the repository at this point in the history
Added back a Dispose(bool) method to the ControlledRealTimeReopenThread class since it's a non-sealed class.
  • Loading branch information
rclabo committed Aug 18, 2021
1 parent 1961928 commit ca9850e
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions src/Lucene.Net/Search/ControlledRealTimeReopenThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public class ControlledRealTimeReopenThread<T> : ThreadJob, IDisposable
private long waitingGen;
private long searchingGen;
private long refreshStartGen;

private bool isDisposed = false;
private readonly EventWaitHandle intrinsic = new ManualResetEvent(false); // LUCENENET specific: used to mimic intrinsic monitor used by java wait and notifyAll keywords.
private readonly EventWaitHandle reopenCond = new AutoResetEvent(false); // LUCENENET NOTE: unlick java, in c# we don't need to lock reopenCond when calling methods on it.
private readonly EventWaitHandle reopenCond = new AutoResetEvent(false); // LUCENENET NOTE: unlike java, in c# we don't need to lock reopenCond when calling methods on it.


/// <summary>
Expand Down Expand Up @@ -119,27 +119,53 @@ private void RefreshDone()
/// thread so that when this method returns the thread is no longer alive.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}



/// <summary>
/// Kills the thread and releases all resources used by the
/// <see cref="ControlledRealTimeReopenThread{T}"/>. Also joins to the
/// thread so that when this method returns the thread is no longer alive.
/// </summary>
// LUCENENET specific - Support for Dispose(bool) since this is a non-sealed class.
protected virtual void Dispose(bool disposing)
{
lock (this)
{
finish = true;
if (isDisposed)
{
return;
}

if (disposing)
{

finish = true;

// So thread wakes up and notices it should finish:
reopenCond.Set();
// So thread wakes up and notices it should finish:
reopenCond.Set();

Join();
// LUCENENET NOTE: No need to catch and rethrow same excepton type ThreadInterruptedException
Join();
// LUCENENET NOTE: No need to catch and rethrow same excepton type ThreadInterruptedException

// Max it out so any waiting search threads will return:
searchingGen = long.MaxValue;
intrinsic.Set(); //LUCENENET NOTE: notify all the waiting threads to wake them up.
// Max it out so any waiting search threads will return:
searchingGen = long.MaxValue;
intrinsic.Set(); //LUCENENET NOTE: notify all the waiting threads to wake them up.

// LUCENENET specific: dispose reset event
reopenCond.Dispose();
intrinsic.Dispose();
// LUCENENET specific: dispose reset event
reopenCond.Dispose();
intrinsic.Dispose();

}

isDisposed = true;
}
}


/// <summary>
/// Waits for the target generation to become visible in
Expand Down Expand Up @@ -292,5 +318,7 @@ public override void Run()

}
}


}
}

0 comments on commit ca9850e

Please sign in to comment.