1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:37:44 +00:00

Revert "Kernel: Switch singletons to use new Singleton class"

This reverts commit f48feae0b2.
This commit is contained in:
Andreas Kling 2020-08-22 17:53:34 +02:00
parent 0addcb45b8
commit 2fd9e72264
44 changed files with 146 additions and 184 deletions

View file

@ -29,7 +29,6 @@
#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>
@ -57,12 +56,7 @@ namespace Kernel {
#define VBE_DISPI_ENABLED 0x01
#define VBE_DISPI_LFB_ENABLED 0x40
static auto s_the = make_singleton<BXVGADevice>();
void BXVGADevice::initialize()
{
s_the.ensure_instance();
}
static BXVGADevice* s_the;
BXVGADevice& BXVGADevice::the()
{
@ -73,6 +67,7 @@ BXVGADevice::BXVGADevice()
: BlockDevice(29, 0)
{
s_the = this;
m_framebuffer_address = PhysicalAddress(find_framebuffer_address());
set_safe_resolution();
}

View file

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

View file

@ -26,15 +26,16 @@
#include <Kernel/Devices/Device.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/Singleton.h>
#include <LibC/errno_numbers.h>
namespace Kernel {
static auto s_all_devices = make_singleton<HashMap<u32, Device*>>();
static HashMap<u32, Device*>* s_all_devices;
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,7 +31,6 @@
#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
@ -336,15 +335,11 @@ void KeyboardDevice::handle_irq(const RegisterState&)
}
}
static auto s_the = make_singleton<KeyboardDevice>();
void KeyboardDevice::initialize()
{
s_the.ensure_instance();
}
static KeyboardDevice* s_the;
KeyboardDevice& KeyboardDevice::the()
{
ASSERT(s_the);
return *s_the;
}
@ -352,6 +347,8 @@ 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,7 +45,6 @@ class KeyboardDevice final : public IRQHandler
public:
using Event = KeyEvent;
static void initialize();
static KeyboardDevice& the();
virtual ~KeyboardDevice() override;

View file

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

View file

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

View file

@ -31,7 +31,6 @@
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/IO.h>
#include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/VM/MemoryManager.h>
namespace Kernel {
@ -107,12 +106,13 @@ 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()
{
return *s_pata_lock;
static Lock* lock;
if (!lock)
lock = new Lock;
return *lock;
};
OwnPtr<PATAChannel> PATAChannel::create(ChannelType type, bool force_pio)

View file

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

View file

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

View file

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

View file

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

View file

@ -25,14 +25,12 @@
*/
#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 {
@ -82,40 +80,33 @@ 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));
}
class VMWareBackdoorDetector
static VMWareBackdoor* s_vmware_backdoor;
static bool detect_presence()
{
public:
VMWareBackdoorDetector()
{
if (detect_presence())
m_backdoor = make<VMWareBackdoor>();
}
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;
}
VMWareBackdoor* get_instance()
{
return m_backdoor.ptr();
}
VMWareBackdoor* VMWareBackdoor::initialize()
{
ASSERT(s_vmware_backdoor == nullptr);
if (!detect_presence())
return nullptr;
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>();
s_vmware_backdoor = new VMWareBackdoor;
klog() << "VMWare backdoor opened.";
return s_vmware_backdoor;
}
VMWareBackdoor* VMWareBackdoor::the()
{
return s_vmware_backdoor->get_instance();
return s_vmware_backdoor;
}
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,6 +76,7 @@ public:
private:
void send_high_bandwidth(VMWareCommand& command);
void get_high_bandwidth(VMWareCommand& command);
VMWareBackdoor();
bool detect_vmmouse();
bool m_vmmouse_absolute { false };
};