Merge changes I66c97386,Id205c88d am: 05a7dfa104 am: 25d87e4419
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1668805 Change-Id: I3b48cc428b332122b8e445eef9b9e1e23152e9e2
This commit is contained in:
commit
debdf364bd
3 changed files with 15 additions and 2 deletions
|
|
@ -242,12 +242,12 @@ TEST(RefBase, ReplacedComparison) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RefBase, AssertWeakRefExistsSuccess) {
|
TEST(RefBase, AssertWeakRefExistsSuccess) {
|
||||||
// uses some other refcounting method, or non at all
|
|
||||||
bool isDeleted;
|
bool isDeleted;
|
||||||
sp<Foo> foo = sp<Foo>::make(&isDeleted);
|
sp<Foo> foo = sp<Foo>::make(&isDeleted);
|
||||||
wp<Foo> weakFoo = foo;
|
wp<Foo> weakFoo = foo;
|
||||||
|
|
||||||
EXPECT_EQ(weakFoo, wp<Foo>::fromExisting(foo.get()));
|
EXPECT_EQ(weakFoo, wp<Foo>::fromExisting(foo.get()));
|
||||||
|
EXPECT_EQ(weakFoo.unsafe_get(), wp<Foo>::fromExisting(foo.get()).unsafe_get());
|
||||||
|
|
||||||
EXPECT_FALSE(isDeleted);
|
EXPECT_FALSE(isDeleted);
|
||||||
foo = nullptr;
|
foo = nullptr;
|
||||||
|
|
@ -255,7 +255,7 @@ TEST(RefBase, AssertWeakRefExistsSuccess) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RefBase, AssertWeakRefExistsDeath) {
|
TEST(RefBase, AssertWeakRefExistsDeath) {
|
||||||
// uses some other refcounting method, or non at all
|
// uses some other refcounting method, or none at all
|
||||||
bool isDeleted;
|
bool isDeleted;
|
||||||
Foo* foo = new Foo(&isDeleted);
|
Foo* foo = new Foo(&isDeleted);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -547,6 +547,7 @@ wp<T> wp<T>::fromExisting(T* other) {
|
||||||
refs->incWeakRequireWeak(other);
|
refs->incWeakRequireWeak(other);
|
||||||
|
|
||||||
wp<T> ret;
|
wp<T> ret;
|
||||||
|
ret.m_ptr = other;
|
||||||
ret.m_refs = refs;
|
ret.m_refs = refs;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,12 @@ public:
|
||||||
template<typename U> sp(const sp<U>& other); // NOLINT(implicit)
|
template<typename U> sp(const sp<U>& other); // NOLINT(implicit)
|
||||||
template<typename U> sp(sp<U>&& other); // NOLINT(implicit)
|
template<typename U> sp(sp<U>&& other); // NOLINT(implicit)
|
||||||
|
|
||||||
|
// Cast a strong pointer directly from one type to another. Constructors
|
||||||
|
// allow changing types, but only if they are pointer-compatible. This does
|
||||||
|
// a static_cast internally.
|
||||||
|
template <typename U>
|
||||||
|
static inline sp<T> cast(const sp<U>& other);
|
||||||
|
|
||||||
~sp();
|
~sp();
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
|
|
@ -279,6 +285,12 @@ sp<T>::sp(sp<U>&& other)
|
||||||
other.m_ptr = nullptr;
|
other.m_ptr = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
template <typename U>
|
||||||
|
sp<T> sp<T>::cast(const sp<U>& other) {
|
||||||
|
return sp<T>::fromExisting(static_cast<T*>(other.get()));
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
sp<T>::~sp() {
|
sp<T>::~sp() {
|
||||||
if (m_ptr)
|
if (m_ptr)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue