lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [1/3] lucenenet git commit: Fix for TestDirectoryReaderReopen.TestThreadSafety
Date Sun, 01 Mar 2015 22:32:02 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master bdf4ec7b0 -> 9ff490365


Fix for TestDirectoryReaderReopen.TestThreadSafety

The java version uses a concurrent hash map so I updated VirtualMethod to use that.
After that change, we no longer needed the lock on the Reap() function.
Next the Get() needed to use a tryGet() and return the default if there was nothing in the
collection.


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

Branch: refs/heads/master
Commit: 9b57fca6a6961905204f41bef1b5fe784741a58b
Parents: ac8fa48
Author: Chand2048 <Chand@Microsoft.com>
Authored: Wed Feb 25 14:21:16 2015 -0800
Committer: Chand2048 <Chand@Microsoft.com>
Committed: Wed Feb 25 14:21:16 2015 -0800

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/VirtualMethod.cs   |  2 +-
 src/Lucene.Net.Core/Util/WeakIdentityMap.cs | 33 +++++++++++++-----------
 2 files changed, 19 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9b57fca6/src/Lucene.Net.Core/Util/VirtualMethod.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/VirtualMethod.cs b/src/Lucene.Net.Core/Util/VirtualMethod.cs
index faa5a70..e21c253 100644
--- a/src/Lucene.Net.Core/Util/VirtualMethod.cs
+++ b/src/Lucene.Net.Core/Util/VirtualMethod.cs
@@ -64,7 +64,7 @@ namespace Lucene.Net.Util
         private readonly Type BaseClass;
         private readonly string Method;
         private readonly Type[] Parameters;
-        private readonly WeakIdentityMap<Type, int> Cache = WeakIdentityMap<Type,
int>.NewHashMap(false);
+        private readonly WeakIdentityMap<Type, int> Cache = WeakIdentityMap<Type,
int>.NewConcurrentHashMap(false);
 
         /// <summary>
         /// Creates a new instance for the given {@code baseClass} and method declaration.
</summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9b57fca6/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/WeakIdentityMap.cs b/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
index ee792be..e556a28 100644
--- a/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
+++ b/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
@@ -135,7 +135,16 @@ namespace Lucene.Net.Util
             {
                 Reap();
             }
-            return BackingStore[new IdentityWeakReference(key)];
+
+            V val;
+            if (BackingStore.TryGetValue(new IdentityWeakReference(key), out val))
+            {
+                return val;
+            }
+            else
+            {
+                return default(V);
+            }
         }
 
         /// <summary>
@@ -329,25 +338,19 @@ namespace Lucene.Net.Util
         /// <seealso cref= <a href="#reapInfo">Information about the <code>reapOnRead</code>
setting</a> </seealso>
         public void Reap()
         {
-            lock (BackingStore)
+            List<IdentityWeakReference> keysToRemove = new List<IdentityWeakReference>();
+            foreach (IdentityWeakReference zombie in BackingStore.Keys)
             {
-                List<IdentityWeakReference> keysToRemove = new List<IdentityWeakReference>();
-
-                foreach (IdentityWeakReference zombie in BackingStore.Keys)
+                if (!zombie.IsAlive)
                 {
-                    if (!zombie.IsAlive)
-                        keysToRemove.Add(zombie);
-                }
-
-                foreach (var key in keysToRemove)
-                {
-                    BackingStore.Remove(key);
+                    keysToRemove.Add(zombie);
                 }
             }
-            /*while ((zombie = queue.poll()) != null)
+
+            foreach (var key in keysToRemove)
             {
-              BackingStore.Remove(zombie);
-            }*/
+                BackingStore.Remove(key);
+            }
         }
 
         // we keep a hard reference to our NULL key, so map supports null keys that never
get GCed:


Mime
View raw message