blob: fffd85aa1a269134781faff4bff9e667544f263e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
diff --git a/boost/serialization/singleton.hpp b/boost/serialization/singleton.hpp
index b50afed..e891d55 100644
--- a/boost/serialization/singleton.hpp
+++ b/boost/serialization/singleton.hpp
@@ -91,7 +91,7 @@ class BOOST_SYMBOL_VISIBLE singleton_module :
public boost::noncopyable
{
private:
- BOOST_SERIALIZATION_DECL BOOST_DLLEXPORT static bool & get_lock() BOOST_USED;
+ BOOST_DLLEXPORT static bool & get_lock() BOOST_USED;
public:
BOOST_DLLEXPORT static void lock(){
get_lock() = true;
@@ -115,7 +115,7 @@ private:
// use a wrapper so that types T with protected constructors
// can be used
class singleton_wrapper : public T {};
- static singleton_wrapper t;
+ static singleton_wrapper* t = new singleton_wrapper;
// refer to instance, causing it to be instantiated (and
// initialized at startup on working compilers)
BOOST_ASSERT(! is_destroyed());
@@ -125,7 +125,9 @@ private:
// our usage/implementation of "locking" and introduce uncertainty into
// the sequence of object initializaition.
use(& m_instance);
- return static_cast<T &>(t);
+ if (!t)
+ t = new singleton_wrapper;
+ return static_cast<T &>(*t);
}
static bool & get_is_destroyed(){
static bool is_destroyed;
@@ -147,6 +149,9 @@ public:
get_is_destroyed() = false;
}
BOOST_DLLEXPORT ~singleton() {
+ if (!get_is_destroyed()) {
+ delete &(get_instance());
+ }
get_is_destroyed() = true;
}
};
|