mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-03 04:50:29 +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
Notes:
sideshowbarker
2024-07-17 21:12:59 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a4b4b358ffd
4 changed files with 0 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue