diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-10-17 22:56:40 +0200 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2019-10-20 16:20:58 +0200 |
commit | 769403a4b2c3dd8e8cc94d7f1b5dad6b66d10caf (patch) | |
tree | 0aba021b487e55bb478cce7c4a56eba9d6fc5496 /qt-models/diveplannermodel.h | |
parent | f7c8d65add1a4b46e847e905bb4ac73e94f9e75a (diff) | |
download | subsurface-769403a4b2c3dd8e8cc94d7f1b5dad6b66d10caf.tar.gz |
Planner: copy deco state before passing it to worker thread
The planner has a computeVariations() function that can be run
in a worker thread. The code was not thread safe: a deco_state
object allocated on the stack of the caller was passed down to
the worker thread. It's well possible that the object would go
out of scope before the thread run.
Therefore, when running in the background, copy the object first
and free it in the worker thread.
Side note: Qt makes proper memory management again as difficult
as possible: You can't pass a std::unique_ptr<> to QtConcurrent::run,
because move-only objects are not supported. Not very friendly!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/diveplannermodel.h')
-rw-r--r-- | qt-models/diveplannermodel.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h index 8fe6e20d6..2a2aaa64d 100644 --- a/qt-models/diveplannermodel.h +++ b/qt-models/diveplannermodel.h @@ -117,7 +117,8 @@ private: void createPlan(bool replanCopy); struct diveplan diveplan; struct divedatapoint *cloneDiveplan(struct diveplan *plan_src, struct diveplan *plan_copy); - void computeVariations(struct diveplan *diveplan, struct deco_state *ds); + void computeVariations(struct diveplan *diveplan, const struct deco_state *ds); + void computeVariationsFreeDeco(struct diveplan *diveplan, struct deco_state *ds); int analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit); Mode mode; bool recalc; |