diff options
-rw-r--r-- | core/planner.c | 2 | ||||
-rw-r--r-- | core/profile.c | 2 | ||||
-rw-r--r-- | core/qthelper.cpp | 15 | ||||
-rw-r--r-- | core/qthelperfromc.h | 2 | ||||
-rw-r--r-- | qt-models/diveplannermodel.cpp | 14 | ||||
-rw-r--r-- | qt-models/diveplannermodel.h | 1 |
6 files changed, 35 insertions, 1 deletions
diff --git a/core/planner.c b/core/planner.c index 1e5f5db8d..a137753b2 100644 --- a/core/planner.c +++ b/core/planner.c @@ -685,6 +685,7 @@ bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct dec int decostopcounter = 0; set_gf(diveplan->gflow, diveplan->gfhigh); + lock_planner(); set_vpmb_conservatism(diveplan->vpmb_conservatism); if (!diveplan->surface_pressure) diveplan->surface_pressure = SURFACE_PRESSURE; @@ -1082,6 +1083,7 @@ bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct dec free(stoplevels); free(gaschanges); free(bottom_cache); + unlock_planner(); return decodive; } diff --git a/core/profile.c b/core/profile.c index 6fafb3017..697ebe1c0 100644 --- a/core/profile.c +++ b/core/profile.c @@ -990,6 +990,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru if (!in_planner()) deco_state->deco_time = 0; struct deco_state *cache_data_initial = NULL; + lock_planner(); /* For VPM-B outside the planner, cache the initial deco state for CVA iterations */ if (decoMode() == VPMB) { cache_deco_state(&cache_data_initial); @@ -1135,6 +1136,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru #if DECO_CALC_DEBUG & 1 dump_tissues(); #endif + unlock_planner(); } #endif diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 53cf1f841..7f72fd9a2 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -1713,11 +1713,13 @@ char *intdup(int index) QHash<int, double> factor_cache; +QMutex factorCacheLock; extern "C" double cache_value(int tissue, int timestep, enum inertgas inertgas) { int key = (timestep << 5) + (tissue << 1); if (inertgas == HE) ++key; + QMutexLocker locker(&factorCacheLock); return factor_cache.value(key); } @@ -1726,6 +1728,7 @@ extern "C" void cache_insert(int tissue, int timestep, enum inertgas inertgas, d int key = (timestep << 5) + (tissue << 1); if (inertgas == HE) ++key; + QMutexLocker locker(&factorCacheLock); factor_cache.insert(key, value); } @@ -1733,3 +1736,15 @@ extern "C" void print_qt_versions() { printf("%s\n", QStringLiteral("built with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()).toUtf8().data()); } + +QMutex planLock; + +extern "C" void lock_planner() +{ + planLock.lock(); +} + +extern "C" void unlock_planner() +{ + planLock.unlock(); +} diff --git a/core/qthelperfromc.h b/core/qthelperfromc.h index 44f67199e..fb308c5dd 100644 --- a/core/qthelperfromc.h +++ b/core/qthelperfromc.h @@ -26,5 +26,7 @@ enum inertgas {N2, HE}; double cache_value(int tissue, int timestep, enum inertgas gas); void cache_insert(int tissue, int timestep, enum inertgas gas, double value); void print_qt_versions(); +void lock_planner(); +void unlock_planner(); #endif // QTHELPERFROMC_H diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 127ea8649..acf2d9c6f 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -9,6 +9,7 @@ #include "core/subsurface-qt/SettingsObjectWrapper.h" #include <QApplication> #include <QTextDocument> +#include <QtConcurrent> #define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0) @@ -920,7 +921,7 @@ void DivePlannerPointsModel::createTemporaryPlan() if (recalcQ() && !diveplan_empty(&diveplan)) { struct decostop stoptable[60]; plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), false); - computeVariations(); + QtConcurrent::run(this, &DivePlannerPointsModel::computeVariations); emit calculatedPlanNotes(); } // throw away the cache @@ -1013,8 +1014,11 @@ void DivePlannerPointsModel::computeVariations() struct divedatapoint *last_segment; if(in_planner() && prefs.display_variations) { + int my_instance = ++instanceCounter; cache_deco_state(&save); cloneDiveplan(&plan_copy); + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, original, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); @@ -1022,6 +1026,8 @@ void DivePlannerPointsModel::computeVariations() last_segment = cloneDiveplan(&plan_copy); last_segment->depth.mm += 1000; last_segment->next->depth.mm += 1000; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, deeper, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); @@ -1029,18 +1035,24 @@ void DivePlannerPointsModel::computeVariations() last_segment = cloneDiveplan(&plan_copy); last_segment->depth.mm -= 1000; last_segment->next->depth.mm -= 1000; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, shallower, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->next->time += 60; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, longer, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->next->time -= 60; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, shorter, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h index ba9db5e19..a4fe35a65 100644 --- a/qt-models/diveplannermodel.h +++ b/qt-models/diveplannermodel.h @@ -123,6 +123,7 @@ private: QDateTime startTime; int tempGFHigh; int tempGFLow; + int instanceCounter = 0; }; #endif |