lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [19/49] lucenenet git commit: Fixed issue with SortedSet not being emptied in Core.Util.Fst.Util, and added thread safety, since SortedSet doesn't have the necessary atomic operations.
Date Sun, 02 Oct 2016 10:16:50 GMT
Fixed issue with SortedSet not being emptied in Core.Util.Fst.Util, and added thread safety,
since SortedSet doesn't have the necessary atomic operations.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ef889ceb
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ef889ceb
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ef889ceb

Branch: refs/heads/master
Commit: ef889cebdeaa180d0bb232afd8e5ab3865cd41bc
Parents: 32e2105
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Thu Sep 8 05:23:58 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Sep 8 06:41:02 2016 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/Fst/Util.cs | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ef889ceb/src/Lucene.Net.Core/Util/Fst/Util.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Fst/Util.cs b/src/Lucene.Net.Core/Util/Fst/Util.cs
index 15a80b7..0419b78 100644
--- a/src/Lucene.Net.Core/Util/Fst/Util.cs
+++ b/src/Lucene.Net.Core/Util/Fst/Util.cs
@@ -363,6 +363,8 @@ namespace Lucene.Net.Util.Fst
 
             internal SortedSet<FSTPath<T>> Queue = null;
 
+            private object syncLock = new object();
+
             /// <summary>
             /// Creates an unbounded TopNSearcher </summary>
             /// <param name="fst"> the <seealso cref="Lucene.Net.Util.Fst.FST"/>
to search on </param>
@@ -433,7 +435,14 @@ namespace Lucene.Net.Util.Fst
 
                 if (Queue.Count == maxQueueDepth + 1)
                 {
-                    Queue.Last();
+                    // LUCENENET NOTE: SortedSet doesn't have atomic operations,
+                    // so we need to add some thread safety just in case.
+                    // Perhaps it might make sense to wrap SortedSet into a type
+                    // that provides thread safety.
+                    lock (syncLock)
+                    {
+                        Queue.Remove(Queue.Max);
+                    }
                 }
             }
 
@@ -502,7 +511,19 @@ namespace Lucene.Net.Util.Fst
 
                     // Remove top path since we are now going to
                     // pursue it:
-                    path = Queue.First();
+
+                    // LUCENENET NOTE: SortedSet doesn't have atomic operations,
+                    // so we need to add some thread safety just in case.
+                    // Perhaps it might make sense to wrap SortedSet into a type
+                    // that provides thread safety.
+                    lock (syncLock)
+                    {
+                        path = Queue.Min;
+                        if (path != null)
+                        {
+                            Queue.Remove(path);
+                        }
+                    }
 
                     if (path == null)
                     {


Mime
View raw message