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:
Robert C. Helling 2017-08-29 11:41:30 +02:00
parent be6b50fce4
commit a9ceecc2e3
6 changed files with 35 additions and 1 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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();
}

View file

@ -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