diff --git a/AK/FlyString.cpp b/AK/FlyString.cpp index 637ef9c596..e6e369c3f6 100644 --- a/AK/FlyString.cpp +++ b/AK/FlyString.cpp @@ -48,7 +48,7 @@ struct FlyStringImplTraits : public AK::Traits { } }; -static AK::Singleton> s_table; +static auto s_table = make_singleton>(); static HashTable& fly_impls() { diff --git a/AK/Singleton.h b/AK/Singleton.h index 0abfa2b277..57962e3176 100644 --- a/AK/Singleton.h +++ b/AK/Singleton.h @@ -39,18 +39,9 @@ namespace AK { -template -struct SingletonInstanceCreator { - static T* create() - { - return new T(); - } -}; - -template::create> +template class Singleton { AK_MAKE_NONCOPYABLE(Singleton); - AK_MAKE_NONMOVABLE(Singleton); public: Singleton() = default; @@ -119,4 +110,18 @@ private: mutable T* m_obj { nullptr }; // atomic }; +template +struct SingletonInstanceCreator { + static T* create() + { + return new T(); + } +}; + +template +inline Singleton::create> make_singleton() +{ + return Singleton::create>(); +} + } diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp index 3155dd6bdc..8b50e7aeec 100644 --- a/Kernel/CommandLine.cpp +++ b/Kernel/CommandLine.cpp @@ -38,7 +38,6 @@ const CommandLine& kernel_command_line() void CommandLine::initialize(const String& string) { - ASSERT(!s_the); s_the = new CommandLine(string); } @@ -46,7 +45,7 @@ CommandLine::CommandLine(const String& string) : m_string(string) { s_the = this; -klog() << "CommandLine: " << string; + for (auto str : m_string.split(' ')) { if (str == "") { continue; diff --git a/Kernel/Console.cpp b/Kernel/Console.cpp index e511a2d876..c3fa023521 100644 --- a/Kernel/Console.cpp +++ b/Kernel/Console.cpp @@ -33,7 +33,7 @@ // Bytes output to 0xE9 end up on the Bochs console. It's very handy. #define CONSOLE_OUT_TO_E9 -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); static Kernel::SpinLock g_console_lock; void Console::initialize() diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index c9f1732260..ee822dac29 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -57,7 +57,7 @@ namespace Kernel { #define VBE_DISPI_ENABLED 0x01 #define VBE_DISPI_LFB_ENABLED 0x40 -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); void BXVGADevice::initialize() { diff --git a/Kernel/Devices/Device.cpp b/Kernel/Devices/Device.cpp index 934c587ba6..e08a0ac6f5 100644 --- a/Kernel/Devices/Device.cpp +++ b/Kernel/Devices/Device.cpp @@ -31,7 +31,7 @@ namespace Kernel { -static AK::Singleton> s_all_devices; +static auto s_all_devices = AK::make_singleton>(); HashMap& Device::all_devices() { diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index 531c488a9f..192b54c721 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -336,7 +336,7 @@ void KeyboardDevice::handle_irq(const RegisterState&) } } -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); void KeyboardDevice::initialize() { diff --git a/Kernel/Devices/NullDevice.cpp b/Kernel/Devices/NullDevice.cpp index 5c6a5c59c5..e879759d1d 100644 --- a/Kernel/Devices/NullDevice.cpp +++ b/Kernel/Devices/NullDevice.cpp @@ -30,7 +30,7 @@ namespace Kernel { -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); void NullDevice::initialize() { diff --git a/Kernel/Devices/PATAChannel.cpp b/Kernel/Devices/PATAChannel.cpp index 172816ea1b..553acd412b 100644 --- a/Kernel/Devices/PATAChannel.cpp +++ b/Kernel/Devices/PATAChannel.cpp @@ -108,7 +108,7 @@ namespace Kernel { #define PCI_Mass_Storage_Class 0x1 #define PCI_IDE_Controller_Subclass 0x1 -static AK::Singleton s_pata_lock; +static auto s_pata_lock = AK::make_singleton(); static Lock& s_lock() { diff --git a/Kernel/Devices/PS2MouseDevice.cpp b/Kernel/Devices/PS2MouseDevice.cpp index 0dbb7d8bba..913b6d5c73 100644 --- a/Kernel/Devices/PS2MouseDevice.cpp +++ b/Kernel/Devices/PS2MouseDevice.cpp @@ -57,7 +57,7 @@ namespace Kernel { //#define PS2MOUSE_DEBUG -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); PS2MouseDevice::PS2MouseDevice() : IRQHandler(IRQ_MOUSE) diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index 8d7406f39b..8e5611a836 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -77,7 +77,7 @@ void SB16::set_sample_rate(uint16_t hz) dsp_write((u8)hz); } -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); SB16::SB16() : IRQHandler(SB16_DEFAULT_IRQ) diff --git a/Kernel/Devices/VMWareBackdoor.cpp b/Kernel/Devices/VMWareBackdoor.cpp index d1686da6c5..04499e522a 100644 --- a/Kernel/Devices/VMWareBackdoor.cpp +++ b/Kernel/Devices/VMWareBackdoor.cpp @@ -111,7 +111,7 @@ private: OwnPtr m_backdoor; }; -static AK::Singleton s_vmware_backdoor; +static auto s_vmware_backdoor = AK::make_singleton(); VMWareBackdoor* VMWareBackdoor::the() { diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index 7ee4d28aa0..2849b8f58b 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS.cpp @@ -46,7 +46,7 @@ DevPtsFS::~DevPtsFS() { } -static AK::Singleton> s_ptys; +static auto s_ptys = AK::make_singleton>(); bool DevPtsFS::initialize() { diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index 3b22a45c6a..52daa26f50 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -38,7 +38,7 @@ namespace Kernel { -static AK::Singleton>> s_table; +static auto s_table = AK::make_singleton>>(); static Lockable>& all_fifos() { diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp index 49f1b284f3..2a96fb6e6c 100644 --- a/Kernel/FileSystem/FileSystem.cpp +++ b/Kernel/FileSystem/FileSystem.cpp @@ -38,7 +38,7 @@ namespace Kernel { static u32 s_lastFileSystemID; -static AK::Singleton> s_fs_map; +static auto s_fs_map = AK::make_singleton>(); static HashMap& all_fses() { diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index e78f87bf59..edfba2eac9 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -39,7 +39,7 @@ namespace Kernel { static SpinLock s_all_inodes_lock; -static AK::Singleton> s_list; +static auto s_list = AK::make_singleton>(); InlineLinkedList& Inode::all_with_lock() { diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index ea06d462c3..9ea1a2d5c7 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -41,7 +41,7 @@ namespace Kernel { -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase? static constexpr int root_mount_flags = MS_NODEV | MS_NOSUID | MS_RDONLY; diff --git a/Kernel/Interrupts/APIC.cpp b/Kernel/Interrupts/APIC.cpp index 23af86d11f..d92416ab9c 100644 --- a/Kernel/Interrupts/APIC.cpp +++ b/Kernel/Interrupts/APIC.cpp @@ -69,7 +69,7 @@ namespace Kernel { -static AK::Singleton s_apic; +static auto s_apic = AK::make_singleton(); class APICIPIInterruptHandler final : public GenericInterruptHandler { public: diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 09e56114ea..2861f1a90e 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -46,7 +46,7 @@ namespace Kernel { -static AK::Singleton>> s_table; +static auto s_table = AK::make_singleton>>(); Lockable>& IPv4Socket::all_sockets() { diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index ca7863bd9c..6750f93403 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -38,7 +38,7 @@ namespace Kernel { -static AK::Singleton>> s_list; +static auto s_list = AK::make_singleton>>(); Lockable>& LocalSocket::all_sockets() { diff --git a/Kernel/Net/LoopbackAdapter.cpp b/Kernel/Net/LoopbackAdapter.cpp index 5728b68b34..6b858c9549 100644 --- a/Kernel/Net/LoopbackAdapter.cpp +++ b/Kernel/Net/LoopbackAdapter.cpp @@ -29,7 +29,7 @@ namespace Kernel { -static AK::Singleton s_loopback; +static auto s_loopback = AK::make_singleton(); LoopbackAdapter& LoopbackAdapter::the() { diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index 4cfdd1cd43..898c95d710 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -38,7 +38,7 @@ namespace Kernel { -static AK::Singleton>> s_table; +static auto s_table = AK::make_singleton>>(); static Lockable>& all_adapters() { diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 281f06ceb4..d73704cccf 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -34,7 +34,7 @@ namespace Kernel { -static AK::Singleton>> s_arp_table; +static auto s_arp_table = AK::make_singleton>>(); Lockable>& arp_table() { diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index b7b615c951..af7f5bb9f4 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -63,14 +63,14 @@ void TCPSocket::set_state(State new_state) } } -static AK::Singleton>>> s_socket_closing; +static auto s_socket_closing = AK::make_singleton>>>(); Lockable>>& TCPSocket::closing_sockets() { return *s_socket_closing; } -static AK::Singleton>> s_socket_tuples; +static auto s_socket_tuples = AK::make_singleton>>(); Lockable>& TCPSocket::sockets_by_tuple() { diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index c770a4e184..27901a2e82 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -42,7 +42,7 @@ void UDPSocket::for_each(Function callback) callback(*it.value); } -static AK::Singleton>> s_map; +static auto s_map = AK::make_singleton>>(); Lockable>& UDPSocket::sockets_by_port() { diff --git a/Kernel/Random.cpp b/Kernel/Random.cpp index d8fe3469cd..472f4519c5 100644 --- a/Kernel/Random.cpp +++ b/Kernel/Random.cpp @@ -33,7 +33,7 @@ namespace Kernel { -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); KernelRng& KernelRng::the() { diff --git a/Kernel/SharedBuffer.cpp b/Kernel/SharedBuffer.cpp index 3a9fd4e42d..a5186773a4 100644 --- a/Kernel/SharedBuffer.cpp +++ b/Kernel/SharedBuffer.cpp @@ -30,7 +30,7 @@ namespace Kernel { -static AK::Singleton>>> s_map; +static auto s_map = AK::make_singleton>>>(); Lockable>>& shared_buffers() { diff --git a/Kernel/TTY/PTYMultiplexer.cpp b/Kernel/TTY/PTYMultiplexer.cpp index e4b7394a9b..c44a565ae9 100644 --- a/Kernel/TTY/PTYMultiplexer.cpp +++ b/Kernel/TTY/PTYMultiplexer.cpp @@ -36,7 +36,7 @@ namespace Kernel { static const unsigned s_max_pty_pairs = 8; -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); PTYMultiplexer& PTYMultiplexer::the() { diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp index 5fb1b4c52a..ff37fa33aa 100644 --- a/Kernel/Time/TimeManagement.cpp +++ b/Kernel/Time/TimeManagement.cpp @@ -40,7 +40,7 @@ namespace Kernel { -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); TimeManagement& TimeManagement::the() { diff --git a/Kernel/TimerQueue.cpp b/Kernel/TimerQueue.cpp index b3f40c69c3..d12e4ecd52 100644 --- a/Kernel/TimerQueue.cpp +++ b/Kernel/TimerQueue.cpp @@ -34,7 +34,7 @@ namespace Kernel { -static AK::Singleton s_the; +static auto s_the = AK::make_singleton(); TimerQueue& TimerQueue::the() { diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp index f126ea95a5..573caa28db 100644 --- a/Kernel/VM/PageDirectory.cpp +++ b/Kernel/VM/PageDirectory.cpp @@ -38,7 +38,7 @@ static const FlatPtr userspace_range_base = 0x00800000; static const FlatPtr userspace_range_ceiling = 0xbe000000; static const FlatPtr kernelspace_range_base = 0xc0800000; -static AK::Singleton> s_cr3_map; +static auto s_cr3_map = AK::make_singleton>(); static HashMap& cr3_map() {