summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/DevPtsFS.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-08-20 09:36:06 -0600
committerAndreas Kling <kling@serenityos.org>2020-08-21 11:47:35 +0200
commitf48feae0b2a300992479abf0b2ded85e45ac6045 (patch)
treed0b01169a60261135ee15a8d4a6abd01785a7bec /Kernel/FileSystem/DevPtsFS.cpp
parent527c8047fe0a08ade2e17fd096ad9b4ebc103ec5 (diff)
downloadserenity-f48feae0b2a300992479abf0b2ded85e45ac6045.zip
Kernel: Switch singletons to use new Singleton class
Fixes #3226
Diffstat (limited to 'Kernel/FileSystem/DevPtsFS.cpp')
-rw-r--r--Kernel/FileSystem/DevPtsFS.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp
index ac060d026b..b3db215c5d 100644
--- a/Kernel/FileSystem/DevPtsFS.cpp
+++ b/Kernel/FileSystem/DevPtsFS.cpp
@@ -28,6 +28,7 @@
#include <AK/StringView.h>
#include <Kernel/FileSystem/DevPtsFS.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
+#include <Kernel/Singleton.h>
#include <Kernel/TTY/SlavePTY.h>
namespace Kernel {
@@ -45,14 +46,10 @@ DevPtsFS::~DevPtsFS()
{
}
-static HashTable<unsigned>* ptys;
+static auto s_ptys = make_singleton<HashTable<unsigned>>();
bool DevPtsFS::initialize()
{
- if (ptys == nullptr) {
- ptys = new HashTable<unsigned>();
- }
-
m_root_inode = adopt(*new DevPtsFSInode(*this, 1));
m_root_inode->m_metadata.inode = { fsid(), 1 };
m_root_inode->m_metadata.mode = 0040555;
@@ -104,12 +101,12 @@ RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
void DevPtsFS::register_slave_pty(SlavePTY& slave_pty)
{
- ptys->set(slave_pty.index());
+ s_ptys->set(slave_pty.index());
}
void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
{
- ptys->remove(slave_pty.index());
+ s_ptys->remove(slave_pty.index());
}
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index)
@@ -144,7 +141,7 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEn
callback({ ".", identifier(), 0 });
callback({ "..", identifier(), 0 });
- for (unsigned pty_index : *ptys) {
+ for (unsigned pty_index : *s_ptys) {
String name = String::number(pty_index);
InodeIdentifier identifier = { fsid(), pty_index_to_inode_index(pty_index) };
callback({ name, identifier, 0 });
@@ -157,7 +154,7 @@ KResultOr<size_t> DevPtsFSInode::directory_entry_count() const
{
ASSERT(identifier().index() == 1);
- return 2 + ptys->size();
+ return 2 + s_ptys->size();
}
RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
@@ -170,7 +167,7 @@ RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
auto& fs = static_cast<DevPtsFS&>(this->fs());
auto pty_index = name.to_uint();
- if (pty_index.has_value() && ptys->contains(pty_index.value())) {
+ if (pty_index.has_value() && s_ptys->contains(pty_index.value())) {
return fs.get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
}