1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 08:00:47 +00:00
Commit Graph

2 Commits

Author SHA1 Message Date
Andreas Kling
ae3ffdd521 AK: Make it possible to not using AK classes into the global namespace
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by
default, but can be overridden by build flags.

This is a step towards integrating Jakt and AK types.
2022-11-26 15:51:34 +01:00
Andreas Kling
c9a35e104b AK: Add RefCountForwarder<T>
This is a convenience template that implements reference count
forwarding. This means that an object forwards ref() and unref() to
another object.

We can use this when two ref-counted objects need to keep each other
alive. This situation poses two problems:

- Using 2x RefPtr would cause a ref cycle and leak both objects.
- Using 2x WeakPtr would allow one of them to be destroyed early.

With RefCountForwarder, only one of the objects has a ref count. The
object with the ref count points to the forwarding object by using a
non-counting smart pointer (OwnPtr or NonnullOwnPtr). Thus, both objects
are kept alive by the same ref count, and they can safely point to each
other without worrying about disjoint lifetimes.
2021-12-09 21:28:52 +01:00