diff options
author | Tom <tomut@yahoo.com> | 2020-08-24 19:35:19 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-25 09:48:48 +0200 |
commit | d89582880ed81c38df67687eadfc0764b6ce5ddd (patch) | |
tree | 3ff52c4e8808c5167ee37d5bf0a6669e9a18dfb4 /Kernel/Devices/KeyboardDevice.cpp | |
parent | ba6e4fb77f00587d2bd57865a00b1a4526684741 (diff) | |
download | serenity-d89582880ed81c38df67687eadfc0764b6ce5ddd.zip |
Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.
Fixes #3226
Diffstat (limited to 'Kernel/Devices/KeyboardDevice.cpp')
-rw-r--r-- | Kernel/Devices/KeyboardDevice.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index ac1d5ac349..531c488a9f 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -26,6 +26,7 @@ #include <AK/Assertions.h> #include <AK/ByteBuffer.h> +#include <AK/Singleton.h> #include <AK/StringView.h> #include <AK/Types.h> #include <Kernel/Arch/i386/CPU.h> @@ -335,11 +336,15 @@ void KeyboardDevice::handle_irq(const RegisterState&) } } -static KeyboardDevice* s_the; +static AK::Singleton<KeyboardDevice> s_the; + +void KeyboardDevice::initialize() +{ + s_the.ensure_instance(); +} KeyboardDevice& KeyboardDevice::the() { - ASSERT(s_the); return *s_the; } @@ -347,8 +352,6 @@ KeyboardDevice::KeyboardDevice() : IRQHandler(IRQ_KEYBOARD) , CharacterDevice(85, 1) { - s_the = this; - // Empty the buffer of any pending data. // I don't care what you've been pressing until now! while (IO::in8(I8042_STATUS) & I8042_BUFFER_FULL) |