Преглед изворни кода

Kernel: Switch LocalSocket to IntrusiveList from InlineLinkedList

Brian Gianforcaro пре 4 година
родитељ
комит
e0da61f9d6
2 измењених фајлова са 13 додато и 13 уклоњено
  1. 7 5
      Kernel/Net/LocalSocket.cpp
  2. 6 8
      Kernel/Net/LocalSocket.h

+ 7 - 5
Kernel/Net/LocalSocket.cpp

@@ -17,9 +17,9 @@
 
 
 namespace Kernel {
 namespace Kernel {
 
 
-static AK::Singleton<Lockable<InlineLinkedList<LocalSocket>>> s_list;
+static AK::Singleton<Lockable<LocalSocket::List>> s_list;
 
 
-Lockable<InlineLinkedList<LocalSocket>>& LocalSocket::all_sockets()
+static Lockable<LocalSocket::List>& all_sockets()
 {
 {
     return *s_list;
     return *s_list;
 }
 }
@@ -69,8 +69,10 @@ KResultOr<SocketPair> LocalSocket::create_connected_pair(int type)
 LocalSocket::LocalSocket(int type)
 LocalSocket::LocalSocket(int type)
     : Socket(AF_LOCAL, type, 0)
     : Socket(AF_LOCAL, type, 0)
 {
 {
-    Locker locker(all_sockets().lock());
-    all_sockets().resource().append(this);
+    {
+        Locker locker(all_sockets().lock());
+        all_sockets().resource().append(*this);
+    }
 
 
     auto current_process = Process::current();
     auto current_process = Process::current();
     m_prebind_uid = current_process->euid();
     m_prebind_uid = current_process->euid();
@@ -90,7 +92,7 @@ LocalSocket::LocalSocket(int type)
 LocalSocket::~LocalSocket()
 LocalSocket::~LocalSocket()
 {
 {
     Locker locker(all_sockets().lock());
     Locker locker(all_sockets().lock());
-    all_sockets().resource().remove(this);
+    all_sockets().resource().remove(*this);
 }
 }
 
 
 void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)
 void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)

+ 6 - 8
Kernel/Net/LocalSocket.h

@@ -6,7 +6,7 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <AK/InlineLinkedList.h>
+#include <AK/IntrusiveList.h>
 #include <Kernel/DoubleBuffer.h>
 #include <Kernel/DoubleBuffer.h>
 #include <Kernel/Net/Socket.h>
 #include <Kernel/Net/Socket.h>
 
 
@@ -19,9 +19,7 @@ struct SocketPair {
     NonnullRefPtr<FileDescription> description2;
     NonnullRefPtr<FileDescription> description2;
 };
 };
 
 
-class LocalSocket final : public Socket
-    , public InlineLinkedListNode<LocalSocket> {
-    friend class InlineLinkedListNode<LocalSocket>;
+class LocalSocket final : public Socket {
 
 
 public:
 public:
     static KResultOr<NonnullRefPtr<Socket>> create(int type);
     static KResultOr<NonnullRefPtr<Socket>> create(int type);
@@ -57,7 +55,6 @@ private:
     virtual const char* class_name() const override { return "LocalSocket"; }
     virtual const char* class_name() const override { return "LocalSocket"; }
     virtual bool is_local() const override { return true; }
     virtual bool is_local() const override { return true; }
     bool has_attached_peer(const FileDescription&) const;
     bool has_attached_peer(const FileDescription&) const;
-    static Lockable<InlineLinkedList<LocalSocket>>& all_sockets();
     DoubleBuffer* receive_buffer_for(FileDescription&);
     DoubleBuffer* receive_buffer_for(FileDescription&);
     DoubleBuffer* send_buffer_for(FileDescription&);
     DoubleBuffer* send_buffer_for(FileDescription&);
     NonnullRefPtrVector<FileDescription>& sendfd_queue_for(const FileDescription&);
     NonnullRefPtrVector<FileDescription>& sendfd_queue_for(const FileDescription&);
@@ -102,9 +99,10 @@ private:
     NonnullRefPtrVector<FileDescription> m_fds_for_client;
     NonnullRefPtrVector<FileDescription> m_fds_for_client;
     NonnullRefPtrVector<FileDescription> m_fds_for_server;
     NonnullRefPtrVector<FileDescription> m_fds_for_server;
 
 
-    // for InlineLinkedList
-    LocalSocket* m_prev { nullptr };
-    LocalSocket* m_next { nullptr };
+    IntrusiveListNode<LocalSocket> m_list_node;
+
+public:
+    using List = IntrusiveList<LocalSocket, RawPtr<LocalSocket>, &LocalSocket::m_list_node>;
 };
 };
 
 
 }
 }