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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
// Singleton.cpp
// $Id$
#if !defined (ACE_SINGLETON_C)
#define ACE_SINGLETON_C
#define ACE_BUILD_DLL
#include "ace/Singleton.h"
#include "ace/Synch_T.h"
#if !defined (__ACE_INLINE__)
#include "ace/Singleton.i"
#endif /* __ACE_INLINE__ */
template <class TYPE, class LOCK> void
ACE_Singleton<TYPE, LOCK>::dump (void)
{
ACE_TRACE ("ACE_Singleton<TYPE, LOCK>::dump");
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
ACE_DEBUG ((LM_DEBUG, "instance_ = %x",
ACE_Singleton<TYPE, LOCK>::instance_i ()));
ACE_Singleton<TYPE, LOCK>::singleton_lock_i ().dump ();
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
}
template <class TYPE, class LOCK> TYPE *&
ACE_Singleton<TYPE, LOCK>::instance_i (void)
{
#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Pointer to the Singleton instance. This works around a bug with
// G++...
static TYPE *instance_ = 0;
return instance_;
#else
return ACE_Singleton<TYPE, LOCK>::instance_;
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
}
template <class TYPE, class LOCK> LOCK &
ACE_Singleton<TYPE, LOCK>::singleton_lock_i (void)
{
#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Lock the creation of the singleton. This works around a
// "feature" of G++... ;-)
static LOCK ace_singleton_lock_;
return ace_singleton_lock_;
#else
return ACE_Singleton<TYPE, LOCK>::ace_singleton_lock_;
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
}
template <class TYPE, class LOCK> TYPE *
ACE_Singleton<TYPE, LOCK>::instance (void)
{
ACE_TRACE ("ACE_Singleton<TYPE, LOCK>::instance");
TYPE *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i ();
// Perform the Double-Check pattern...
if (singleton == 0)
{
ACE_GUARD_RETURN (LOCK, ace_mon, ACE_Singleton<TYPE, LOCK>::singleton_lock_i (), 0);
if (singleton == 0)
ACE_NEW_RETURN (singleton, TYPE, 0);
}
return singleton;
}
template <class TYPE, class LOCK> TYPE *
ACE_Singleton<TYPE, LOCK>::instance (TYPE *new_instance)
{
ACE_TRACE ("ACE_Singleton::set_instance");
TYPE *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i ();
ACE_GUARD_RETURN (LOCK, ace_mon, ACE_Singleton<TYPE, LOCK>::singleton_lock_i (), 0);
TYPE *old_instance = singleton;
singleton = new_instance;
return singleton;
}
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Pointer to the Singleton instance.
template <class TYPE, class LOCK> TYPE *
ACE_Singleton<TYPE, LOCK>::instance_ = 0;
// Lock the creation of the singleton.
template <class TYPE, class LOCK> LOCK
ACE_Singleton<TYPE, LOCK>::ace_singleton_lock_;
#endif /* !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */
template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> void
ACE_SingletonEx<TYPE, LOCK, MEMORY>::dump (void)
{
ACE_TRACE ("ACE_SingletonEx<TYPE, LOCK, MEMORY>::dump");
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
ACE_DEBUG ((LM_DEBUG, "instance_ = %x",
ACE_Singleton<TYPE, LOCK>::instance_i ()));
ACE_Singleton<TYPE, LOCK>::singleton_lock_i ().dump ();
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
}
template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> TYPE *&
ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance_i (void)
{
#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Pointer to the Singleton instance. This works around a bug with
// G++...
static TYPE *instance_ = 0;
return instance_;
#else
return ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance_;
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
}
template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> LOCK &
ACE_SingletonEx<TYPE, LOCK, MEMORY>::singleton_lock_i (void)
{
#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Lock the creation of the singleton. This works around a
// "feature" of G++... ;-)
static LOCK ace_singletonex_lock_;
return ace_singletonex_lock_;
#else
return ACE_SingletonEx<TYPE, LOCK, MEMORY>::ace_singletonex_lock_;
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
}
template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> TYPE *
ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance (void)
{
ACE_TRACE ("ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance");
TYPE *&singleton = ACE_SingletonEx<TYPE, LOCK>::instance_i ();
// Perform the Double-Check pattern...
if (singleton == 0)
{
ACE_GUARD_RETURN (LOCK, ace_mon, ACE_SingletonEx<TYPE, LOCK>::singleton_lock_i (), 0);
if (singleton == 0)
ACE_NEW_RETURN (singleton, TYPE, 0);
}
if (MEMORY == ACE_SINGLETON_HEAP)
return singleton;
else
return ACE_TSS_GET (singleton, TYPE);
}
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Pointer to the Singleton instance.
template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> TYPE *
ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance_ = 0;
// Lock the creation of the singleton.
template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> LOCK
ACE_SingletonEx<TYPE, LOCK, MEMORY>::ace_singletonex_lock_;
#endif /* !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */
#endif /* ACE_SINGLETON_C */
|