Преглед на файлове

AK: Revert Eternal<T> for now since it doesn't work as intended.

Andreas Kling преди 6 години
родител
ревизия
bcc00857a4

+ 0 - 30
AK/Eternal.h

@@ -1,30 +0,0 @@
-#pragma once
-
-#include <AK/StdLibExtras.h>
-
-namespace AK {
-
-template<typename T>
-class Eternal {
-public:
-    template<typename... Args>
-    Eternal(Args&&... args)
-    {
-        new (m_slot) T(forward<Args>(args)...);
-    }
-
-    T& get() { return *reinterpret_cast<T*>(&m_slot); }
-    const T& get() const { return *reinterpret_cast<T*>(&m_slot); }
-    T* operator->() { return &get(); }
-    const T* operator->() const { return &get(); }
-    operator T&() { return get(); }
-    operator const T&() const { return get(); }
-
-
-private:
-    [[gnu::aligned(alignof(T))]] char m_slot[sizeof(T)];
-};
-
-}
-
-using AK::Eternal;

+ 0 - 1
AK/kmalloc.h

@@ -4,7 +4,6 @@
 #define AK_MAKE_ETERNAL \
 public: \
     void* operator new(size_t size) { return kmalloc_eternal(size); } \
-    void* operator new(size_t, void* ptr) { return ptr; } \
 private:
 #else
 #define AK_MAKE_ETERNAL

+ 4 - 3
Kernel/Net/LoopbackAdapter.cpp

@@ -1,10 +1,11 @@
 #include <Kernel/Net/LoopbackAdapter.h>
-#include <AK/Eternal.h>
 
 LoopbackAdapter& LoopbackAdapter::the()
 {
-    static Eternal<LoopbackAdapter> the;
-    return the;
+    static LoopbackAdapter* the;
+    if (!the)
+        the = new LoopbackAdapter;
+    return *the;
 }
 
 LoopbackAdapter::LoopbackAdapter()

+ 3 - 2
Kernel/Net/LoopbackAdapter.h

@@ -6,11 +6,12 @@ class LoopbackAdapter final : public NetworkAdapter {
     AK_MAKE_ETERNAL
 public:
     static LoopbackAdapter& the();
-    LoopbackAdapter();
+
+    virtual ~LoopbackAdapter() override;
 
     virtual void send_raw(const byte*, int) override;
     virtual const char* class_name() const override { return "LoopbackAdapter"; }
 
 private:
-    virtual ~LoopbackAdapter() override;
+    LoopbackAdapter();
 };

+ 5 - 3
Kernel/Net/NetworkTask.cpp

@@ -12,7 +12,7 @@
 #include <Kernel/Process.h>
 #include <Kernel/Net/EtherType.h>
 #include <Kernel/Lock.h>
-#include <AK/Eternal.h>
+
 
 //#define ETHERNET_DEBUG
 #define IPV4_DEBUG
@@ -28,8 +28,10 @@ static void handle_tcp(const EthernetFrameHeader&, int frame_size);
 
 Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
 {
-    static Eternal<Lockable<HashMap<IPv4Address, MACAddress>>> the;
-    return the;
+    static Lockable<HashMap<IPv4Address, MACAddress>>* the;
+    if (!the)
+        the = new Lockable<HashMap<IPv4Address, MACAddress>>;
+    return *the;
 }
 
 void NetworkTask_main()

+ 0 - 10
Kernel/StdLib.cpp

@@ -145,14 +145,4 @@ int memcmp(const void* v1, const void* v2, size_t n)
     ASSERT_NOT_REACHED();
 }
 
-void __cxa_guard_acquire(void*)
-{
-    // FIXME: Lock somehow?
-}
-
-void __cxa_guard_release(void*)
-{
-    // FIXME: Unlock somehow?
-}
-
 }

+ 13 - 1
LibGUI/GClipboard.cpp

@@ -3,7 +3,19 @@
 #include <WindowServer/WSAPITypes.h>
 #include <LibC/SharedBuffer.h>
 
-String GClipboard::data()
+GClipboard& GClipboard::the()
+{
+    static GClipboard* s_the;
+    if (!s_the)
+        s_the = new GClipboard;
+    return *s_the;
+}
+
+GClipboard::GClipboard()
+{
+}
+
+String GClipboard::data() const
 {
     WSAPI_ClientMessage request;
     request.type = WSAPI_ClientMessage::Type::GetClipboardContents;

+ 7 - 2
LibGUI/GClipboard.h

@@ -4,6 +4,11 @@
 
 class GClipboard {
 public:
-    static String data();
-    static void set_data(const String&);
+    static GClipboard& the();
+
+    String data() const;
+    void set_data(const String&);
+
+private:
+    GClipboard();
 };

+ 4 - 3
LibGUI/GDesktop.cpp

@@ -1,13 +1,14 @@
 #include <LibGUI/GDesktop.h>
 #include <LibGUI/GEventLoop.h>
-#include <AK/Eternal.h>
 #include <string.h>
 #include <unistd.h>
 
 GDesktop& GDesktop::the()
 {
-    static Eternal<GDesktop> the;
-    return the;
+    static GDesktop* the;
+    if (!the)
+        the = new GDesktop;
+    return *the;
 }
 
 GDesktop::GDesktop()

+ 5 - 3
LibGUI/GFontDatabase.cpp

@@ -1,14 +1,16 @@
 #include <LibGUI/GFontDatabase.h>
 #include <SharedGraphics/Font.h>
-#include <AK/Eternal.h>
 #include <dirent.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+static GFontDatabase* s_the;
+
 GFontDatabase& GFontDatabase::the()
 {
-    static Eternal<GFontDatabase> the;
-    return the;
+    if (!s_the)
+        s_the = new GFontDatabase;
+    return *s_the;
 }
 
 GFontDatabase::GFontDatabase()

+ 1 - 1
LibGUI/GFontDatabase.h

@@ -9,13 +9,13 @@ class Font;
 class GFontDatabase {
 public:
     static GFontDatabase& the();
-    GFontDatabase();
 
     RetainPtr<Font> get_by_name(const String&);
     void for_each_font(Function<void(const String&)>);
     void for_each_fixed_width_font(Function<void(const String&)>);
 
 private:
+    GFontDatabase();
     ~GFontDatabase();
 
     struct Metadata {

+ 3 - 3
LibGUI/GTextEditor.cpp

@@ -785,7 +785,7 @@ void GTextEditor::cut()
 {
     auto selected_text = this->selected_text();
     printf("Cut: \"%s\"\n", selected_text.characters());
-    GClipboard::set_data(selected_text);
+    GClipboard::the().set_data(selected_text);
     delete_selection();
 }
 
@@ -793,12 +793,12 @@ void GTextEditor::copy()
 {
     auto selected_text = this->selected_text();
     printf("Copy: \"%s\"\n", selected_text.characters());
-    GClipboard::set_data(selected_text);
+    GClipboard::the().set_data(selected_text);
 }
 
 void GTextEditor::paste()
 {
-    auto paste_text = GClipboard::data();
+    auto paste_text = GClipboard::the().data();
     printf("Paste: \"%s\"\n", paste_text.characters());
     insert_at_cursor_or_replace_selection(paste_text);
 }

+ 4 - 3
Servers/WindowServer/WSClipboard.cpp

@@ -1,10 +1,11 @@
 #include <WindowServer/WSClipboard.h>
-#include <AK/Eternal.h>
 
 WSClipboard& WSClipboard::the()
 {
-    static Eternal<WSClipboard> the;
-    return the;
+    static WSClipboard* s_the;
+    if (!s_the)
+        s_the = new WSClipboard;
+    return *s_the;
 }
 
 WSClipboard::WSClipboard()

+ 2 - 2
Servers/WindowServer/WSClipboard.h

@@ -7,7 +7,7 @@
 class WSClipboard final : public WSMessageReceiver {
 public:
     static WSClipboard& the();
-    WSClipboard();
+    virtual ~WSClipboard() override;
 
     bool has_data() const
     {
@@ -21,7 +21,7 @@ public:
     void set_data(Retained<SharedBuffer>&&, int contents_size);
 
 private:
-    virtual ~WSClipboard() override;
+    WSClipboard();
     virtual void on_message(const WSMessage&) override;
 
     RetainPtr<SharedBuffer> m_shared_buffer;