mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
Kernel: Use SpinlockProtected list in SharedIRQHandler
Adding handlers to the SharedIRQHandler without any lock is not thread safe. Use SpinlockProtected list instead.
This commit is contained in:
parent
fd8a154f8c
commit
756a73471e
2 changed files with 17 additions and 12 deletions
|
@ -23,15 +23,17 @@ UNMAP_AFTER_INIT void SharedIRQHandler::initialize(u8 interrupt_number)
|
||||||
void SharedIRQHandler::register_handler(GenericInterruptHandler& handler)
|
void SharedIRQHandler::register_handler(GenericInterruptHandler& handler)
|
||||||
{
|
{
|
||||||
dbgln_if(INTERRUPT_DEBUG, "Interrupt Handler registered @ Shared Interrupt Handler {}", interrupt_number());
|
dbgln_if(INTERRUPT_DEBUG, "Interrupt Handler registered @ Shared Interrupt Handler {}", interrupt_number());
|
||||||
m_handlers.append(handler);
|
m_handlers.with([&handler](auto& list) { list.append(handler); });
|
||||||
enable_interrupt_vector();
|
enable_interrupt_vector();
|
||||||
}
|
}
|
||||||
void SharedIRQHandler::unregister_handler(GenericInterruptHandler& handler)
|
void SharedIRQHandler::unregister_handler(GenericInterruptHandler& handler)
|
||||||
{
|
{
|
||||||
dbgln_if(INTERRUPT_DEBUG, "Interrupt Handler unregistered @ Shared Interrupt Handler {}", interrupt_number());
|
dbgln_if(INTERRUPT_DEBUG, "Interrupt Handler unregistered @ Shared Interrupt Handler {}", interrupt_number());
|
||||||
m_handlers.remove(handler);
|
m_handlers.with([&handler, this](auto& list) {
|
||||||
if (m_handlers.is_empty())
|
list.remove(handler);
|
||||||
disable_interrupt_vector();
|
if (list.is_empty())
|
||||||
|
disable_interrupt_vector();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SharedIRQHandler::eoi()
|
bool SharedIRQHandler::eoi()
|
||||||
|
@ -43,9 +45,7 @@ bool SharedIRQHandler::eoi()
|
||||||
|
|
||||||
void SharedIRQHandler::enumerate_handlers(Function<void(GenericInterruptHandler&)>& callback)
|
void SharedIRQHandler::enumerate_handlers(Function<void(GenericInterruptHandler&)>& callback)
|
||||||
{
|
{
|
||||||
for (auto& handler : m_handlers) {
|
m_handlers.for_each([&](auto& handler) { callback(handler); });
|
||||||
callback(handler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedIRQHandler::SharedIRQHandler(u8 irq)
|
SharedIRQHandler::SharedIRQHandler(u8 irq)
|
||||||
|
@ -67,11 +67,11 @@ bool SharedIRQHandler::handle_interrupt(RegisterState const& regs)
|
||||||
|
|
||||||
if constexpr (INTERRUPT_DEBUG) {
|
if constexpr (INTERRUPT_DEBUG) {
|
||||||
dbgln("Interrupt @ {}", interrupt_number());
|
dbgln("Interrupt @ {}", interrupt_number());
|
||||||
dbgln("Interrupt Handlers registered - {}", m_handlers.size_slow());
|
dbgln("Interrupt Handlers registered - {}", sharing_devices_count());
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
bool was_handled = false;
|
bool was_handled = false;
|
||||||
for (auto& handler : m_handlers) {
|
m_handlers.for_each([&](auto& handler) {
|
||||||
dbgln_if(INTERRUPT_DEBUG, "Going for Interrupt Handling @ {}, Shared Interrupt {}", i, interrupt_number());
|
dbgln_if(INTERRUPT_DEBUG, "Going for Interrupt Handling @ {}, Shared Interrupt {}", i, interrupt_number());
|
||||||
if (handler.handle_interrupt(regs)) {
|
if (handler.handle_interrupt(regs)) {
|
||||||
handler.increment_call_count();
|
handler.increment_call_count();
|
||||||
|
@ -79,7 +79,8 @@ bool SharedIRQHandler::handle_interrupt(RegisterState const& regs)
|
||||||
}
|
}
|
||||||
dbgln_if(INTERRUPT_DEBUG, "Going for Interrupt Handling @ {}, Shared Interrupt {} - End", i, interrupt_number());
|
dbgln_if(INTERRUPT_DEBUG, "Going for Interrupt Handling @ {}, Shared Interrupt {} - End", i, interrupt_number());
|
||||||
i++;
|
i++;
|
||||||
}
|
});
|
||||||
|
|
||||||
return was_handled;
|
return was_handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <Kernel/Arch/IRQController.h>
|
#include <Kernel/Arch/IRQController.h>
|
||||||
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
||||||
#include <Kernel/Library/LockRefPtr.h>
|
#include <Kernel/Library/LockRefPtr.h>
|
||||||
|
#include <Kernel/Locking/SpinlockProtected.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class IRQHandler;
|
class IRQHandler;
|
||||||
|
@ -27,7 +28,10 @@ public:
|
||||||
|
|
||||||
void enumerate_handlers(Function<void(GenericInterruptHandler&)>&);
|
void enumerate_handlers(Function<void(GenericInterruptHandler&)>&);
|
||||||
|
|
||||||
virtual size_t sharing_devices_count() const override { return m_handlers.size_slow(); }
|
virtual size_t sharing_devices_count() const override
|
||||||
|
{
|
||||||
|
return m_handlers.with([](auto& list) { return list.size_slow(); });
|
||||||
|
}
|
||||||
virtual bool is_shared_handler() const override { return true; }
|
virtual bool is_shared_handler() const override { return true; }
|
||||||
virtual bool is_sharing_with_others() const override { return false; }
|
virtual bool is_sharing_with_others() const override { return false; }
|
||||||
|
|
||||||
|
@ -40,7 +44,7 @@ private:
|
||||||
void disable_interrupt_vector();
|
void disable_interrupt_vector();
|
||||||
explicit SharedIRQHandler(u8 interrupt_number);
|
explicit SharedIRQHandler(u8 interrupt_number);
|
||||||
bool m_enabled { true };
|
bool m_enabled { true };
|
||||||
GenericInterruptHandler::List m_handlers;
|
SpinlockProtected<GenericInterruptHandler::List, LockRank::None> m_handlers;
|
||||||
NonnullLockRefPtr<IRQController> m_responsible_irq_controller;
|
NonnullLockRefPtr<IRQController> m_responsible_irq_controller;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue