summaryrefslogtreecommitdiffstats
path: root/core/divelist.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2017-11-22 20:42:33 +0100
committerGravatar Robert C. Helling <helling@atdotde.de>2017-11-25 20:13:01 +0100
commit8e21a65653514d9340ef45c9b9c53dfe5d280350 (patch)
tree2ada40567e25bc45035698748f368127b1cca199 /core/divelist.c
parenta9ceecc2e3646432d6688d04b592c48f9c63ae65 (diff)
downloadsubsurface-8e21a65653514d9340ef45c9b9c53dfe5d280350.tar.gz
Localize global planner state
For UI responsiveness, we need to be able to run the planner in the background. This needs the planner state to be localized (and we need to pass a pointer around). In order to not let too many lines overrun (and to save typing in the future) I have renamed instances of struct deco_state to ds. Yes this should have gone to a separate commit but I accidentally commit --amend'ed it. Computing of planner variations is temporarily disabled. Unlock the planner when returning early So we don't deadlock in add dive and recreational mode (which use the planner without actually planning). Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core/divelist.c')
-rw-r--r--core/divelist.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 58376eef9..0ae33153e 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -419,7 +419,7 @@ static int calculate_sac(struct dive *dive)
}
/* for now we do this based on the first divecomputer */
-static void add_dive_to_deco(struct dive *dive)
+static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
{
struct divecomputer *dc = &dive->dc;
struct gasmix *gasmix = NULL;
@@ -439,7 +439,7 @@ static void add_dive_to_deco(struct dive *dive)
for (j = t0; j < t1; j++) {
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
gasmix = get_gasmix(dive, dc, j, &ev, gasmix);
- add_segment(depth_to_bar(depth, dive), gasmix, 1, sample->setpoint.mbar, dive, dive->sac);
+ add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, sample->setpoint.mbar, dive, dive->sac);
}
}
}
@@ -475,7 +475,9 @@ static struct gasmix air = { .o2.permille = O2_IN_AIR, .he.permille = 0 };
/* take into account previous dives until there is a 48h gap between dives */
/* return last surface time before this dive or dummy value of 48h */
/* return negative surface time if dives are overlapping */
-int init_decompression(struct dive *dive)
+/* The place you call this function is likely the place where you want
+ * to create the deco_state */
+int init_decompression(struct deco_state *ds, struct dive *dive)
{
int i, divenr = -1;
int surface_time = 48 * 60 * 60;
@@ -576,7 +578,7 @@ int init_decompression(struct dive *dive)
#if DECO_CALC_DEBUG & 2
printf("Init deco\n");
#endif
- clear_deco(surface_pressure);
+ clear_deco(ds, surface_pressure);
deco_init = true;
#if DECO_CALC_DEBUG & 2
printf("Tissues after init:\n");
@@ -591,21 +593,21 @@ int init_decompression(struct dive *dive)
#endif
return surface_time;
}
- add_segment(surface_pressure, &air, surface_time, 0, dive, prefs.decosac);
+ add_segment(ds, surface_pressure, &air, surface_time, 0, dive, prefs.decosac);
#if DECO_CALC_DEBUG & 2
printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60));
- dump_tissues();
+ dump_tissues(ds);
#endif
}
- add_dive_to_deco(pdive);
+ add_dive_to_deco(ds, pdive);
last_starttime = pdive->when;
last_endtime = dive_endtime(pdive);
- clear_vpmb_state();
+ clear_vpmb_state(ds);
#if DECO_CALC_DEBUG & 2
printf("Tissues after added dive #%d:\n", pdive->number);
- dump_tissues();
+ dump_tissues(ds);
#endif
}
@@ -615,10 +617,10 @@ int init_decompression(struct dive *dive)
#if DECO_CALC_DEBUG & 2
printf("Init deco\n");
#endif
- clear_deco(surface_pressure);
+ clear_deco(ds, surface_pressure);
#if DECO_CALC_DEBUG & 2
printf("Tissues after no previous dive, surface time set to 48h:\n");
- dump_tissues();
+ dump_tissues(ds);
#endif
}
else {
@@ -629,15 +631,15 @@ int init_decompression(struct dive *dive)
#endif
return surface_time;
}
- add_segment(surface_pressure, &air, surface_time, 0, dive, prefs.decosac);
+ add_segment(ds, surface_pressure, &air, surface_time, 0, dive, prefs.decosac);
#if DECO_CALC_DEBUG & 2
printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60));
- dump_tissues();
+ dump_tissues(ds);
#endif
}
// I do not dare to remove this call. We don't need the result but it might have side effects. Bummer.
- tissue_tolerance_calc(dive, surface_pressure);
+ tissue_tolerance_calc(ds, dive, surface_pressure);
return surface_time;
}