diff options
author | Tom <tomut@yahoo.com> | 2020-09-29 16:26:13 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-10 19:11:52 +0100 |
commit | 75f61fe3d9055b4e65deecc796401ea2f9e827b2 (patch) | |
tree | ed09858a8bf4071afe859d92178a9e2a77676d62 /Kernel/TTY/TTY.h | |
parent | 3c1ef744f6c55b40c3d89baaa942aac7e0c9110e (diff) | |
download | serenity-75f61fe3d9055b4e65deecc796401ea2f9e827b2.zip |
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.
Diffstat (limited to 'Kernel/TTY/TTY.h')
-rw-r--r-- | Kernel/TTY/TTY.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Kernel/TTY/TTY.h b/Kernel/TTY/TTY.h index 6b9d571336..aafbe17292 100644 --- a/Kernel/TTY/TTY.h +++ b/Kernel/TTY/TTY.h @@ -51,7 +51,12 @@ public: unsigned short rows() const { return m_rows; } unsigned short columns() const { return m_columns; } - ProcessGroupID pgid() const { return m_pg ? m_pg->pgid() : 0; } + ProcessGroupID pgid() const + { + if (auto pg = m_pg.strong_ref()) + return pg->pgid(); + return 0; + } void set_termios(const termios&); bool should_generate_signals() const { return m_termios.c_lflag & ISIG; } |