1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:47:35 +00:00

Kernel: Switch singletons to use new Singleton class

Fixes #3226
This commit is contained in:
Tom 2020-08-20 09:36:06 -06:00 committed by Andreas Kling
parent 527c8047fe
commit f48feae0b2
44 changed files with 184 additions and 146 deletions

View file

@ -29,6 +29,7 @@
#include <Kernel/IO.h>
#include <Kernel/PCI/Access.h>
#include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h>
@ -56,7 +57,12 @@ namespace Kernel {
#define VBE_DISPI_ENABLED 0x01
#define VBE_DISPI_LFB_ENABLED 0x40
static BXVGADevice* s_the;
static auto s_the = make_singleton<BXVGADevice>();
void BXVGADevice::initialize()
{
s_the.ensure_instance();
}
BXVGADevice& BXVGADevice::the()
{
@ -67,7 +73,6 @@ BXVGADevice::BXVGADevice()
: BlockDevice(29, 0)
{
s_the = this;
m_framebuffer_address = PhysicalAddress(find_framebuffer_address());
set_safe_resolution();
}

View file

@ -36,6 +36,7 @@ namespace Kernel {
class BXVGADevice final : public BlockDevice {
AK_MAKE_ETERNAL
public:
static void initialize();
static BXVGADevice& the();
BXVGADevice();

View file

@ -26,16 +26,15 @@
#include <Kernel/Devices/Device.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/Singleton.h>
#include <LibC/errno_numbers.h>
namespace Kernel {
static HashMap<u32, Device*>* s_all_devices;
static auto s_all_devices = make_singleton<HashMap<u32, Device*>>();
HashMap<u32, Device*>& Device::all_devices()
{
if (s_all_devices == nullptr)
s_all_devices = new HashMap<u32, Device*>;
return *s_all_devices;
}

View file

@ -31,6 +31,7 @@
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/Devices/KeyboardDevice.h>
#include <Kernel/IO.h>
#include <Kernel/Singleton.h>
#include <Kernel/TTY/VirtualConsole.h>
//#define KEYBOARD_DEBUG
@ -335,11 +336,15 @@ void KeyboardDevice::handle_irq(const RegisterState&)
}
}
static KeyboardDevice* s_the;
static auto s_the = make_singleton<KeyboardDevice>();
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)

View file

@ -45,6 +45,7 @@ class KeyboardDevice final : public IRQHandler
public:
using Event = KeyEvent;
static void initialize();
static KeyboardDevice& the();
virtual ~KeyboardDevice() override;

View file

@ -26,21 +26,25 @@
#include "NullDevice.h"
#include <AK/StdLibExtras.h>
#include <Kernel/Singleton.h>
namespace Kernel {
static NullDevice* s_the;
static auto s_the = make_singleton<NullDevice>();
void NullDevice::initialize()
{
s_the.ensure_instance();
}
NullDevice& NullDevice::the()
{
ASSERT(s_the);
return *s_the;
}
NullDevice::NullDevice()
: CharacterDevice(1, 3)
{
s_the = this;
}
NullDevice::~NullDevice()

View file

@ -36,6 +36,7 @@ public:
NullDevice();
virtual ~NullDevice() override;
static void initialize();
static NullDevice& the();
private:

View file

@ -31,6 +31,7 @@
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/IO.h>
#include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/VM/MemoryManager.h>
namespace Kernel {
@ -106,13 +107,12 @@ namespace Kernel {
#define PCI_Mass_Storage_Class 0x1
#define PCI_IDE_Controller_Subclass 0x1
static auto s_pata_lock = make_singleton<Lock>();
static Lock& s_lock()
{
static Lock* lock;
if (!lock)
lock = new Lock;
return *lock;
return *s_pata_lock;
};
OwnPtr<PATAChannel> PATAChannel::create(ChannelType type, bool force_pio)

View file

@ -28,6 +28,7 @@
#include <Kernel/Devices/PS2MouseDevice.h>
#include <Kernel/Devices/VMWareBackdoor.h>
#include <Kernel/IO.h>
#include <Kernel/Singleton.h>
namespace Kernel {
@ -56,13 +57,12 @@ namespace Kernel {
//#define PS2MOUSE_DEBUG
static PS2MouseDevice* s_the;
static auto s_the = make_singleton<PS2MouseDevice>();
PS2MouseDevice::PS2MouseDevice()
: IRQHandler(IRQ_MOUSE)
, CharacterDevice(10, 1)
{
s_the = this;
initialize();
}
@ -70,6 +70,11 @@ PS2MouseDevice::~PS2MouseDevice()
{
}
void PS2MouseDevice::create()
{
s_the.ensure_instance();
}
PS2MouseDevice& PS2MouseDevice::the()
{
return *s_the;

View file

@ -40,6 +40,7 @@ public:
PS2MouseDevice();
virtual ~PS2MouseDevice() override;
static void create();
static PS2MouseDevice& the();
// ^CharacterDevice

View file

@ -31,6 +31,7 @@
#include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/IO.h>
#include <Kernel/Singleton.h>
//#define SB16_DEBUG
@ -76,13 +77,12 @@ void SB16::set_sample_rate(uint16_t hz)
dsp_write((u8)hz);
}
static SB16* s_the;
static auto s_the = make_singleton<SB16>();
SB16::SB16()
: IRQHandler(SB16_DEFAULT_IRQ)
, CharacterDevice(42, 42) // ### ?
{
s_the = this;
initialize();
}
@ -90,6 +90,11 @@ SB16::~SB16()
{
}
void SB16::create()
{
s_the.ensure_instance();
}
SB16& SB16::the()
{
return *s_the;

View file

@ -42,6 +42,7 @@ public:
SB16();
virtual ~SB16() override;
static void create();
static SB16& the();
// ^CharacterDevice

View file

@ -25,12 +25,14 @@
*/
#include <AK/Assertions.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Devices/VMWareBackdoor.h>
#include <Kernel/API/MousePacket.h>
#include <Kernel/IO.h>
#include <Kernel/Singleton.h>
namespace Kernel {
@ -80,33 +82,40 @@ inline void vmware_high_bandwidth_get(VMWareCommand& command)
: "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
}
static VMWareBackdoor* s_vmware_backdoor;
static bool detect_presence()
class VMWareBackdoorDetector
{
VMWareCommand command;
command.bx = ~VMWARE_MAGIC;
command.command = VMWARE_CMD_GETVERSION;
vmware_out(command);
if (command.bx != VMWARE_MAGIC || command.ax == 0xFFFFFFFF)
return false;
return true;
}
public:
VMWareBackdoorDetector()
{
if (detect_presence())
m_backdoor = make<VMWareBackdoor>();
}
VMWareBackdoor* VMWareBackdoor::initialize()
{
ASSERT(s_vmware_backdoor == nullptr);
if (!detect_presence())
return nullptr;
VMWareBackdoor* get_instance()
{
return m_backdoor.ptr();
}
s_vmware_backdoor = new VMWareBackdoor;
klog() << "VMWare backdoor opened.";
return s_vmware_backdoor;
}
private:
static bool detect_presence()
{
VMWareCommand command;
command.bx = ~VMWARE_MAGIC;
command.command = VMWARE_CMD_GETVERSION;
vmware_out(command);
if (command.bx != VMWARE_MAGIC || command.ax == 0xFFFFFFFF)
return false;
return true;
}
OwnPtr<VMWareBackdoor> m_backdoor;
};
static auto s_vmware_backdoor = make_singleton<VMWareBackdoorDetector>();
VMWareBackdoor* VMWareBackdoor::the()
{
return s_vmware_backdoor;
return s_vmware_backdoor->get_instance();
}
VMWareBackdoor::VMWareBackdoor()

View file

@ -63,9 +63,9 @@ class VMWareBackdoor {
AK_MAKE_ETERNAL;
public:
VMWareBackdoor();
static VMWareBackdoor* the();
static VMWareBackdoor* initialize();
bool vmmouse_is_absolute() const;
void enable_absolute_vmmouse();
void disable_absolute_vmmouse();
@ -76,7 +76,6 @@ public:
private:
void send_high_bandwidth(VMWareCommand& command);
void get_high_bandwidth(VMWareCommand& command);
VMWareBackdoor();
bool detect_vmmouse();
bool m_vmmouse_absolute { false };
};