/src/trafficserver/include/tscore/Ptr.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | Reference-counting shared pointer, like std::shared_ptr. |
4 | | |
5 | | @section license License |
6 | | |
7 | | Licensed to the Apache Software Foundation (ASF) under one |
8 | | or more contributor license agreements. See the NOTICE file |
9 | | distributed with this work for additional information |
10 | | regarding copyright ownership. The ASF licenses this file |
11 | | to you under the Apache License, Version 2.0 (the |
12 | | "License"); you may not use this file except in compliance |
13 | | with the License. You may obtain a copy of the License at |
14 | | |
15 | | http://www.apache.org/licenses/LICENSE-2.0 |
16 | | |
17 | | Unless required by applicable law or agreed to in writing, software |
18 | | distributed under the License is distributed on an "AS IS" BASIS, |
19 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 | | See the License for the specific language governing permissions and |
21 | | limitations under the License. |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #include <atomic> |
27 | | #include <cstddef> |
28 | | |
29 | | //////////////////////////////////////////////////////////////////// |
30 | | //////////////////////////////////////////////////////////////////// |
31 | | ////// ATOMIC VERSIONS |
32 | | //////////////////////////////////////////////////////////////////// |
33 | | //////////////////////////////////////////////////////////////////// |
34 | | |
35 | | struct ForceVFPTToTop { |
36 | 0 | virtual ~ForceVFPTToTop() {} |
37 | | }; |
38 | | |
39 | | //////////////////////////////////////////////////////////////////////// |
40 | | // |
41 | | // class RefCountObj |
42 | | // prototypical class for reference counting |
43 | | // not necessarily allocated with new |
44 | | // |
45 | | //////////////////////////////////////////////////////////////////////// |
46 | | class RefCountObj : public ForceVFPTToTop |
47 | | { |
48 | | public: |
49 | 64.9k | RefCountObj() {} |
50 | | RefCountObj(const RefCountObj &) = delete; |
51 | 0 | ~RefCountObj() override {} |
52 | | |
53 | | RefCountObj &operator=(const RefCountObj &) = delete; |
54 | | |
55 | | // Increment the reference count, returning the new count. |
56 | | int |
57 | | refcount_inc() |
58 | 90.7k | { |
59 | 90.7k | return ++m_refcount; |
60 | 90.7k | } |
61 | | |
62 | | // Decrement the reference count, returning the new count. |
63 | | int |
64 | | refcount_dec() |
65 | 90.7k | { |
66 | 90.7k | return --m_refcount; |
67 | 90.7k | } |
68 | | |
69 | | int |
70 | | refcount() const |
71 | 19.4k | { |
72 | 19.4k | return m_refcount; |
73 | 19.4k | } |
74 | | |
75 | | virtual void free() = 0; |
76 | | |
77 | | private: |
78 | | std::atomic<int> m_refcount = 0; |
79 | | }; |
80 | | |
81 | | //////////////////////////////////////////////////////////////////////// |
82 | | // |
83 | | // class RefCountObjInHeap |
84 | | // reference counted object allocated with new |
85 | | // |
86 | | //////////////////////////////////////////////////////////////////////// |
87 | | class RefCountObjInHeap : public RefCountObj |
88 | | { |
89 | | public: |
90 | | void |
91 | | free() override |
92 | 0 | { |
93 | 0 | delete this; |
94 | 0 | } |
95 | | }; |
96 | | |
97 | | //////////////////////////////////////////////////////////////////////// |
98 | | // |
99 | | // class Ptr |
100 | | // |
101 | | //////////////////////////////////////////////////////////////////////// |
102 | | template <class T> class Ptr |
103 | | { |
104 | | public: |
105 | | explicit Ptr(T *p = nullptr); |
106 | | Ptr(const Ptr<T> &); |
107 | | Ptr(Ptr<T> &&); |
108 | | ~Ptr(); |
109 | | |
110 | | void clear(); |
111 | | Ptr<T> &operator=(const Ptr<T> &); |
112 | | Ptr<T> &operator=(Ptr<T> &&); |
113 | | Ptr<T> &operator=(T *); |
114 | | |
115 | | T * |
116 | | operator->() const |
117 | 75.0M | { |
118 | 75.0M | return (m_ptr); |
119 | 75.0M | } Ptr<IOBufferData>::operator->() const Line | Count | Source | 117 | 68.2k | { | 118 | 68.2k | return (m_ptr); | 119 | 68.2k | } |
Ptr<IOBufferBlock>::operator->() const Line | Count | Source | 117 | 74.7M | { | 118 | 74.7M | return (m_ptr); | 119 | 74.7M | } |
Ptr<ProxyMutex>::operator->() const Line | Count | Source | 117 | 5 | { | 118 | 5 | return (m_ptr); | 119 | 5 | } |
Ptr<HdrStrHeap>::operator->() const Line | Count | Source | 117 | 152k | { | 118 | 152k | return (m_ptr); | 119 | 152k | } |
Unexecuted instantiation: Ptr<HostDBRecord>::operator->() const Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::operator->() const Unexecuted instantiation: Ptr<LogFile>::operator->() const Unexecuted instantiation: Ptr<PluginDso::LoadedPlugins>::operator->() const Unexecuted instantiation: Ptr<LogFieldAliasTable>::operator->() const Unexecuted instantiation: Ptr<LogFieldAliasMap>::operator->() const Unexecuted instantiation: Ptr<HostEnt>::operator->() const Unexecuted instantiation: Ptr<NetAcceptAction>::operator->() const |
120 | | T & |
121 | | operator*() const |
122 | 0 | { |
123 | 0 | return (*m_ptr); |
124 | 0 | } Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::operator*() const Unexecuted instantiation: Ptr<NetAcceptAction>::operator*() const |
125 | | |
126 | | // Making this explicit avoids unwanted conversions. See https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool . |
127 | | explicit |
128 | | operator bool() const |
129 | 47.2M | { |
130 | 47.2M | return m_ptr != nullptr; |
131 | 47.2M | } Ptr<IOBufferBlock>::operator bool() const Line | Count | Source | 129 | 47.0M | { | 130 | 47.0M | return m_ptr != nullptr; | 131 | 47.0M | } |
Ptr<ProxyMutex>::operator bool() const Line | Count | Source | 129 | 6 | { | 130 | 6 | return m_ptr != nullptr; | 131 | 6 | } |
Ptr<HdrStrHeap>::operator bool() const Line | Count | Source | 129 | 172k | { | 130 | 172k | return m_ptr != nullptr; | 131 | 172k | } |
Unexecuted instantiation: Ptr<HostDBRecord>::operator bool() const Unexecuted instantiation: Ptr<PluginDso::LoadedPlugins>::operator bool() const Unexecuted instantiation: Ptr<IOBufferData>::operator bool() const Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::operator bool() const Unexecuted instantiation: Ptr<LogFile>::operator bool() const |
132 | | |
133 | | bool |
134 | | operator==(const T *p) |
135 | 38.1k | { |
136 | 38.1k | return (m_ptr == p); |
137 | 38.1k | } Ptr<IOBufferBlock>::operator==(IOBufferBlock const*) Line | Count | Source | 135 | 38.1k | { | 136 | 38.1k | return (m_ptr == p); | 137 | 38.1k | } |
Unexecuted instantiation: Ptr<ProxyMutex>::operator==(ProxyMutex const*) Unexecuted instantiation: Ptr<HostEnt>::operator==(HostEnt const*) |
138 | | |
139 | | bool |
140 | | operator==(const Ptr<T> &p) const |
141 | 0 | { |
142 | 0 | return (m_ptr == p.m_ptr); |
143 | 0 | } Unexecuted instantiation: Ptr<ProxyMutex>::operator==(Ptr<ProxyMutex> const&) const Unexecuted instantiation: Ptr<IOBufferData>::operator==(Ptr<IOBufferData> const&) const |
144 | | |
145 | | bool |
146 | | operator!=(const T *p) |
147 | 0 | { |
148 | 0 | return (m_ptr != p); |
149 | 0 | } Unexecuted instantiation: Ptr<IOBufferBlock>::operator!=(IOBufferBlock const*) Unexecuted instantiation: Ptr<ProxyMutex>::operator!=(ProxyMutex const*) |
150 | | |
151 | | bool |
152 | | operator!=(const Ptr<T> &p) |
153 | 0 | { |
154 | 0 | return (m_ptr != p.m_ptr); |
155 | 0 | } |
156 | | |
157 | | // Return the raw pointer. |
158 | | T * |
159 | | get() const |
160 | 20.5M | { |
161 | 20.5M | return m_ptr; |
162 | 20.5M | } Ptr<IOBufferBlock>::get() const Line | Count | Source | 160 | 20.5M | { | 161 | 20.5M | return m_ptr; | 162 | 20.5M | } |
Unexecuted instantiation: Ptr<IOBufferData>::get() const Ptr<ProxyMutex>::get() const Line | Count | Source | 160 | 7 | { | 161 | 7 | return m_ptr; | 162 | 7 | } |
Ptr<HdrStrHeap>::get() const Line | Count | Source | 160 | 28 | { | 161 | 28 | return m_ptr; | 162 | 28 | } |
Unexecuted instantiation: Ptr<RefCountObj>::get() const Unexecuted instantiation: Ptr<HostDBRecord>::get() const Unexecuted instantiation: Ptr<LogFieldAliasTable>::get() const Unexecuted instantiation: Ptr<LogFile>::get() const Unexecuted instantiation: Ptr<LogFieldAliasMap>::get() const Unexecuted instantiation: Ptr<HostEnt>::get() const Unexecuted instantiation: Ptr<NetAcceptAction>::get() const |
163 | | |
164 | | // Return the raw pointer as a RefCount object. Typically |
165 | | // this is for keeping a collection of ogenous objects. |
166 | | RefCountObj * |
167 | | object() const |
168 | 28 | { |
169 | 28 | return static_cast<RefCountObj *>(m_ptr); |
170 | 28 | } Unexecuted instantiation: Ptr<RefCountObj>::object() const Ptr<HdrStrHeap>::object() const Line | Count | Source | 168 | 28 | { | 169 | 28 | return static_cast<RefCountObj *>(m_ptr); | 170 | 28 | } |
Unexecuted instantiation: Ptr<IOBufferData>::object() const |
171 | | |
172 | | // Return the stored pointer, storing NULL instead. Do not increment |
173 | | // the refcount; the caller is now responsible for owning the RefCountObj. |
174 | | T * |
175 | | detach() |
176 | 140k | { |
177 | 140k | T *tmp = m_ptr; |
178 | 140k | m_ptr = nullptr; |
179 | 140k | return tmp; |
180 | 140k | } Ptr<IOBufferBlock>::detach() Line | Count | Source | 176 | 41.5k | { | 177 | 41.5k | T *tmp = m_ptr; | 178 | 41.5k | m_ptr = nullptr; | 179 | 41.5k | return tmp; | 180 | 41.5k | } |
Ptr<HdrStrHeap>::detach() Line | Count | Source | 176 | 24.8k | { | 177 | 24.8k | T *tmp = m_ptr; | 178 | 24.8k | m_ptr = nullptr; | 179 | 24.8k | return tmp; | 180 | 24.8k | } |
Ptr<RefCountObj>::detach() Line | Count | Source | 176 | 74.4k | { | 177 | 74.4k | T *tmp = m_ptr; | 178 | 74.4k | m_ptr = nullptr; | 179 | 74.4k | return tmp; | 180 | 74.4k | } |
|
181 | | |
182 | | // XXX Clearly this is not safe. This is used in HdrHeap::unmarshal() to swizzle |
183 | | // the refcount of the managed heap pointers. That code needs to be cleaned up |
184 | | // so that this can be removed. Do not use this in new code. |
185 | | void |
186 | | swizzle(RefCountObj *ptr) |
187 | 0 | { |
188 | 0 | m_ptr = ptr; |
189 | 0 | } |
190 | | |
191 | | private: |
192 | | T *m_ptr; |
193 | | }; |
194 | | |
195 | | template <typename T> |
196 | | Ptr<T> |
197 | | make_ptr(T *p) |
198 | 0 | { |
199 | 0 | return Ptr<T>(p); |
200 | 0 | } Unexecuted instantiation: Ptr<IOBufferBlock> make_ptr<IOBufferBlock>(IOBufferBlock*) Unexecuted instantiation: Ptr<IOBufferData> make_ptr<IOBufferData>(IOBufferData*) Unexecuted instantiation: Ptr<HostDBRecord> make_ptr<HostDBRecord>(HostDBRecord*) Unexecuted instantiation: Ptr<RefCountObj> make_ptr<RefCountObj>(RefCountObj*) Unexecuted instantiation: Ptr<VirtualHostConfig::Entry> make_ptr<VirtualHostConfig::Entry>(VirtualHostConfig::Entry*) Unexecuted instantiation: Ptr<LogFieldAliasMap> make_ptr<LogFieldAliasMap>(LogFieldAliasMap*) Unexecuted instantiation: Ptr<LogFieldAliasTable> make_ptr<LogFieldAliasTable>(LogFieldAliasTable*) Unexecuted instantiation: Ptr<HostEnt> make_ptr<HostEnt>(HostEnt*) |
201 | | |
202 | | //////////////////////////////////////////////////////////////////////// |
203 | | // |
204 | | // inline functions definitions |
205 | | // |
206 | | //////////////////////////////////////////////////////////////////////// |
207 | 153k | template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr) |
208 | 153k | { |
209 | 153k | if (m_ptr) { |
210 | 0 | m_ptr->refcount_inc(); |
211 | 0 | } |
212 | 153k | } Ptr<IOBufferBlock>::Ptr(IOBufferBlock*) Line | Count | Source | 207 | 44.7k | template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr) | 208 | 44.7k | { | 209 | 44.7k | if (m_ptr) { | 210 | 0 | m_ptr->refcount_inc(); | 211 | 0 | } | 212 | 44.7k | } |
Ptr<IOBufferData>::Ptr(IOBufferData*) Line | Count | Source | 207 | 22.7k | template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr) | 208 | 22.7k | { | 209 | 22.7k | if (m_ptr) { | 210 | 0 | m_ptr->refcount_inc(); | 211 | 0 | } | 212 | 22.7k | } |
Ptr<ProxyMutex>::Ptr(ProxyMutex*) Line | Count | Source | 207 | 58 | template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr) | 208 | 58 | { | 209 | 58 | if (m_ptr) { | 210 | 0 | m_ptr->refcount_inc(); | 211 | 0 | } | 212 | 58 | } |
Ptr<RefCountObj>::Ptr(RefCountObj*) Line | Count | Source | 207 | 86.0k | template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr) | 208 | 86.0k | { | 209 | 86.0k | if (m_ptr) { | 210 | 0 | m_ptr->refcount_inc(); | 211 | 0 | } | 212 | 86.0k | } |
Unexecuted instantiation: Ptr<HostDBRecord>::Ptr(HostDBRecord*) Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::Ptr(VirtualHostConfig::Entry*) Ptr<PluginDso::LoadedPlugins>::Ptr(PluginDso::LoadedPlugins*) Line | Count | Source | 207 | 2 | template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr) | 208 | 2 | { | 209 | 2 | if (m_ptr) { | 210 | 0 | m_ptr->refcount_inc(); | 211 | 0 | } | 212 | 2 | } |
Unexecuted instantiation: Ptr<LogFieldAliasMap>::Ptr(LogFieldAliasMap*) Unexecuted instantiation: Ptr<LogFieldAliasTable>::Ptr(LogFieldAliasTable*) Unexecuted instantiation: Ptr<LogFile>::Ptr(LogFile*) Unexecuted instantiation: Ptr<HostEnt>::Ptr(HostEnt*) Unexecuted instantiation: Ptr<NetAcceptAction>::Ptr(NetAcceptAction*) |
213 | | |
214 | 2 | template <class T> inline Ptr<T>::Ptr(const Ptr<T> &src) : m_ptr(src.m_ptr) |
215 | 2 | { |
216 | 2 | if (m_ptr) { |
217 | 2 | m_ptr->refcount_inc(); |
218 | 2 | } |
219 | 2 | } Unexecuted instantiation: Ptr<IOBufferBlock>::Ptr(Ptr<IOBufferBlock> const&) Ptr<ProxyMutex>::Ptr(Ptr<ProxyMutex> const&) Line | Count | Source | 214 | 2 | template <class T> inline Ptr<T>::Ptr(const Ptr<T> &src) : m_ptr(src.m_ptr) | 215 | 2 | { | 216 | 2 | if (m_ptr) { | 217 | 2 | m_ptr->refcount_inc(); | 218 | 2 | } | 219 | 2 | } |
Unexecuted instantiation: Ptr<HostDBRecord>::Ptr(Ptr<HostDBRecord> const&) Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::Ptr(Ptr<VirtualHostConfig::Entry> const&) Unexecuted instantiation: Ptr<IOBufferData>::Ptr(Ptr<IOBufferData> const&) Unexecuted instantiation: Ptr<LogFieldAliasMap>::Ptr(Ptr<LogFieldAliasMap> const&) |
220 | | |
221 | 0 | template <class T> inline Ptr<T>::Ptr(Ptr<T> &&src) : m_ptr(src.m_ptr) |
222 | 0 | { |
223 | 0 | src.m_ptr = nullptr; |
224 | 0 | } Unexecuted instantiation: Ptr<ProxyMutex>::Ptr(Ptr<ProxyMutex>&&) Unexecuted instantiation: Ptr<HostDBRecord>::Ptr(Ptr<HostDBRecord>&&) Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::Ptr(Ptr<VirtualHostConfig::Entry>&&) |
225 | | |
226 | | template <class T> inline Ptr<T>::~Ptr() |
227 | 86.1k | { |
228 | 86.1k | if (m_ptr && m_ptr->refcount_dec() == 0) { |
229 | 0 | m_ptr->free(); |
230 | 0 | } |
231 | 86.1k | } Ptr<IOBufferBlock>::~Ptr() Line | Count | Source | 227 | 10 | { | 228 | 10 | if (m_ptr && m_ptr->refcount_dec() == 0) { | 229 | 0 | m_ptr->free(); | 230 | 0 | } | 231 | 10 | } |
Unexecuted instantiation: Ptr<IOBufferData>::~Ptr() Line | Count | Source | 227 | 5 | { | 228 | 5 | if (m_ptr && m_ptr->refcount_dec() == 0) { | 229 | 0 | m_ptr->free(); | 230 | 0 | } | 231 | 5 | } |
Line | Count | Source | 227 | 86.0k | { | 228 | 86.0k | if (m_ptr && m_ptr->refcount_dec() == 0) { | 229 | 0 | m_ptr->free(); | 230 | 0 | } | 231 | 86.0k | } |
Unexecuted instantiation: Ptr<HostDBRecord>::~Ptr() Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::~Ptr() Unexecuted instantiation: Ptr<PluginDso::LoadedPlugins>::~Ptr() Unexecuted instantiation: Ptr<LogFile>::~Ptr() Unexecuted instantiation: Ptr<LogFieldAliasMap>::~Ptr() Unexecuted instantiation: Ptr<LogFieldAliasTable>::~Ptr() Unexecuted instantiation: Ptr<HostEnt>::~Ptr() Unexecuted instantiation: Ptr<NetAcceptAction>::~Ptr() |
232 | | |
233 | | template <class T> |
234 | | inline Ptr<T> & |
235 | | Ptr<T>::operator=(T *p) |
236 | 225k | { |
237 | 225k | T *temp_ptr = m_ptr; |
238 | | |
239 | 225k | if (m_ptr == p) { |
240 | 83.5k | return (*this); |
241 | 83.5k | } |
242 | | |
243 | 141k | m_ptr = p; |
244 | | |
245 | 141k | if (m_ptr) { |
246 | 90.5k | m_ptr->refcount_inc(); |
247 | 90.5k | } |
248 | | |
249 | 141k | if (temp_ptr && temp_ptr->refcount_dec() == 0) { |
250 | 46.1k | temp_ptr->free(); |
251 | 46.1k | } |
252 | | |
253 | 141k | return (*this); |
254 | 225k | } Ptr<IOBufferBlock>::operator=(IOBufferBlock*) Line | Count | Source | 236 | 61.2k | { | 237 | 61.2k | T *temp_ptr = m_ptr; | 238 | | | 239 | 61.2k | if (m_ptr == p) { | 240 | 3.82k | return (*this); | 241 | 3.82k | } | 242 | | | 243 | 57.3k | m_ptr = p; | 244 | | | 245 | 57.3k | if (m_ptr) { | 246 | 48.3k | m_ptr->refcount_inc(); | 247 | 48.3k | } | 248 | | | 249 | 57.3k | if (temp_ptr && temp_ptr->refcount_dec() == 0) { | 250 | 3.93k | temp_ptr->free(); | 251 | 3.93k | } | 252 | | | 253 | 57.3k | return (*this); | 254 | 61.2k | } |
Ptr<ProxyMutex>::operator=(ProxyMutex*) Line | Count | Source | 236 | 19 | { | 237 | 19 | T *temp_ptr = m_ptr; | 238 | | | 239 | 19 | if (m_ptr == p) { | 240 | 12 | return (*this); | 241 | 12 | } | 242 | | | 243 | 7 | m_ptr = p; | 244 | | | 245 | 7 | if (m_ptr) { | 246 | 5 | m_ptr->refcount_inc(); | 247 | 5 | } | 248 | | | 249 | 7 | if (temp_ptr && temp_ptr->refcount_dec() == 0) { | 250 | 0 | temp_ptr->free(); | 251 | 0 | } | 252 | | | 253 | 7 | return (*this); | 254 | 19 | } |
Ptr<IOBufferData>::operator=(IOBufferData*) Line | Count | Source | 236 | 45.4k | { | 237 | 45.4k | T *temp_ptr = m_ptr; | 238 | | | 239 | 45.4k | if (m_ptr == p) { | 240 | 0 | return (*this); | 241 | 0 | } | 242 | | | 243 | 45.4k | m_ptr = p; | 244 | | | 245 | 45.4k | if (m_ptr) { | 246 | 22.7k | m_ptr->refcount_inc(); | 247 | 22.7k | } | 248 | | | 249 | 45.4k | if (temp_ptr && temp_ptr->refcount_dec() == 0) { | 250 | 22.7k | temp_ptr->free(); | 251 | 22.7k | } | 252 | | | 253 | 45.4k | return (*this); | 254 | 45.4k | } |
Ptr<RefCountObj>::operator=(RefCountObj*) Line | Count | Source | 236 | 74.4k | { | 237 | 74.4k | T *temp_ptr = m_ptr; | 238 | | | 239 | 74.4k | if (m_ptr == p) { | 240 | 74.3k | return (*this); | 241 | 74.3k | } | 242 | | | 243 | 56 | m_ptr = p; | 244 | | | 245 | 56 | if (m_ptr) { | 246 | 28 | m_ptr->refcount_inc(); | 247 | 28 | } | 248 | | | 249 | 56 | if (temp_ptr && temp_ptr->refcount_dec() == 0) { | 250 | 28 | temp_ptr->free(); | 251 | 28 | } | 252 | | | 253 | 56 | return (*this); | 254 | 74.4k | } |
Ptr<HdrStrHeap>::operator=(HdrStrHeap*) Line | Count | Source | 236 | 44.3k | { | 237 | 44.3k | T *temp_ptr = m_ptr; | 238 | | | 239 | 44.3k | if (m_ptr == p) { | 240 | 5.34k | return (*this); | 241 | 5.34k | } | 242 | | | 243 | 38.9k | m_ptr = p; | 244 | | | 245 | 38.9k | if (m_ptr) { | 246 | 19.4k | m_ptr->refcount_inc(); | 247 | 19.4k | } | 248 | | | 249 | 38.9k | if (temp_ptr && temp_ptr->refcount_dec() == 0) { | 250 | 19.4k | temp_ptr->free(); | 251 | 19.4k | } | 252 | | | 253 | 38.9k | return (*this); | 254 | 44.3k | } |
Unexecuted instantiation: Ptr<PluginDso::LoadedPlugins>::operator=(PluginDso::LoadedPlugins*) Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::operator=(VirtualHostConfig::Entry*) Unexecuted instantiation: Ptr<NetAcceptAction>::operator=(NetAcceptAction*) Unexecuted instantiation: Ptr<HostDBRecord>::operator=(HostDBRecord*) Unexecuted instantiation: Ptr<LogFile>::operator=(LogFile*) Unexecuted instantiation: Ptr<HostEnt>::operator=(HostEnt*) |
255 | | |
256 | | template <class T> |
257 | | inline void |
258 | | Ptr<T>::clear() |
259 | 0 | { |
260 | 0 | if (m_ptr) { |
261 | 0 | if (!m_ptr->refcount_dec()) { |
262 | 0 | m_ptr->free(); |
263 | 0 | } |
264 | 0 | m_ptr = nullptr; |
265 | 0 | } |
266 | 0 | } Unexecuted instantiation: Ptr<ProxyMutex>::clear() Unexecuted instantiation: Ptr<IOBufferData>::clear() Unexecuted instantiation: Ptr<IOBufferBlock>::clear() Unexecuted instantiation: Ptr<HostDBRecord>::clear() Unexecuted instantiation: Ptr<HostEnt>::clear() Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::clear() Unexecuted instantiation: Ptr<RefCountObj>::clear() |
267 | | |
268 | | template <class T> |
269 | | inline Ptr<T> & |
270 | | Ptr<T>::operator=(const Ptr<T> &src) |
271 | 25.5k | { |
272 | 25.5k | return (operator=(src.m_ptr)); |
273 | 25.5k | } Ptr<IOBufferBlock>::operator=(Ptr<IOBufferBlock> const&) Line | Count | Source | 271 | 25.5k | { | 272 | 25.5k | return (operator=(src.m_ptr)); | 273 | 25.5k | } |
Ptr<ProxyMutex>::operator=(Ptr<ProxyMutex> const&) Line | Count | Source | 271 | 10 | { | 272 | 10 | return (operator=(src.m_ptr)); | 273 | 10 | } |
Unexecuted instantiation: Ptr<IOBufferData>::operator=(Ptr<IOBufferData> const&) Unexecuted instantiation: Ptr<RefCountObj>::operator=(Ptr<RefCountObj> const&) Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::operator=(Ptr<VirtualHostConfig::Entry> const&) Unexecuted instantiation: Ptr<HostDBRecord>::operator=(Ptr<HostDBRecord> const&) Unexecuted instantiation: Ptr<HostEnt>::operator=(Ptr<HostEnt> const&) Unexecuted instantiation: Ptr<NetAcceptAction>::operator=(Ptr<NetAcceptAction> const&) |
274 | | |
275 | | template <class T> |
276 | | inline Ptr<T> & |
277 | | Ptr<T>::operator=(Ptr<T> &&src) |
278 | 0 | { |
279 | 0 | if (this != &src) { |
280 | 0 | this->~Ptr(); |
281 | 0 | m_ptr = src.m_ptr; |
282 | 0 | src.m_ptr = nullptr; |
283 | 0 | } |
284 | 0 | return *this; |
285 | 0 | } Unexecuted instantiation: Ptr<ProxyMutex>::operator=(Ptr<ProxyMutex>&&) Unexecuted instantiation: Ptr<IOBufferBlock>::operator=(Ptr<IOBufferBlock>&&) Unexecuted instantiation: Ptr<VirtualHostConfig::Entry>::operator=(Ptr<VirtualHostConfig::Entry>&&) Unexecuted instantiation: Ptr<HostDBRecord>::operator=(Ptr<HostDBRecord>&&) Unexecuted instantiation: Ptr<RefCountObj>::operator=(Ptr<RefCountObj>&&) Unexecuted instantiation: Ptr<IOBufferData>::operator=(Ptr<IOBufferData>&&) Unexecuted instantiation: Ptr<HostEnt>::operator=(Ptr<HostEnt>&&) |
286 | | |
287 | | // Bit of subtly here for the flipped version of equality checks |
288 | | // With only the template versions, the compiler will try to substitute @c nullptr_t |
289 | | // for @c T and fail, because that's not the type and no operator will be found. |
290 | | // Therefore there needs to be specific overrides for @c nullptr_t. |
291 | | |
292 | | template <typename T> |
293 | | inline bool |
294 | | operator==(std::nullptr_t, Ptr<T> const &rhs) |
295 | | { |
296 | | return rhs.get() == nullptr; |
297 | | } |
298 | | |
299 | | template <typename T> |
300 | | inline bool |
301 | | operator!=(std::nullptr_t, Ptr<T> const &rhs) |
302 | | { |
303 | | return rhs.get() != nullptr; |
304 | | } |
305 | | |
306 | | template <typename T> |
307 | | inline bool |
308 | | operator==(T const *lhs, Ptr<T> const &rhs) |
309 | | { |
310 | | return rhs.get() == lhs; |
311 | | } |
312 | | |
313 | | template <typename T> |
314 | | inline bool |
315 | | operator!=(T const *lhs, Ptr<T> const &rhs) |
316 | | { |
317 | | return rhs.get() != lhs; |
318 | | } |