summaryrefslogtreecommitdiff
path: root/AK/Weakable.h
AgeCommit message (Collapse)Author
2020-11-10AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safeTom
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.
2020-08-30AK: Unbreak building with extra debug macrosBen Wiederhake
2020-07-04AK: Add Weakable::revoke_weak_ptrs()Andreas Kling
This allows you to clear all the WeakPtrs pointing at a Weakable *now* instead of waiting until the Weakable is destroyed.
2020-06-12AK: Remove useless castsSergey Bugaev
2020-02-15AK: Make sure that Weakable always has the same memory layoutAndreas Kling
Weakable objects ended up with differing memory layouts in some ports since they don't build with the DEBUG macro defined. Instead of forcing ports to define DEBUG, just put this behind a custom WEAKABLE_DEBUG macro and leave it always-on for now.
2020-01-25AK: Assert if trying to create a WeakPtr to an object being destroyedAndreas Kling
Trying to make_weak_ptr() on something that has begun destruction is very unlikely to be what you want. Let's assert if that scenario comes up so we can catch it immediately.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-06-21AK: Rename Retainable.h => RefCounted.h.Andreas Kling
2019-06-21AK: Rename RetainPtr.h => RefPtr.h, Retained.h => NonnullRefPtr.h.Andreas Kling
2019-06-21AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr.Andreas Kling
2019-06-21AK: Rename Retainable => RefCounted.Andreas Kling
(And various related renames that go along with it.)
2019-05-28Add clang-format fileRobin Burchell
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
2019-01-31Big, possibly complete sweep of naming changes.Andreas Kling
2018-10-13Start using WeakPtr for some of the WindowManager window pointers.Andreas Kling
2018-10-13Add WeakPtr/Weakable templates.Andreas Kling