beagle r4785 - trunk/beagle/beagled



Author: dbera
Date: Sat Jun 14 20:53:17 2008
New Revision: 4785
URL: http://svn.gnome.org/viewvc/beagle?rev=4785&view=rev

Log:
Fix a bug I introduced in refcounting IndexReaders. Remove the MarkClose and MarkNoClose methods and instead do it directly using the Refcount; this is easier to understand.


Modified:
   trunk/beagle/beagled/LuceneCommon.cs

Modified: trunk/beagle/beagled/LuceneCommon.cs
==============================================================================
--- trunk/beagle/beagled/LuceneCommon.cs	(original)
+++ trunk/beagle/beagled/LuceneCommon.cs	Sat Jun 14 20:53:17 2008
@@ -1913,19 +1913,6 @@
 				this.Version = version;
 				this.Refcount = 1;
 			}
-
-			// Use these methods to keep one instance of a reader
-			// always opened.
-
-			public void MarkNoClose ()
-			{
-				this.Refcount ++;
-			}
-
-			public void MarkClose ()
-			{
-				this.Refcount --;
-			}
 		}
 
 		static private Hashtable directory_rav_map = new Hashtable ();
@@ -1951,7 +1938,7 @@
 					reader = IndexReader.Open (directory);
 
 					rav = new ReaderAndVersion (reader, version);
-					rav.MarkNoClose (); // keep this reader open until...
+					rav.Refcount ++; // add one refcount to keep this reader open until...
 
 					directory_rav_map [directory] = rav;
 					reader_rav_map [reader] = rav;
@@ -1960,9 +1947,10 @@
 				}
 
 				version = IndexReader.GetCurrentVersion (directory);
-				
+
 				if (version != rav.Version) {
-					rav.MarkClose ();
+					// unref once and then close reader or call UnrefReaderAndVersion_Unlocked as a single step
+					UnrefReaderAndVersion_Unlocked (rav);
 
 					reader = IndexReader.Open (directory);
 
@@ -2009,7 +1997,7 @@
 				ReaderAndVersion rav = (ReaderAndVersion) reader_rav_map [reader];
 
 				if (rav != null) {
-					rav.MarkClose ();
+					rav.Refcount --; // Remove one extra refcount that was added to keep the reader opened
 					UnrefReaderAndVersion_Unlocked (rav);
 				} else
 					reader.Close ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]