mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +00:00
Kernel: Simplify (un)registering interrupt logic
Lose a level of indentation and remove a superfluous `handler_slot` check.
This commit is contained in:
parent
100c8f9bcf
commit
5f85f1abaa
2 changed files with 59 additions and 64 deletions
|
@ -64,13 +64,14 @@ static void revert_to_unused_handler(u8 interrupt_number)
|
|||
void register_generic_interrupt_handler(u8 interrupt_number, GenericInterruptHandler& handler)
|
||||
{
|
||||
auto*& handler_slot = s_interrupt_handlers[interrupt_number];
|
||||
if (handler_slot != nullptr) {
|
||||
if (handler_slot == nullptr) {
|
||||
handler_slot = &handler;
|
||||
return;
|
||||
}
|
||||
if (handler_slot->type() == HandlerType::UnhandledInterruptHandler) {
|
||||
if (handler_slot) {
|
||||
auto* unhandled_handler = static_cast<UnhandledInterruptHandler*>(handler_slot);
|
||||
unhandled_handler->unregister_interrupt_handler();
|
||||
delete unhandled_handler;
|
||||
}
|
||||
handler_slot = &handler;
|
||||
return;
|
||||
}
|
||||
|
@ -94,18 +95,14 @@ void register_generic_interrupt_handler(u8 interrupt_number, GenericInterruptHan
|
|||
return;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
} else {
|
||||
handler_slot = &handler;
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_generic_interrupt_handler(u8 interrupt_number, GenericInterruptHandler& handler)
|
||||
{
|
||||
auto*& handler_slot = s_interrupt_handlers[interrupt_number];
|
||||
VERIFY(handler_slot != nullptr);
|
||||
if (handler_slot->type() == HandlerType::UnhandledInterruptHandler) {
|
||||
if (handler_slot->type() == HandlerType::UnhandledInterruptHandler)
|
||||
return;
|
||||
}
|
||||
if (handler_slot->is_shared_handler() && !handler_slot->is_sharing_with_others()) {
|
||||
VERIFY(handler_slot->type() == HandlerType::SharedIRQHandler);
|
||||
auto* shared_handler = static_cast<SharedIRQHandler*>(handler_slot);
|
||||
|
|
|
@ -478,13 +478,14 @@ void register_generic_interrupt_handler(u8 interrupt_number, GenericInterruptHan
|
|||
{
|
||||
VERIFY(interrupt_number < GENERIC_INTERRUPT_HANDLERS_COUNT);
|
||||
auto*& handler_slot = s_interrupt_handler[interrupt_number];
|
||||
if (handler_slot != nullptr) {
|
||||
if (handler_slot == nullptr) {
|
||||
handler_slot = &handler;
|
||||
return;
|
||||
}
|
||||
if (handler_slot->type() == HandlerType::UnhandledInterruptHandler) {
|
||||
if (handler_slot) {
|
||||
auto* unhandled_handler = static_cast<UnhandledInterruptHandler*>(handler_slot);
|
||||
unhandled_handler->unregister_interrupt_handler();
|
||||
delete unhandled_handler;
|
||||
}
|
||||
handler_slot = &handler;
|
||||
return;
|
||||
}
|
||||
|
@ -508,9 +509,6 @@ void register_generic_interrupt_handler(u8 interrupt_number, GenericInterruptHan
|
|||
return;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
} else {
|
||||
handler_slot = &handler;
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_generic_interrupt_handler(u8 interrupt_number, GenericInterruptHandler& handler)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue