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/FileSystem/DevPtsFS.cpp | |
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/FileSystem/DevPtsFS.cpp')
-rw-r--r-- | Kernel/FileSystem/DevPtsFS.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index d05437591a..3c781e73cd 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS.cpp @@ -113,7 +113,7 @@ DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index, SlavePTY* pty) : Inode(fs, index) { if (pty) - m_pty = pty->make_weak_ptr(); + m_pty = *pty; } DevPtsFSInode::~DevPtsFSInode() @@ -132,9 +132,9 @@ ssize_t DevPtsFSInode::write_bytes(off_t, ssize_t, const UserOrKernelBuffer&, Fi InodeMetadata DevPtsFSInode::metadata() const { - if (m_pty) { + if (auto pty = m_pty.strong_ref()) { auto metadata = m_metadata; - metadata.mtime = m_pty->time_of_last_write(); + metadata.mtime = pty->time_of_last_write(); return metadata; } return m_metadata; |