summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2017-10-31 14:23:37 -0700
committerHans Boehm <hboehm@google.com>2017-10-31 14:36:59 -0700
commit276a33a1b55896587d24a8a0032a853b82a96dec (patch)
tree72e87abb578c52a73fb90e5078022843321d9899
parentdfed3c6d374ce288e7ba5bf987ccaed3ba14eea6 (diff)
downloadcrcalc-276a33a1b55896587d24a8a0032a853b82a96dec.tar.gz
Make signum and compareTo check for interruptsandroid-o-mr1-iot-preview-6o-mr1-iot-preview-6
Bug: 68670525 Unless we check for interrupts some comparisons will run forever uninterruptibly. If the client, for example, compares sqrt(11) - sqrt(11) to zero, and then interrupts, it may still take quite a while for the interrupt to be recognized, since each iteration of the compare loop can take seconds. For the Android Calculator, this is usually not directly visible, except that the compute thread will continue to use cpu for several seconds. Test: Ran Android calculator tests, manually exercised this case. Change-Id: I0fe0922a8ee68bf0e08ce59c0d8c372ad10ef419
-rw-r--r--src/com/hp/creals/CR.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/com/hp/creals/CR.java b/src/com/hp/creals/CR.java
index de89faf..d051050 100644
--- a/src/com/hp/creals/CR.java
+++ b/src/com/hp/creals/CR.java
@@ -109,6 +109,7 @@
// Don't negate argument and compute inverse for exp(). That causes severe
// performance problems for (-huge).exp()
// hboehm@google.com 8/21/2017
+// Have comparison check for interruption. hboehm@google.com 10/31/2017
package com.hp.creals;
@@ -513,6 +514,9 @@ public volatile static boolean please_stop = false;
check_prec(a);
int result = compareTo(x, a);
if (0 != result) return result;
+ if (Thread.interrupted() || please_stop) {
+ throw new AbortedException();
+ }
}
}
@@ -542,6 +546,9 @@ public volatile static boolean please_stop = false;
check_prec(a);
int result = signum(a);
if (0 != result) return result;
+ if (Thread.interrupted() || please_stop) {
+ throw new AbortedException();
+ }
}
}