33 #ifndef GOOGLE_PROTOBUF_STUBS_SHARED_PTR_H__ 34 #define GOOGLE_PROTOBUF_STUBS_SHARED_PTR_H__ 48 #if !defined(UTIL_GTL_USE_STD_SHARED_PTR) && \ 49 (defined(COMPILER_MSVC) || defined(LANG_CXX11)) 50 #define UTIL_GTL_USE_STD_SHARED_PTR 1 53 #if defined(UTIL_GTL_USE_STD_SHARED_PTR) && UTIL_GTL_USE_STD_SHARED_PTR 60 using std::enable_shared_from_this;
61 using std::shared_ptr;
65 #else // below, UTIL_GTL_USE_STD_SHARED_PTR not set or set to 0. 105 template <
typename T>
118 MaybeSetupWeakThis(ptr);
123 template <
typename U>
126 control_block_(
NULL) {
132 control_block_(
NULL) {
138 template <
typename U>
140 if (ptr_ != ptr.ptr_) {
149 if (ptr_ != ptr.ptr_) {
173 delete control_block_;
186 template <
typename Y>
204 swap(control_block_, r.control_block_);
223 return control_block_ ? control_block_->refcount_ : 1;
227 return use_count() == 1;
235 template <
typename U>
240 InitializeWithStaticCast<U>(
r);
248 template <
typename U,
typename V>
250 if (r.control_block_ !=
NULL) {
253 ptr_ =
static_cast<U*
>(r.ptr_);
254 control_block_ = r.control_block_;
263 void MaybeSetupWeakThis(...) { }
269 template <
typename U>
272 template <
typename U,
typename V>
282 template <
typename T,
typename U>
285 lhs.template InitializeWithStaticCast<T>(rhs);
292 template <
typename T>
306 CopyFrom(ptr.ptr_, ptr.control_block_);
314 CopyFrom(ptr.ptr_, ptr.control_block_);
319 CopyFrom(ptr.ptr_, ptr.control_block_);
329 if (control_block_ !=
NULL &&
331 delete control_block_;
355 swap(ptr_, ptr.ptr_);
356 swap(control_block_, ptr.control_block_);
367 return control_block_ !=
NULL ? control_block_->refcount_ : 0;
370 bool expired()
const {
return use_count() == 0; }
381 if (control_block_ !=
NULL) {
384 old_refcount = control_block_->refcount_;
385 if (old_refcount == 0)
387 }
while (old_refcount !=
389 &control_block_->refcount_, old_refcount,
391 if (old_refcount > 0) {
393 result.control_block_ = control_block_;
403 control_block_ = control_block;
404 if (control_block_ !=
NULL)
420 template <
typename T>
431 CHECK(!weak_this_.expired()) <<
"No shared_ptr owns this object";
432 return weak_this_.lock();
435 CHECK(!weak_this_.expired()) <<
"No shared_ptr owns this object";
436 return weak_this_.lock();
459 CHECK(ptr->weak_this_.expired()) <<
"Object already owned by a shared_ptr";
460 ptr->weak_this_ = *
this;
464 #endif // UTIL_GTL_USE_STD_SHARED_PTR 470 #endif // GOOGLE_PROTOBUF_STUBS_SHARED_PTR_H__ weak_ptr(const weak_ptr< U > &ptr)
Definition: shared_ptr.h:313
weak_ptr(const shared_ptr< U > &ptr)
Definition: shared_ptr.h:305
void RefCountInc(volatile Atomic32 *ptr)
Definition: shared_ptr.h:72
shared_ptr< T > shared_from_this()
Definition: shared_ptr.h:428
Definition: shared_ptr.h:103
DOMString p
Definition: WebCryptoAPI.idl:116
long use_count() const
Definition: shared_ptr.h:222
shared_ptr< T > & operator=(const shared_ptr< T > &ptr)
Definition: shared_ptr.h:148
weak_ptr(const weak_ptr &ptr)
Definition: shared_ptr.h:318
shared_ptr< T > & operator=(const shared_ptr< U > &ptr)
Definition: shared_ptr.h:139
void reset()
Definition: shared_ptr.h:359
shared_ptr(const shared_ptr< U > &ptr)
Definition: shared_ptr.h:124
shared_ptr< T > lock() const
Definition: shared_ptr.h:379
double U(int64_t x, double alpha)
Definition: metric_recorder.cc:414
enable_shared_from_this & operator=(const enable_shared_from_this &other)
Definition: shared_ptr.h:442
Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr, Atomic32 old_value, Atomic32 new_value)
Definition: atomicops_internals_arm64_gcc.h:52
shared_ptr< T > static_pointer_cast(const shared_ptr< U > &rhs)
Definition: shared_ptr.h:283
bool expired() const
Definition: shared_ptr.h:370
shared_ptr(T *ptr)
Definition: shared_ptr.h:113
void swap(weak_ptr &ptr)
Definition: shared_ptr.h:353
void swap(shared_ptr< T > &r)
Definition: shared_ptr.h:201
TestSubObjConstructor T
Definition: TestTypedefs.idl:84
enable_shared_from_this()
Definition: shared_ptr.h:440
void swap(shared_ptr< T > &r, shared_ptr< T > &s)
Definition: shared_ptr.h:278
~shared_ptr()
Definition: shared_ptr.h:165
~weak_ptr()
Definition: shared_ptr.h:328
T & operator*() const
Definition: shared_ptr.h:214
void reset(Y *p)
Definition: shared_ptr.h:187
void reset()
Definition: shared_ptr.h:194
shared_ptr(const shared_ptr< T > &ptr)
Definition: shared_ptr.h:130
Definition: __init__.py:1
T * operator->() const
Definition: shared_ptr.h:218
weak_ptr & operator=(const weak_ptr< U > &ptr)
Definition: shared_ptr.h:342
shared_ptr< const T > shared_from_this() const
Definition: shared_ptr.h:434
~enable_shared_from_this()
Definition: shared_ptr.h:445
shared_ptr()
Definition: shared_ptr.h:111
Definition: document.h:393
result
Definition: target-blank-opener-post-window.php:5
Definition: shared_ptr.h:76
weak_ptr & operator=(const shared_ptr< U > &ptr)
Definition: shared_ptr.h:347
T element_type
Definition: shared_ptr.h:296
#define CHECK(x)
Definition: dynbench.cpp:46
bool RefCountDec(volatile Atomic32 *ptr)
Definition: shared_ptr.h:68
long use_count() const
Definition: shared_ptr.h:366
bool unique() const
Definition: shared_ptr.h:226
#define NULL
Definition: common_types.h:41
Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr, Atomic32 increment)
Definition: atomicops_internals_arm64_gcc.h:118
Definition: gflags_completions.h:115
ANGLE_EXPORT EGLBoolean EGLAPIENTRY Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
Definition: entry_points_egl.cpp:48
Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr, Atomic32 increment)
Definition: atomicops_internals_arm64_gcc.h:97
int32 Atomic32
Definition: atomicops.h:75
weak_ptr & operator=(const weak_ptr &ptr)
Definition: shared_ptr.h:335
enable_shared_from_this(const enable_shared_from_this &other)
Definition: shared_ptr.h:441
weak_ptr()
Definition: shared_ptr.h:299
void swap(optional< T > &x, optional< T > &y) __NOEXCEPT_(__NOEXCEPT_(x.swap(y)))
Definition: Optional.h:1047
T element_type
Definition: shared_ptr.h:109
Definition: shared_ptr.h:93
GLboolean r
Definition: gl2ext.h:306
Definition: shared_ptr.h:77