aboutsummaryrefslogtreecommitdiff
path: root/source/util
diff options
context:
space:
mode:
Diffstat (limited to 'source/util')
-rw-r--r--source/util/Jobs.mc32
1 files changed, 27 insertions, 5 deletions
diff --git a/source/util/Jobs.mc b/source/util/Jobs.mc
index d7342e3..595562e 100644
--- a/source/util/Jobs.mc
+++ b/source/util/Jobs.mc
@@ -8,10 +8,17 @@
// that can take long (key derivation, SHA-512 batches, 2D barcode encoding,
// large imports) is a Job whose step() does a bounded amount of work.
//
-// JobRunner drives a job from a timer, one step per tick, and calls back when
-// it is done. Tests call Jobs.runToCompletion() instead, synchronously.
+// Steps are sized for the Forerunner 255/255S (the only 512 KB targets).
+// Every 768 KB target allows twice as much per event
+// (tools/gen_products.py --check fails if a product breaks that rule), so
+// JobRunner runs two steps per tick there, which halves the time of an
+// import or a large QR code.
+//
+// JobRunner drives a job from a timer and calls back when it is done.
+// Tests call Jobs.runToCompletion() instead, synchronously.
import Toybox.Lang;
+import Toybox.System;
import Toybox.Timer;
module Jobs {
@@ -69,10 +76,25 @@ module Jobs {
}
function onTick() as Void {
- if (_job.step(_budget)) {
- cancel();
- _onDone.invoke();
+ for (var i = 0; i < stepsPerTick(); i++) {
+ if (_job.step(_budget)) {
+ cancel();
+ _onDone.invoke();
+ return;
+ }
}
}
}
+
+ // App memory above this means a 240,000-bytecode watchdog.
+ const LARGE_WATCH_MEMORY = 600000;
+ var _stepsPerTick as Number = 0;
+
+ // 1 on the 512 KB watches (120,000 bytecodes per event), 2 elsewhere.
+ function stepsPerTick() as Number {
+ if (_stepsPerTick == 0) {
+ _stepsPerTick = System.getSystemStats().totalMemory > LARGE_WATCH_MEMORY ? 2 : 1;
+ }
+ return _stepsPerTick;
+ }
}