From dcfa93e71f09ca3a6992529790ec8981ce5452f0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 13 Jul 2019 20:15:17 +0200 Subject: SB16: Use a snooze alarm to block the current thread while playing. --- Kernel/Devices/SB16.cpp | 17 ++++++++++------- Kernel/Devices/SB16.h | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index 1e6bc45163..141f01ade3 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -1,5 +1,6 @@ -#include "SB16.h" -#include "IO.h" +#include +#include +#include #include //#define SB16_DEBUG @@ -48,6 +49,7 @@ static SB16* s_the; SB16::SB16() : IRQHandler(5) , CharacterDevice(42, 42) // ### ? + , m_interrupt_alarm(*this) { s_the = this; initialize(); @@ -141,11 +143,7 @@ void SB16::wait_for_irq() #ifdef SB16_DEBUG kprintf("SB16: waiting for interrupt...\n"); #endif - // FIXME: Add timeout. - while (!m_interrupted) { - // FIXME: Put this process into a Blocked state instead, it's stupid to wake up just to check a flag. - Scheduler::yield(); - } + current->snooze_until(m_interrupt_alarm); #ifdef SB16_DEBUG kprintf("SB16: got interrupt!\n"); #endif @@ -196,3 +194,8 @@ ssize_t SB16::write(FileDescription&, const u8* data, ssize_t length) wait_for_irq(); return length; } + +bool SB16InterruptAlarm::is_ringing() const +{ + return m_device.got_interrupt({}); +} diff --git a/Kernel/Devices/SB16.h b/Kernel/Devices/SB16.h index 20bbb8f6ed..bef47f5f07 100644 --- a/Kernel/Devices/SB16.h +++ b/Kernel/Devices/SB16.h @@ -1,11 +1,26 @@ #pragma once #include +#include #include #include #include #include +class SB16; + +class SB16InterruptAlarm final : public Alarm { +public: + SB16InterruptAlarm(SB16& device) + : m_device(device) + { + } + virtual bool is_ringing() const override; + +private: + SB16& m_device; +}; + class SB16 final : public IRQHandler , public CharacterDevice { public: @@ -20,6 +35,8 @@ public: virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; virtual bool can_write(FileDescription&) const override { return true; } + bool got_interrupt(Badge) const { return m_interrupted; } + private: // ^IRQHandler virtual void handle_irq() override; @@ -37,4 +54,6 @@ private: RefPtr m_dma_buffer_page; bool m_interrupted { false }; int m_major_version { 0 }; + + SB16InterruptAlarm m_interrupt_alarm; }; -- cgit v1.2.3