Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Properly handling disposing of values inside CloseableThreadLocal.cs

  • Loading branch information...
commit bd9ca1ab154732d27985c2d237917af8bbd5fbf3 1 parent 7bfc902
@ayende ayende authored
View
BIN  SharedLibs/Lucene.Net.dll
Binary file not shown
View
BIN  SharedLibs/Lucene.Net.pdb
Binary file not shown
View
42 SharedLibs/Lucene.Net.xml
@@ -1261,6 +1261,12 @@
were cloned from.
</summary>
</member>
+ <member name="M:Lucene.Net.Store.IndexInput.Dispose">
+ <summary>
+ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ </summary>
+ <filterpriority>2</filterpriority>
+ </member>
<member name="F:Lucene.Net.Store.BufferedIndexInput.BUFFER_SIZE">
<summary>Default buffer size </summary>
</member>
@@ -4723,6 +4729,12 @@
<member name="M:Lucene.Net.Analysis.TokenStream.Close">
<summary>Releases resources associated with this stream. </summary>
</member>
+ <member name="M:Lucene.Net.Analysis.TokenStream.Dispose">
+ <summary>
+ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ </summary>
+ <filterpriority>2</filterpriority>
+ </member>
<member name="T:Lucene.Net.Analysis.TokenStream.MethodSupport">
<deprecated> Remove this when old API is removed!
</deprecated>
@@ -6960,6 +6972,12 @@
<deprecated> This will be removed (hardwired to true) in 3.0
</deprecated>
</member>
+ <member name="M:Lucene.Net.Analysis.Standard.StandardAnalyzer.SavedStreams.Dispose">
+ <summary>
+ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ </summary>
+ <filterpriority>2</filterpriority>
+ </member>
<member name="T:Lucene.Net.Analysis.CharReader">
<summary> CharReader is a Reader wrapper. It reads chars from
Reader and outputs {@link CharStream}, defining an
@@ -20130,6 +20148,12 @@
</param>
<throws> IOException </throws>
</member>
+ <member name="M:Lucene.Net.Index.TermVectorsReader.Dispose">
+ <summary>
+ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ </summary>
+ <filterpriority>2</filterpriority>
+ </member>
<member name="T:Lucene.Net.Index.ParallelArrayTermVectorMapper">
<summary> Models the existing parallel array structure</summary>
</member>
@@ -20196,6 +20220,12 @@
<member name="T:Lucene.Net.Index.TermInfosReader.ThreadResources">
<summary> Per-thread resources managed by ThreadLocal</summary>
</member>
+ <member name="M:Lucene.Net.Index.TermInfosReader.ThreadResources.Dispose">
+ <summary>
+ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ </summary>
+ <filterpriority>2</filterpriority>
+ </member>
<member name="M:Lucene.Net.Index.SegmentTermEnum.Next">
<summary>Increments the enumeration to the next element. True if one exists.</summary>
</member>
@@ -21500,6 +21530,12 @@
This will have the most payoff on large fields.
</summary>
</member>
+ <member name="M:Lucene.Net.Index.FieldsReader.Dispose">
+ <summary>
+ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ </summary>
+ <filterpriority>2</filterpriority>
+ </member>
<member name="T:Lucene.Net.Index.FieldsReader.LazyField">
<summary> A Lazy implementation of Fieldable that differs loading of fields until asked for, instead of when the Document is
loaded.
@@ -22681,6 +22717,12 @@
<member name="T:Lucene.Net.Analysis.StopAnalyzer.SavedStreams">
<summary>Filters LowerCaseTokenizer with StopFilter. </summary>
</member>
+ <member name="M:Lucene.Net.Analysis.StopAnalyzer.SavedStreams.Dispose">
+ <summary>
+ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ </summary>
+ <filterpriority>2</filterpriority>
+ </member>
<member name="T:Lucene.Net.Analysis.CachingTokenFilter">
<summary> This class can be used if the token attributes of a TokenStream
are intended to be consumed more than once. It caches
View
14 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Analysis/Standard/StandardAnalyzer.cs
@@ -325,10 +325,22 @@ public override TokenStream TokenStream(System.String fieldName, System.IO.TextR
return result;
}
- private sealed class SavedStreams
+ private sealed class SavedStreams : IDisposable
{
internal StandardTokenizer tokenStream;
internal TokenStream filteredTokenStream;
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose()
+ {
+ if(tokenStream!=null)
+ tokenStream.Close();
+ if(filteredTokenStream!=null)
+ filteredTokenStream.Close();
+ }
}
/// <summary>Default maximum allowed token length </summary>
View
14 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Analysis/StopAnalyzer.cs
@@ -262,7 +262,7 @@ public override TokenStream TokenStream(System.String fieldName, System.IO.TextR
}
/// <summary>Filters LowerCaseTokenizer with StopFilter. </summary>
- private class SavedStreams
+ private class SavedStreams : IDisposable
{
public SavedStreams(StopAnalyzer enclosingInstance)
{
@@ -283,6 +283,18 @@ public StopAnalyzer Enclosing_Instance
}
internal Tokenizer source;
internal TokenStream result;
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose()
+ {
+ if(source != null)
+ source.Close();
+ if(result != null)
+ result.Close();
+ }
}
public override TokenStream ReusableTokenStream(System.String fieldName, System.IO.TextReader reader)
View
11 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Analysis/TokenStream.cs
@@ -82,7 +82,7 @@ namespace Lucene.Net.Analysis
/// {@link AttributeSource#CaptureState} and {@link AttributeSource#RestoreState}
/// can be used.
/// </summary>
- public abstract class TokenStream:AttributeSource
+ public abstract class TokenStream:AttributeSource, IDisposable
{
private void InitBlock()
{
@@ -501,5 +501,14 @@ public virtual void Reset()
public virtual void Close()
{
}
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose()
+ {
+ Close();
+ }
}
}
View
2  SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Analysis/Tokenizer.cs
@@ -32,7 +32,7 @@ namespace Lucene.Net.Analysis
/// {@link Token#Clear()} before setting Token attributes.
/// </summary>
- public abstract class Tokenizer:TokenStream
+ public abstract class Tokenizer:TokenStream
{
/// <summary>The text source for this Tokenizer. </summary>
protected internal System.IO.TextReader input;
View
11 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Index/FieldsReader.cs
@@ -36,7 +36,7 @@ namespace Lucene.Net.Index
/// </summary>
/// <version> $Id: FieldsReader.java 801344 2009-08-05 18:05:06Z yonik $
/// </version>
- public sealed class FieldsReader : System.ICloneable
+ public sealed class FieldsReader : System.ICloneable, IDisposable
{
private FieldInfos fieldInfos;
@@ -771,5 +771,14 @@ public FieldForMerge(System.Object value_Renamed, FieldInfo fi, bool binary, boo
this.storeTermVector = fi.storeTermVector;
}
}
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose()
+ {
+ Close();
+ }
}
}
View
14 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Index/TermInfosReader.cs
@@ -48,12 +48,24 @@ sealed class TermInfosReader
private const int DEFAULT_CACHE_SIZE = 1024;
/// <summary> Per-thread resources managed by ThreadLocal</summary>
- private sealed class ThreadResources
+ private sealed class ThreadResources : IDisposable
{
internal SegmentTermEnum termEnum;
// Used for caching the least recently looked-up Terms
internal Lucene.Net.Util.Cache.Cache termInfoCache;
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose()
+ {
+ if (termEnum != null)
+ termEnum.Close();
+ if (termInfoCache != null)
+ termInfoCache.Close();
+ }
}
internal TermInfosReader(Directory dir, System.String seg, FieldInfos fis, int readBufferSize, int indexDivisor)
View
11 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Index/TermVectorsReader.cs
@@ -26,7 +26,7 @@ namespace Lucene.Net.Index
/// <version> $Id: TermVectorsReader.java 687046 2008-08-19 13:01:11Z mikemccand $
/// </version>
- public class TermVectorsReader : System.ICloneable
+ public class TermVectorsReader : System.ICloneable, IDisposable
{
// NOTE: if you make a new format, it must be larger than
@@ -647,6 +647,15 @@ public virtual System.Object Clone()
return clone;
}
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose()
+ {
+ Close();
+ }
}
View
43,806 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Lucene.Net.xml
21,918 additions, 21,888 deletions not shown
View
11 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Store/IndexInput.cs
@@ -25,7 +25,7 @@ namespace Lucene.Net.Store
/// </summary>
/// <seealso cref="Directory">
/// </seealso>
- public abstract class IndexInput : System.ICloneable
+ public abstract class IndexInput : System.ICloneable, IDisposable
{
private byte[] bytes; // used by readString()
private char[] chars; // used by readModifiedUTF8String()
@@ -282,5 +282,14 @@ public virtual System.Object Clone()
return map;
}
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose()
+ {
+ Close();
+ }
}
}
View
39 SharedLibs/Sources/Lucene2.9.2/src/Lucene.Net/Util/CloseableThreadLocal.cs
@@ -16,6 +16,7 @@
*/
using System;
+using System.Collections.Concurrent;
using System.Threading;
namespace Lucene.Net.Util
@@ -47,18 +48,31 @@ namespace Lucene.Net.Util
/// </remarks>
public class CloseableThreadLocal
{
- ThreadLocal<object> self ;
+ readonly ThreadLocal<object> self ;
+ readonly ConcurrentDictionary<object, object> threadLocals = new ConcurrentDictionary<object, object>();
+
+ private static readonly object ignored = new object();
public CloseableThreadLocal()
{
- self = new ThreadLocal<object>(InitialValue);
+ self = new ThreadLocal<object>(() => Track(InitialValue()));
}
+ private object Track(object initialValue)
+ {
+ if(initialValue != null)
+ {
+ threadLocals.AddOrUpdate(initialValue, ignored, (o, o1) => ignored);
+ }
+ return initialValue;
+ }
- public virtual System.Object InitialValue()
+
+ public virtual System.Object InitialValue()
{
return null;
}
+
public virtual System.Object Get()
{
return self.Value;
@@ -66,12 +80,27 @@ public virtual System.Object Get()
public virtual void Set(System.Object object_Renamed)
{
- self.Value = object_Renamed;
+ if(self.IsValueCreated && self.Value != null)
+ {
+ object _;
+ threadLocals.TryRemove(self.Value, out _);
+ }
+ self.Value = object_Renamed;
+ if(object_Renamed != null)
+ {
+ threadLocals.AddOrUpdate(object_Renamed, ignored, (k, v) => ignored);
+ }
}
public virtual void Close()
{
- self.Value = null;
+ foreach (var threadLocal in threadLocals)
+ {
+ using (threadLocal.Key as IDisposable)
+ {
+
+ }
+ }
self.Dispose();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.