mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +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
|
||||
}
|
||||
|
||||
static bool shouldComputeVariations()
|
||||
{
|
||||
return prefs.display_variations && decoMode(true) != RECREATIONAL;
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::updateDiveProfile()
|
||||
{
|
||||
createTemporaryPlan();
|
||||
|
@ -1046,12 +1051,13 @@ void DivePlannerPointsModel::updateDiveProfile()
|
|||
struct deco_state *cache = NULL;
|
||||
struct decostop stoptable[60];
|
||||
struct deco_state plan_deco_state;
|
||||
struct diveplan *plan_copy;
|
||||
|
||||
memset(&plan_deco_state, 0, sizeof(struct deco_state));
|
||||
plan(&plan_deco_state, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
|
||||
updateMaxDepth();
|
||||
plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
||||
|
||||
if (isPlanner() && shouldComputeVariations()) {
|
||||
struct diveplan *plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
||||
lock_planner();
|
||||
cloneDiveplan(&diveplan, plan_copy);
|
||||
unlock_planner();
|
||||
|
@ -1065,6 +1071,7 @@ void DivePlannerPointsModel::updateDiveProfile()
|
|||
#endif
|
||||
final_deco_state = plan_deco_state;
|
||||
emit calculatedPlanNotes(QString(d->notes));
|
||||
}
|
||||
|
||||
// throw away the cache
|
||||
free(cache);
|
||||
|
@ -1164,7 +1171,6 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, c
|
|||
struct divedatapoint *last_segment;
|
||||
struct deco_state ds = *previous_ds;
|
||||
|
||||
if (isPlanner() && prefs.display_variations && decoMode(true) != RECREATIONAL) {
|
||||
int my_instance = ++instanceCounter;
|
||||
cache_deco_state(&ds, &save);
|
||||
|
||||
|
@ -1234,7 +1240,6 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, c
|
|||
#ifdef DEBUG_STOPVAR
|
||||
printf("\n\n");
|
||||
#endif
|
||||
}
|
||||
finish:
|
||||
free_dps(original_plan);
|
||||
free(original_plan);
|
||||
|
@ -1261,12 +1266,15 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
|
|||
//TODO: C-based function here?
|
||||
struct decostop stoptable[60];
|
||||
plan(&ds_after_previous_dives, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), true);
|
||||
|
||||
if (shouldComputeVariations()) {
|
||||
struct diveplan *plan_copy;
|
||||
plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
||||
lock_planner();
|
||||
cloneDiveplan(&diveplan, plan_copy);
|
||||
unlock_planner();
|
||||
computeVariations(plan_copy, &ds_after_previous_dives);
|
||||
}
|
||||
|
||||
free(cache);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue