mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-03 15:43:09 +00:00
planner: avoid starting unneeded variation thread
When updating the dive profile, a thread is started to calculate plan-variations. This is done even when only editing the profile or when variation calculation is disabled by the user. The thread then exits if it shouldn't calculate the variations. Turn this around: test whether variations should be calculated before starting the thread. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0f8560276d
commit
a0f6b4d0b4
1 changed files with 94 additions and 86 deletions
|
@ -1037,6 +1037,11 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool shouldComputeVariations()
|
||||||
|
{
|
||||||
|
return prefs.display_variations && decoMode(true) != RECREATIONAL;
|
||||||
|
}
|
||||||
|
|
||||||
void DivePlannerPointsModel::updateDiveProfile()
|
void DivePlannerPointsModel::updateDiveProfile()
|
||||||
{
|
{
|
||||||
createTemporaryPlan();
|
createTemporaryPlan();
|
||||||
|
@ -1046,12 +1051,13 @@ void DivePlannerPointsModel::updateDiveProfile()
|
||||||
struct deco_state *cache = NULL;
|
struct deco_state *cache = NULL;
|
||||||
struct decostop stoptable[60];
|
struct decostop stoptable[60];
|
||||||
struct deco_state plan_deco_state;
|
struct deco_state plan_deco_state;
|
||||||
struct diveplan *plan_copy;
|
|
||||||
|
|
||||||
memset(&plan_deco_state, 0, sizeof(struct deco_state));
|
memset(&plan_deco_state, 0, sizeof(struct deco_state));
|
||||||
plan(&plan_deco_state, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
|
plan(&plan_deco_state, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
|
||||||
updateMaxDepth();
|
updateMaxDepth();
|
||||||
plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
|
||||||
|
if (isPlanner() && shouldComputeVariations()) {
|
||||||
|
struct diveplan *plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
||||||
lock_planner();
|
lock_planner();
|
||||||
cloneDiveplan(&diveplan, plan_copy);
|
cloneDiveplan(&diveplan, plan_copy);
|
||||||
unlock_planner();
|
unlock_planner();
|
||||||
|
@ -1065,6 +1071,7 @@ void DivePlannerPointsModel::updateDiveProfile()
|
||||||
#endif
|
#endif
|
||||||
final_deco_state = plan_deco_state;
|
final_deco_state = plan_deco_state;
|
||||||
emit calculatedPlanNotes(QString(d->notes));
|
emit calculatedPlanNotes(QString(d->notes));
|
||||||
|
}
|
||||||
|
|
||||||
// throw away the cache
|
// throw away the cache
|
||||||
free(cache);
|
free(cache);
|
||||||
|
@ -1164,7 +1171,6 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, c
|
||||||
struct divedatapoint *last_segment;
|
struct divedatapoint *last_segment;
|
||||||
struct deco_state ds = *previous_ds;
|
struct deco_state ds = *previous_ds;
|
||||||
|
|
||||||
if (isPlanner() && prefs.display_variations && decoMode(true) != RECREATIONAL) {
|
|
||||||
int my_instance = ++instanceCounter;
|
int my_instance = ++instanceCounter;
|
||||||
cache_deco_state(&ds, &save);
|
cache_deco_state(&ds, &save);
|
||||||
|
|
||||||
|
@ -1234,7 +1240,6 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, c
|
||||||
#ifdef DEBUG_STOPVAR
|
#ifdef DEBUG_STOPVAR
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
finish:
|
finish:
|
||||||
free_dps(original_plan);
|
free_dps(original_plan);
|
||||||
free(original_plan);
|
free(original_plan);
|
||||||
|
@ -1261,12 +1266,15 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
|
||||||
//TODO: C-based function here?
|
//TODO: C-based function here?
|
||||||
struct decostop stoptable[60];
|
struct decostop stoptable[60];
|
||||||
plan(&ds_after_previous_dives, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), true);
|
plan(&ds_after_previous_dives, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), true);
|
||||||
|
|
||||||
|
if (shouldComputeVariations()) {
|
||||||
struct diveplan *plan_copy;
|
struct diveplan *plan_copy;
|
||||||
plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
||||||
lock_planner();
|
lock_planner();
|
||||||
cloneDiveplan(&diveplan, plan_copy);
|
cloneDiveplan(&diveplan, plan_copy);
|
||||||
unlock_planner();
|
unlock_planner();
|
||||||
computeVariations(plan_copy, &ds_after_previous_dives);
|
computeVariations(plan_copy, &ds_after_previous_dives);
|
||||||
|
}
|
||||||
|
|
||||||
free(cache);
|
free(cache);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue