mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Run variations calculation in background
but there are still side effects and thus it crashes. Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
be6b50fce4
commit
a9ceecc2e3
6 changed files with 35 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -123,6 +123,7 @@ private:
|
|||
QDateTime startTime;
|
||||
int tempGFHigh;
|
||||
int tempGFLow;
|
||||
int instanceCounter = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue