mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
AK+Kernel: Remove one_ref_left() footgun
This mechanism was unsafe to use in any multithreaded context, since the hook function was invoked on a raw pointer *after* decrementing the local ref count. Since we don't use it for anything anymore, let's just get rid of it.
This commit is contained in:
parent
08e927f084
commit
a4b4b358ff
|
@ -69,9 +69,6 @@ public:
|
||||||
that->will_be_destroyed();
|
that->will_be_destroyed();
|
||||||
delete static_cast<const T*>(this);
|
delete static_cast<const T*>(this);
|
||||||
return true;
|
return true;
|
||||||
} else if (new_ref_count == 1) {
|
|
||||||
if constexpr (requires { that->one_ref_left(); })
|
|
||||||
that->one_ref_left();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,6 @@ public:
|
||||||
if constexpr (requires { that->will_be_destroyed(); })
|
if constexpr (requires { that->will_be_destroyed(); })
|
||||||
that->will_be_destroyed();
|
that->will_be_destroyed();
|
||||||
delete that;
|
delete that;
|
||||||
} else if (new_ref_count == 1) {
|
|
||||||
if constexpr (requires { that->one_ref_left(); })
|
|
||||||
that->one_ref_left();
|
|
||||||
}
|
}
|
||||||
return new_ref_count == 0;
|
return new_ref_count == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,10 +77,6 @@ public:
|
||||||
delete that;
|
delete that;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (new_ref_count == 1) {
|
|
||||||
if constexpr (requires { that->one_ref_left(); })
|
|
||||||
that->one_ref_left();
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,10 +17,8 @@ struct Object2 : Object {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SelfAwareObject : public RefCounted<SelfAwareObject> {
|
struct SelfAwareObject : public RefCounted<SelfAwareObject> {
|
||||||
void one_ref_left() { m_has_one_ref_left = true; }
|
|
||||||
void will_be_destroyed() { ++num_destroyed; }
|
void will_be_destroyed() { ++num_destroyed; }
|
||||||
|
|
||||||
bool m_has_one_ref_left = false;
|
|
||||||
static size_t num_destroyed;
|
static size_t num_destroyed;
|
||||||
};
|
};
|
||||||
size_t SelfAwareObject::num_destroyed = 0;
|
size_t SelfAwareObject::num_destroyed = 0;
|
||||||
|
@ -132,17 +130,14 @@ TEST_CASE(self_observers)
|
||||||
{
|
{
|
||||||
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
|
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
|
||||||
EXPECT_EQ(object->ref_count(), 1u);
|
EXPECT_EQ(object->ref_count(), 1u);
|
||||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||||
|
|
||||||
object->ref();
|
object->ref();
|
||||||
EXPECT_EQ(object->ref_count(), 2u);
|
EXPECT_EQ(object->ref_count(), 2u);
|
||||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||||
|
|
||||||
object->unref();
|
object->unref();
|
||||||
EXPECT_EQ(object->ref_count(), 1u);
|
EXPECT_EQ(object->ref_count(), 1u);
|
||||||
EXPECT_EQ(object->m_has_one_ref_left, true);
|
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||||
}
|
}
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 1u);
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 1u);
|
||||||
|
|
Loading…
Reference in a new issue