1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

Kernel: Remove unnecessary churn in ConsoleManagement

The maximum number of virtual consoles is determined at compile time,
so we can pre-allocate that many slots, dodging some heap allocations.

Furthermore, virtual consoles are never destroyed, so it's fine to
simply store a raw pointer to the currently active one.
This commit is contained in:
Andreas Kling 2021-08-08 00:44:25 +02:00
parent 652fa54495
commit 2ff3c54153
2 changed files with 6 additions and 6 deletions

View file

@ -29,7 +29,7 @@ bool ConsoleManagement::is_initialized()
return false; return false;
if (s_the->m_consoles.is_empty()) if (s_the->m_consoles.is_empty())
return false; return false;
if (s_the->m_active_console.is_null()) if (s_the->m_active_console)
return false; return false;
return true; return true;
} }
@ -58,7 +58,7 @@ UNMAP_AFTER_INIT void ConsoleManagement::initialize()
if (tty_number > m_consoles.size()) { if (tty_number > m_consoles.size()) {
PANIC("Switch to tty value is invalid: {} ", tty_number); PANIC("Switch to tty value is invalid: {} ", tty_number);
} }
m_active_console = m_consoles[tty_number]; m_active_console = &m_consoles[tty_number];
ScopedSpinLock lock(m_lock); ScopedSpinLock lock(m_lock);
m_active_console->set_active(true); m_active_console->set_active(true);
if (!m_active_console->is_graphical()) if (!m_active_console->is_graphical())
@ -75,7 +75,7 @@ void ConsoleManagement::switch_to(unsigned index)
bool was_graphical = m_active_console->is_graphical(); bool was_graphical = m_active_console->is_graphical();
m_active_console->set_active(false); m_active_console->set_active(false);
m_active_console = m_consoles[index]; m_active_console = &m_consoles[index];
dbgln_if(VIRTUAL_CONSOLE_DEBUG, "Console: Switch to {}", index); dbgln_if(VIRTUAL_CONSOLE_DEBUG, "Console: Switch to {}", index);
// Before setting current console to be "active", switch between graphical mode to "textual" mode // Before setting current console to be "active", switch between graphical mode to "textual" mode

View file

@ -20,7 +20,7 @@ class ConsoleManagement {
public: public:
ConsoleManagement(); ConsoleManagement();
static constexpr unsigned s_max_virtual_consoles = 6; static constexpr size_t s_max_virtual_consoles = 6;
static bool is_initialized(); static bool is_initialized();
static ConsoleManagement& the(); static ConsoleManagement& the();
@ -38,8 +38,8 @@ public:
RecursiveSpinLock& tty_write_lock() { return m_tty_write_lock; } RecursiveSpinLock& tty_write_lock() { return m_tty_write_lock; }
private: private:
NonnullRefPtrVector<VirtualConsole> m_consoles; NonnullRefPtrVector<VirtualConsole, s_max_virtual_consoles> m_consoles;
RefPtr<VirtualConsole> m_active_console; VirtualConsole* m_active_console { nullptr };
SpinLock<u8> m_lock; SpinLock<u8> m_lock;
RecursiveSpinLock m_tty_write_lock; RecursiveSpinLock m_tty_write_lock;
}; };