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

Daniel Burrows dburrows at costa.debian.org
Wed Sep 21 23:58:49 UTC 2005


Author: dburrows
Date: Wed Sep 21 23:58:46 2005
New Revision: 4164

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/resolver_manager.cc
   branches/aptitude-0.3/aptitude/src/generic/resolver_manager.h
Log:
Add a routine that allows maybe-blocking solution searches.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Sep 21 23:58:46 2005
@@ -1,5 +1,11 @@
 2005-09-21  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/resolver_manager.cc, src/generic/resolver_manager.h:
+
+	  Add a routine that waits for the resolver to perform some number
+	  of steps before returning; can be used to avoid displaying a
+	  progress indicator unless the search seems to be taking a while.
+
 	* src/ui.cc:
 
 	  Ignore attempts to apply solutions that don't exist yet.

Modified: branches/aptitude-0.3/aptitude/src/generic/resolver_manager.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/resolver_manager.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/resolver_manager.cc	Wed Sep 21 23:58:46 2005
@@ -559,6 +559,8 @@
   threads::condition c;
 
   get_solution_background(solution_num, max_steps, new solution_return_continuation(sol, oot, oos, m, c));
+  l.release();
+
   threads::mutex::lock cond_l(m);
 
   while(!sol && !oot && !oos)
@@ -578,6 +580,10 @@
 {
   threads::mutex::lock l(mutex);
 
+  // It's necessary to stop the background thread because we might be
+  // decreasing the maximum number of steps to search.
+  background_suspender bs(*this);
+
   assert(resolver_exists());
 
   threads::mutex::lock sol_l(solutions_mutex);
@@ -597,6 +603,86 @@
   background_control_cond.wake_all();
 }
 
+class blocking_continuation : public resolver_manager::background_continuation
+{
+  /** The real continuation */
+  resolver_manager::background_continuation *k;
+
+  /** The solution for which we are searching. */
+  unsigned int solution_num;
+
+  /** The channel through which the result should be announced. */
+  threads::box<bool> &result_box;
+
+  /** The number of steps to try searching for a solution after this if
+   *  time runs out.
+   */
+  int remaining_steps;
+
+  /** The manager associated with this continuation. */
+  resolver_manager &m;
+public:
+  blocking_continuation(background_continuation *_k,
+			unsigned int _solution_num,
+			threads::box<bool> &_result_box,
+			int _remaining_steps,
+			resolver_manager &_m)
+    : k(_k), solution_num(_solution_num), result_box(_result_box),
+      remaining_steps(_remaining_steps), m(_m)
+  {
+  }
+
+  ~blocking_continuation()
+  {
+    delete k;
+  }
+
+  void success(const generic_solution<aptitude_universe> &sol)
+  {
+    k->success(sol);
+    result_box.put(true);
+  }
+
+  void no_more_solutions()
+  {
+    k->no_more_solutions();
+    result_box.put(true);
+  }
+
+  void no_more_time()
+  {
+    m.get_solution_background(solution_num, remaining_steps, k);
+    k = NULL;
+    result_box.put(false);
+  }
+
+  void interrupted()
+  {
+    result_box.put(false);
+  }
+};
+
+bool resolver_manager::get_solution_background_blocking(unsigned int solution_num,
+							int max_steps,
+							int block_steps,
+							background_continuation *k)
+{
+  int remaining;
+
+  if(block_steps < max_steps)
+    remaining = max_steps - block_steps;
+  else
+    remaining = 0;
+
+  threads::box<bool> rbox;
+
+  get_solution_background(solution_num, block_steps,
+			  new blocking_continuation(k, solution_num, rbox,
+						    remaining, *this));
+
+  return rbox.take();
+}
+
 void resolver_manager::reject_version(const aptitude_resolver_version &ver)
 {
   threads::mutex::lock l(mutex);

Modified: branches/aptitude-0.3/aptitude/src/generic/resolver_manager.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/resolver_manager.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/resolver_manager.h	Wed Sep 21 23:58:46 2005
@@ -350,6 +350,24 @@
 			       int max_steps,
 			       background_continuation *k);
 
+  /** Like get_solution_background, but blocks until the background
+   *  solver has \i either found a solution or examined at least
+   *  block_count solutions.
+   *
+   *  \param solution_num the solution to retrieve
+   *
+   *  \param max_steps the number of steps to allow the computation
+   *
+   *  \param block_count the number of steps to wait before returning
+   *
+   *  \return \b true if the search terminated in block_count steps or
+   *  less
+   */
+  bool get_solution_background_blocking(unsigned int solution_num,
+					int max_steps,
+					int block_count,
+					background_continuation *k);
+
   /** If \b true, all solutions have been generated. */
   bool solution_generation_complete() /*const*/;
 



More information about the Aptitude-svn-commit mailing list