chiark / gitweb /
adjust code from abandon.stability e19af2579b9619071d17d3fba67c2d0e3d225f61 to curren...
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 28 Jun 2009 15:06:45 +0000 (16:06 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 28 Jun 2009 15:06:45 +0000 (16:06 +0100)
pctb/pages.c

index 0081161..1a99701 100644 (file)
@@ -321,6 +321,7 @@ static void wait_for_stability(Snapshot **output,
   va_start(al,fmt);
 
   Snapshot *last=0;
+  int nidentical=0;
   /* waits longer if we're going to return an image identical to previously
    * if previously==0, all images are considered identical to it */
 
@@ -333,33 +334,33 @@ static void wait_for_stability(Snapshot **output,
          last_input, previously, doing);
 
   for (;;) {
-    double at_snapshot= timestamp();
-    double need_sleep= min_update_allowance - (at_snapshot - last_input);
-    if (need_sleep > 0) { delay(need_sleep); continue; }
-
+    usleep(250000);
     snapshot(output);
 
-    if (!with_keypress &&
-       !(previously && identical(*output,previously))) {
-      debugf("PAGING  wait_for_stability  simple\n");
-      break;
-    }
-
-    if (last && identical(*output,last)) {
-      debugf("PAGING  wait_for_stability  stabilised\n");
-      break;
+    if (!last) {
+      debugf("PAGING  wait_for_stability first...\n");
+      last=*output; *output=0;
+    } else if (!identical(*output,last)) {
+      debugf("PAGING  wait_for_stability changed...\n");
+      free(last); last=*output; *output=0;
+      nidentical=0;
+    } else {
+      nidentical++;
+      int threshold=
+       !previously ? 3 :
+       identical(*output,previously) ? 3
+       : 1;
+      debugf("PAGING  wait_for_stability nidentical=%d threshold=%d\n",
+             nidentical, threshold);
+      if (nidentical >= threshold)
+       break;
     }
-    
     progress_spinner("%s",doing);
 
-    debugf("PAGING  wait_for_stability  retry\n");
-
-    free_snapshot(&last); last=*output; *output=0;
-
     if (with_keypress)
       with_keypress();
 
-    delay(0.5);
+    usleep(250000);
   }
 
   free_snapshot(&last);