Merge pull request #303 from AdrianLxM/synchronize-intervals

synchronize interval access from other classes
This commit is contained in:
AdrianLxM 2017-07-21 16:47:00 +02:00 committed by GitHub
commit 06497a862d

View file

@ -188,12 +188,14 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
} }
if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses())
synchronized (extendedBoluses) {
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) { for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
ExtendedBolus e = extendedBoluses.get(pos); ExtendedBolus e = extendedBoluses.get(pos);
if (e.date > time) continue; if (e.date > time) continue;
IobTotal calc = e.iobCalc(time); IobTotal calc = e.iobCalc(time);
total.plus(calc); total.plus(calc);
} }
}
return total; return total;
} }
@ -292,6 +294,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public IobTotal getCalculationToTimeTempBasals(long time) { public IobTotal getCalculationToTimeTempBasals(long time) {
IobTotal total = new IobTotal(time); IobTotal total = new IobTotal(time);
synchronized (tempBasals) {
for (Integer pos = 0; pos < tempBasals.size(); pos++) { for (Integer pos = 0; pos < tempBasals.size(); pos++) {
TemporaryBasal t = tempBasals.get(pos); TemporaryBasal t = tempBasals.get(pos);
if (t.date > time) continue; if (t.date > time) continue;
@ -299,14 +302,17 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob); //log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
total.plus(calc); total.plus(calc);
} }
}
if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) { if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
IobTotal totalExt = new IobTotal(time); IobTotal totalExt = new IobTotal(time);
synchronized (extendedBoluses) {
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) { for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
ExtendedBolus e = extendedBoluses.get(pos); ExtendedBolus e = extendedBoluses.get(pos);
if (e.date > time) continue; if (e.date > time) continue;
IobTotal calc = e.iobCalc(time); IobTotal calc = e.iobCalc(time);
totalExt.plus(calc); totalExt.plus(calc);
} }
}
// Convert to basal iob // Convert to basal iob
totalExt.basaliob = totalExt.iob; totalExt.basaliob = totalExt.iob;
totalExt.iob = 0d; totalExt.iob = 0d;
@ -420,12 +426,18 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public long oldestDataAvailable() { public long oldestDataAvailable() {
long oldestTime = System.currentTimeMillis(); long oldestTime = System.currentTimeMillis();
synchronized (tempBasals) {
if (tempBasals.size() > 0) if (tempBasals.size() > 0)
oldestTime = Math.min(oldestTime, tempBasals.get(0).date); oldestTime = Math.min(oldestTime, tempBasals.get(0).date);
}
synchronized (extendedBoluses) {
if (extendedBoluses.size() > 0) if (extendedBoluses.size() > 0)
oldestTime = Math.min(oldestTime, extendedBoluses.get(0).date); oldestTime = Math.min(oldestTime, extendedBoluses.get(0).date);
}
synchronized (treatments) {
if (treatments.size() > 0) if (treatments.size() > 0)
oldestTime = Math.min(oldestTime, treatments.get(treatments.size() - 1).date); oldestTime = Math.min(oldestTime, treatments.get(treatments.size() - 1).date);
}
oldestTime -= 15 * 60 * 1000L; // allow 15 min before oldestTime -= 15 * 60 * 1000L; // allow 15 min before
return oldestTime; return oldestTime;
} }