diff options
author | Tom <tomut@yahoo.com> | 2020-08-20 09:36:06 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-21 11:47:35 +0200 |
commit | f48feae0b2a300992479abf0b2ded85e45ac6045 (patch) | |
tree | d0b01169a60261135ee15a8d4a6abd01785a7bec /Kernel/Net | |
parent | 527c8047fe0a08ade2e17fd096ad9b4ebc103ec5 (diff) | |
download | serenity-f48feae0b2a300992479abf0b2ded85e45ac6045.zip |
Kernel: Switch singletons to use new Singleton class
Fixes #3226
Diffstat (limited to 'Kernel/Net')
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 6 | ||||
-rw-r--r-- | Kernel/Net/LocalSocket.cpp | 6 | ||||
-rw-r--r-- | Kernel/Net/LoopbackAdapter.cpp | 8 | ||||
-rw-r--r-- | Kernel/Net/LoopbackAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 8 | ||||
-rw-r--r-- | Kernel/Net/Routing.cpp | 8 | ||||
-rw-r--r-- | Kernel/Net/TCPSocket.cpp | 6 | ||||
-rw-r--r-- | Kernel/Net/UDPSocket.cpp | 6 |
8 files changed, 25 insertions, 27 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 6e4fcfcbfa..8286e5a2e8 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -25,6 +25,7 @@ */ #include <AK/StringBuilder.h> +#include <Kernel/Singleton.h> #include <Kernel/FileSystem/FileDescription.h> #include <Kernel/Net/ARP.h> #include <Kernel/Net/ICMP.h> @@ -45,11 +46,10 @@ namespace Kernel { +static auto s_table = make_singleton<Lockable<HashTable<IPv4Socket*>>>(); + Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets() { - static Lockable<HashTable<IPv4Socket*>>* s_table; - if (!s_table) - s_table = new Lockable<HashTable<IPv4Socket*>>; return *s_table; } diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 92f333ad23..c703cc8ac6 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -29,6 +29,7 @@ #include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/Net/LocalSocket.h> #include <Kernel/Process.h> +#include <Kernel/Singleton.h> #include <Kernel/StdLib.h> #include <Kernel/UnixTypes.h> #include <LibC/errno_numbers.h> @@ -37,11 +38,10 @@ namespace Kernel { +static auto s_list = make_singleton<Lockable<InlineLinkedList<LocalSocket>>>(); + Lockable<InlineLinkedList<LocalSocket>>& LocalSocket::all_sockets() { - static Lockable<InlineLinkedList<LocalSocket>>* s_list; - if (!s_list) - s_list = new Lockable<InlineLinkedList<LocalSocket>>(); return *s_list; } diff --git a/Kernel/Net/LoopbackAdapter.cpp b/Kernel/Net/LoopbackAdapter.cpp index e42ee66a5e..27faa8bfad 100644 --- a/Kernel/Net/LoopbackAdapter.cpp +++ b/Kernel/Net/LoopbackAdapter.cpp @@ -25,15 +25,15 @@ */ #include <Kernel/Net/LoopbackAdapter.h> +#include <Kernel/Singleton.h> namespace Kernel { +static auto s_loopback = make_singleton<LoopbackAdapter>(); + LoopbackAdapter& LoopbackAdapter::the() { - static LoopbackAdapter* the; - if (!the) - the = new LoopbackAdapter; - return *the; + return *s_loopback; } LoopbackAdapter::LoopbackAdapter() diff --git a/Kernel/Net/LoopbackAdapter.h b/Kernel/Net/LoopbackAdapter.h index b87bb5003f..cebedfe7a3 100644 --- a/Kernel/Net/LoopbackAdapter.h +++ b/Kernel/Net/LoopbackAdapter.h @@ -33,15 +33,13 @@ namespace Kernel { class LoopbackAdapter final : public NetworkAdapter { AK_MAKE_ETERNAL public: + LoopbackAdapter(); static LoopbackAdapter& the(); virtual ~LoopbackAdapter() override; virtual void send_raw(ReadonlyBytes) override; virtual const char* class_name() const override { return "LoopbackAdapter"; } - -private: - LoopbackAdapter(); }; } diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index 7efa7b353e..936bf9a2e7 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -33,16 +33,16 @@ #include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/NetworkAdapter.h> #include <Kernel/Random.h> +#include <Kernel/Singleton.h> #include <Kernel/StdLib.h> namespace Kernel { +static auto s_table = make_singleton<Lockable<HashTable<NetworkAdapter*>>>(); + static Lockable<HashTable<NetworkAdapter*>>& all_adapters() { - static Lockable<HashTable<NetworkAdapter*>>* table; - if (!table) - table = new Lockable<HashTable<NetworkAdapter*>>; - return *table; + return *s_table; } void NetworkAdapter::for_each(Function<void(NetworkAdapter&)> callback) diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index b2b9786a2e..5f72ab1166 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -28,17 +28,17 @@ #include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/Routing.h> #include <Kernel/Thread.h> +#include <Kernel/Singleton.h> //#define ROUTING_DEBUG namespace Kernel { +static auto s_arp_table = make_singleton<Lockable<HashMap<IPv4Address, MACAddress>>>(); + Lockable<HashMap<IPv4Address, MACAddress>>& arp_table() { - static Lockable<HashMap<IPv4Address, MACAddress>>* the; - if (!the) - the = new Lockable<HashMap<IPv4Address, MACAddress>>; - return *the; + return *s_arp_table; } bool RoutingDecision::is_zero() const diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index cafe48370e..7b8c12a49c 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -33,6 +33,7 @@ #include <Kernel/Net/TCPSocket.h> #include <Kernel/Process.h> #include <Kernel/Random.h> +#include <Kernel/Singleton.h> //#define TCP_SOCKET_DEBUG @@ -70,11 +71,10 @@ Lockable<HashMap<IPv4SocketTuple, RefPtr<TCPSocket>>>& TCPSocket::closing_socket return *s_map; } +static auto s_map = make_singleton<Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>>(); + Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>& TCPSocket::sockets_by_tuple() { - static Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>* s_map; - if (!s_map) - s_map = new Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>; return *s_map; } diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index 65091a37c1..ad57696675 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -31,6 +31,7 @@ #include <Kernel/Net/UDPSocket.h> #include <Kernel/Process.h> #include <Kernel/Random.h> +#include <Kernel/Singleton.h> namespace Kernel { @@ -41,11 +42,10 @@ void UDPSocket::for_each(Function<void(const UDPSocket&)> callback) callback(*it.value); } +static auto s_map = make_singleton<Lockable<HashMap<u16, UDPSocket*>>>(); + Lockable<HashMap<u16, UDPSocket*>>& UDPSocket::sockets_by_port() { - static Lockable<HashMap<u16, UDPSocket*>>* s_map; - if (!s_map) - s_map = new Lockable<HashMap<u16, UDPSocket*>>; return *s_map; } |