mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:57:44 +00:00
Kernel/Devices: Defer creation of SysFS component after the constructor
Instead of doing so in the constructor, let's do immediately after the constructor, so we can safely pass a reference of a Device, so the SysFSDeviceComponent constructor can use that object to identify whether it's a block device or a character device. This allows to us to not hold a device in SysFSDeviceComponent with a RefPtr. Also, we also call the before_removing method in both SlavePTY::unref and File::unref, so because Device has that method being overrided, it can ensure the device is removed always cleanly.
This commit is contained in:
parent
c545d4ffcb
commit
f5de4f24b2
41 changed files with 142 additions and 57 deletions
|
@ -22,6 +22,8 @@ KResultOr<NonnullRefPtr<MasterPTY>> MasterPTY::try_create(unsigned int index)
|
|||
auto master_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer))));
|
||||
auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index)));
|
||||
master_pty->m_slave = slave_pty;
|
||||
master_pty->after_inserting();
|
||||
slave_pty->after_inserting();
|
||||
return master_pty;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,11 @@ UNMAP_AFTER_INIT PTYMultiplexer::~PTYMultiplexer()
|
|||
{
|
||||
}
|
||||
|
||||
void PTYMultiplexer::initialize()
|
||||
{
|
||||
the().after_inserting();
|
||||
}
|
||||
|
||||
KResultOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
||||
{
|
||||
return m_freelist.with_exclusive([&](auto& freelist) -> KResultOr<NonnullRefPtr<OpenFileDescription>> {
|
||||
|
|
|
@ -20,10 +20,7 @@ public:
|
|||
PTYMultiplexer();
|
||||
virtual ~PTYMultiplexer() override;
|
||||
|
||||
static void initialize()
|
||||
{
|
||||
the();
|
||||
}
|
||||
static void initialize();
|
||||
static PTYMultiplexer& the();
|
||||
|
||||
// ^CharacterDevice
|
||||
|
|
|
@ -28,8 +28,10 @@ bool SlavePTY::unref() const
|
|||
m_list_node.remove();
|
||||
return true;
|
||||
});
|
||||
if (did_hit_zero)
|
||||
if (did_hit_zero) {
|
||||
const_cast<SlavePTY&>(*this).before_removing();
|
||||
delete this;
|
||||
}
|
||||
return did_hit_zero;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,12 +103,18 @@ void VirtualConsole::set_graphical(bool graphical)
|
|||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create(size_t index)
|
||||
{
|
||||
return adopt_ref(*new VirtualConsole(index));
|
||||
auto virtual_console_or_error = try_create_device<VirtualConsole>(index);
|
||||
// FIXME: Find a way to propagate errors
|
||||
VERIFY(!virtual_console_or_error.is_error());
|
||||
return virtual_console_or_error.release_value();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create_with_preset_log(size_t index, const CircularQueue<char, 16384>& log)
|
||||
{
|
||||
return adopt_ref(*new VirtualConsole(index, log));
|
||||
auto virtual_console_or_error = try_create_device<VirtualConsole>(index, log);
|
||||
// FIXME: Find a way to propagate errors
|
||||
VERIFY(!virtual_console_or_error.is_error());
|
||||
return virtual_console_or_error.release_value();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT void VirtualConsole::initialize()
|
||||
|
|
|
@ -84,9 +84,11 @@ public:
|
|||
|
||||
void emit_char(char);
|
||||
|
||||
private:
|
||||
// FIXME: We expose these constructors to make try_create_device helper to work
|
||||
explicit VirtualConsole(const unsigned index);
|
||||
VirtualConsole(const unsigned index, const CircularQueue<char, 16384>&);
|
||||
|
||||
private:
|
||||
// ^KeyboardClient
|
||||
virtual void on_key_pressed(KeyEvent) override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue