mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe
This makes most operations thread safe, especially so that they can safely be used in the Kernel. This includes obtaining a strong reference from a weak reference, which now requires an explicit call to WeakPtr::strong_ref(). Another major change is that Weakable::make_weak_ref() may require the explicit target type. Previously we used reinterpret_cast in WeakPtr, assuming that it can be properly converted. But WeakPtr does not necessarily have the knowledge to be able to do this. Instead, we now ask the class itself to deliver a WeakPtr to the type that we want. Also, WeakLink is no longer specific to a target type. The reason for this is that we want to be able to safely convert e.g. WeakPtr<T> to WeakPtr<U>, and before this we just reinterpret_cast the internal WeakLink<T> to WeakLink<U>, which is a bold assumption that it would actually produce the correct code. Instead, WeakLink now operates on just a raw pointer and we only make those constructors/operators available if we can verify that it can be safely cast. In order to guarantee thread safety, we now use the least significant bit in the pointer for locking purposes. This also means that only properly aligned pointers can be used.
This commit is contained in:
parent
3c1ef744f6
commit
75f61fe3d9
Notes:
sideshowbarker
2024-07-19 01:27:31 +09:00
Author: https://github.com/tomuta
Commit: 75f61fe3d9
Pull-request: https://github.com/SerenityOS/serenity/pull/4012
50 changed files with 819 additions and 322 deletions
|
@ -45,7 +45,7 @@ HTMLScriptElement::~HTMLScriptElement()
|
|||
|
||||
void HTMLScriptElement::set_parser_document(Badge<HTMLDocumentParser>, DOM::Document& document)
|
||||
{
|
||||
m_parser_document = document.make_weak_ptr();
|
||||
m_parser_document = document;
|
||||
}
|
||||
|
||||
void HTMLScriptElement::set_non_blocking(Badge<HTMLDocumentParser>, bool non_blocking)
|
||||
|
@ -82,12 +82,12 @@ void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>)
|
|||
// FIXME: Check the "type" and "language" attributes
|
||||
|
||||
if (parser_document) {
|
||||
m_parser_document = parser_document->make_weak_ptr();
|
||||
m_parser_document = *parser_document;
|
||||
m_non_blocking = false;
|
||||
}
|
||||
|
||||
m_already_started = true;
|
||||
m_preparation_time_document = document().make_weak_ptr();
|
||||
m_preparation_time_document = document();
|
||||
|
||||
if (parser_document && parser_document.ptr() != m_preparation_time_document.ptr()) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue