[Aptitude-svn-commit] r4241 - in branches/aptitude-0.3/aptitude: . src/generic/problemresolver

Daniel Burrows dburrows at costa.debian.org
Sat Sep 24 19:17:14 UTC 2005


Author: dburrows
Date: Sat Sep 24 19:17:11 2005
New Revision: 4241

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
Log:
Cache the value of finished, and aggressively try to update the
cache when it is being retrieved.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Sep 24 19:17:11 2005
@@ -2,6 +2,12 @@
 
 	* src/generic/problemresolver/problemresolver.h:
 
+	  Add an element to the counts cache that mirrors 'finished', and
+	  update the cache at the important exit points from the solver
+	  and (if no solver is running) when retrieving queue counts.
+
+	* src/generic/problemresolver/problemresolver.h:
+
 	  When screening out solutions that we've already generated a
 	  subset of, take into account the set of unresolved dependencies
 	  as well as the set of actions.

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	Sat Sep 24 19:17:11 2005
@@ -187,8 +187,14 @@
     size_t deferred;
     size_t conflicts;
 
+    /** \b true if the resolver has finished searching for solutions.
+     *  If open is empty, this member distinguishes between the start
+     *  and the end of a search.
+     */
+    bool finished;
+
     queue_counts()
-      : open(0), closed(0), deferred(0), conflicts(0)
+      : open(0), closed(0), deferred(0), conflicts(0), finished(false)
     {
     }
   };
@@ -363,7 +369,13 @@
    */
   bool solver_cancelled : 1;
 
-  /** Mutex guarding the solver_executing and stop_solver variables. */
+  /** Mutex guarding the solver_executing and stop_solver variables.
+   *
+   *  If a routine wants to execute some code conditionally based on
+   *  whether the resolver is currently executing, it should grab this
+   *  mutex, test solver_executing, and run the code if
+   *  solver_executing is \b false.
+   */
   threads::mutex execution_mutex;
 
 
@@ -2250,10 +2262,39 @@
   /** Atomically read the current queue sizes of this resolver. */
   queue_counts get_counts()
   {
+    maybe_update_deferred_and_counts();
+
     threads::mutex::lock l(counts_mutex);
     return counts;
   }
 
+  /** Update the cached queue sizes. */
+  void update_counts_cache()
+  {
+    threads::mutex::lock l(counts_mutex);
+    counts.open      = open.size();
+    counts.closed    = closed.size();
+    counts.deferred  = deferred.size();
+    counts.conflicts = conflicts.size();
+    counts.finished  = finished;
+  }
+
+  /** If no resolver is running, run through the deferred list and
+   *  update the counts cache.  In particular, this allows the
+   *  'are-we-out-of-solutions' state to be updated immediately when
+   *  something like reject_version is called.
+   */
+  void maybe_update_deferred_and_counts()
+  {
+    threads::mutex::lock l(execution_mutex);
+    if(!solver_executing)
+      {
+	if(deferred_dirty)
+	  reexamine_deferred();
+	update_counts_cache();
+      }
+  }
+
   /** Try to find the "next" solution: remove partial solutions from
    *  the open queue and place them in the closed queue until one of
    *  the following occurs:
@@ -2315,14 +2356,7 @@
 	    throw InterruptedException();
 	}
 
-	// Update the cached queue sizes.
-	{
-	  threads::mutex::lock l(counts_mutex);
-	  counts.open      = open.size();
-	  counts.closed    = closed.size();
-	  counts.deferred  = deferred.size();
-	  counts.conflicts = conflicts.size();
-	}
+	update_counts_cache();
 
 
 	solution s=open.top();
@@ -2405,6 +2439,8 @@
 			      << std::endl;
 		  }
 
+		update_counts_cache();
+
 		return minimized;
 	      }
 	  }
@@ -2427,6 +2463,8 @@
 
     finished=true;
 
+    update_counts_cache();
+
     if(debug)
       {
 	std::cout << " *** Out of solutions after " << odometer << " steps." << std::endl;



More information about the Aptitude-svn-commit mailing list