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
Notes: sideshowbarker 2024-07-17 21:12:59 +09:00
4 changed files with 0 additions and 15 deletions

View File

@ -69,9 +69,6 @@ public:
that->will_be_destroyed();
delete static_cast<const T*>(this);
return true;
} else if (new_ref_count == 1) {
if constexpr (requires { that->one_ref_left(); })
that->one_ref_left();
}
return false;
}

View File

@ -49,9 +49,6 @@ public:
if constexpr (requires { that->will_be_destroyed(); })
that->will_be_destroyed();
delete that;
} else if (new_ref_count == 1) {
if constexpr (requires { that->one_ref_left(); })
that->one_ref_left();
}
return new_ref_count == 0;
}

View File

@ -77,10 +77,6 @@ public:
delete that;
return true;
}
if (new_ref_count == 1) {
if constexpr (requires { that->one_ref_left(); })
that->one_ref_left();
}
return false;
}
};

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);