mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:07:46 +00:00
Kernel: Convert SlavePTY all-instances HashTable to an IntrusiveList
This simplifies the DevPtsFS implementation somewhat, as it no longer requires SlavePTY to register itself with it, since it can now simply use the list of SlavePTY instances.
This commit is contained in:
parent
62719b85e0
commit
0de8c95d49
4 changed files with 53 additions and 33 deletions
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Singleton.h>
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
@ -12,6 +13,26 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static Singleton<SpinLockProtectedValue<SlavePTY::List>> s_all_instances;
|
||||
|
||||
SpinLockProtectedValue<SlavePTY::List>& SlavePTY::all_instances()
|
||||
{
|
||||
return s_all_instances;
|
||||
}
|
||||
|
||||
bool SlavePTY::unref() const
|
||||
{
|
||||
bool did_hit_zero = SlavePTY::all_instances().with([&](auto&) {
|
||||
if (deref_base())
|
||||
return false;
|
||||
m_list_node.remove();
|
||||
return true;
|
||||
});
|
||||
if (did_hit_zero)
|
||||
delete this;
|
||||
return did_hit_zero;
|
||||
}
|
||||
|
||||
SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
|
||||
: TTY(201, index)
|
||||
, m_master(master)
|
||||
|
@ -21,14 +42,14 @@ SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
|
|||
auto process = Process::current();
|
||||
set_uid(process->uid());
|
||||
set_gid(process->gid());
|
||||
DevPtsFS::register_slave_pty(*this);
|
||||
set_size(80, 25);
|
||||
|
||||
SlavePTY::all_instances().with([&](auto& list) { list.append(*this); });
|
||||
}
|
||||
|
||||
SlavePTY::~SlavePTY()
|
||||
{
|
||||
dbgln_if(SLAVEPTY_DEBUG, "~SlavePTY({})", m_index);
|
||||
DevPtsFS::unregister_slave_pty(*this);
|
||||
}
|
||||
|
||||
String const& SlavePTY::tty_name() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue