Merge lp:~jan-ellenbeck/openwns-library/fixForBug661367 into lp:openwns-library

Proposed by Jan
Status: Needs review
Proposed branch: lp:~jan-ellenbeck/openwns-library/fixForBug661367
Merge into: lp:openwns-library
Diff against target: 63 lines (+21/-3)
3 files modified
src/events/PeriodicTimeout.cpp (+8/-2)
src/simulator/ISimulator.cpp (+6/-0)
src/simulator/ISimulator.hpp (+7/-1)
To merge this branch: bzr merge lp:~jan-ellenbeck/openwns-library/fixForBug661367
Reviewer Review Type Date Requested Status
Maciej Muehleisen Disapprove
Review via email: mp+44414@code.launchpad.net

Description of the change

Provides a fix/workaround to Bug #661367 by adding a method to check whether the wns::simulator::Singleton is (still) valid. This is checked for in the PeriodicTimeout destructor to avoid situations where the simulator core is already gone when destroying the class derived from PeriodicTimeout (e.g. a Singleton that gets destroyed std::atexit). As this check is only performed in the destructor, there is no performance impact whatsoever.

To post a comment you must log in.
Revision history for this message
Maciej Muehleisen (mue-comnets) wrote :

Thank you for the effort but I prefer a clean solution by getting rid of std::atexit and using the simulator end event to shutdown singletons. I'll try to take care of that before X-mas.

review: Disapprove

Unmerged revisions

242. By Jan

Fixes bug 661367 which occurs at shutdown when a Singleton is also derived from PeriodicTimeout

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/events/PeriodicTimeout.cpp'
2--- src/events/PeriodicTimeout.cpp 2008-10-14 23:51:59 +0000
3+++ src/events/PeriodicTimeout.cpp 2010-12-22 00:48:10 +0000
4@@ -74,8 +74,14 @@
5 {
6 if(this->hasPeriodicTimeoutSet())
7 {
8- this->cancelPeriodicTimeout();
9- }
10+ // check whether event scheduler still exists because if called
11+ // from a Singleton, the event scheduler would already be destroyed at
12+ // the time the Singletong gets destroyed and thus this destructor gets called
13+ if (wns::simulator::getSingleton().hasValidInstance())
14+ {
15+ this->cancelPeriodicTimeout();
16+ }
17+ }
18 }
19
20
21
22=== modified file 'src/simulator/ISimulator.cpp'
23--- src/simulator/ISimulator.cpp 2010-04-07 15:03:35 +0000
24+++ src/simulator/ISimulator.cpp 2010-12-22 00:48:10 +0000
25@@ -120,6 +120,12 @@
26 return simulator_.get();
27 }
28
29+bool
30+Singleton::hasValidInstance()
31+{
32+ return simulator_.get() != NULL;
33+}
34+
35 void
36 Singleton::setInstance(ISimulator* simulator)
37 {
38
39=== modified file 'src/simulator/ISimulator.hpp'
40--- src/simulator/ISimulator.hpp 2010-04-07 15:03:35 +0000
41+++ src/simulator/ISimulator.hpp 2010-12-22 00:48:10 +0000
42@@ -216,6 +216,12 @@
43 ~Singleton();
44
45 /**
46+ * @brief Check whether the global instance of ISimulator exists
47+ */
48+ bool
49+ hasValidInstance();
50+
51+ /**
52 * @brief Retrieve the global instance of ISimulator
53 * @pre An instance must be set
54 */
55@@ -223,7 +229,7 @@
56 getInstance();
57
58 /**
59- * @brief Retrieve set the global instance of ISimulator
60+ * @brief Set the global instance of ISimulator
61 * @pre No instance must be set
62 */
63 void

Subscribers

People subscribed via source and target branches

to status/vote changes: