1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:38:13 +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:
Andreas Kling 2022-01-11 01:05:18 +01:00
parent 08e927f084
commit a4b4b358ff
4 changed files with 0 additions and 15 deletions

View file

@ -17,10 +17,8 @@ struct Object2 : Object {
};
struct SelfAwareObject : public RefCounted<SelfAwareObject> {
void one_ref_left() { m_has_one_ref_left = true; }
void will_be_destroyed() { ++num_destroyed; }
bool m_has_one_ref_left = false;
static size_t num_destroyed;
};
size_t SelfAwareObject::num_destroyed = 0;
@ -132,17 +130,14 @@ TEST_CASE(self_observers)
{
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
EXPECT_EQ(object->ref_count(), 1u);
EXPECT_EQ(object->m_has_one_ref_left, false);
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
object->ref();
EXPECT_EQ(object->ref_count(), 2u);
EXPECT_EQ(object->m_has_one_ref_left, false);
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
object->unref();
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, 1u);