mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 19:15:06 +00:00
AK: Revert Eternal<T> for now since it doesn't work as intended.
This commit is contained in:
parent
fb6dc5350d
commit
bcc00857a4
14 changed files with 51 additions and 67 deletions
30
AK/Eternal.h
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;
|
|
|
@ -4,7 +4,6 @@
|
||||||
#define AK_MAKE_ETERNAL \
|
#define AK_MAKE_ETERNAL \
|
||||||
public: \
|
public: \
|
||||||
void* operator new(size_t size) { return kmalloc_eternal(size); } \
|
void* operator new(size_t size) { return kmalloc_eternal(size); } \
|
||||||
void* operator new(size_t, void* ptr) { return ptr; } \
|
|
||||||
private:
|
private:
|
||||||
#else
|
#else
|
||||||
#define AK_MAKE_ETERNAL
|
#define AK_MAKE_ETERNAL
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include <Kernel/Net/LoopbackAdapter.h>
|
#include <Kernel/Net/LoopbackAdapter.h>
|
||||||
#include <AK/Eternal.h>
|
|
||||||
|
|
||||||
LoopbackAdapter& LoopbackAdapter::the()
|
LoopbackAdapter& LoopbackAdapter::the()
|
||||||
{
|
{
|
||||||
static Eternal<LoopbackAdapter> the;
|
static LoopbackAdapter* the;
|
||||||
return the;
|
if (!the)
|
||||||
|
the = new LoopbackAdapter;
|
||||||
|
return *the;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoopbackAdapter::LoopbackAdapter()
|
LoopbackAdapter::LoopbackAdapter()
|
||||||
|
|
|
@ -6,11 +6,12 @@ class LoopbackAdapter final : public NetworkAdapter {
|
||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
public:
|
public:
|
||||||
static LoopbackAdapter& the();
|
static LoopbackAdapter& the();
|
||||||
LoopbackAdapter();
|
|
||||||
|
virtual ~LoopbackAdapter() override;
|
||||||
|
|
||||||
virtual void send_raw(const byte*, int) override;
|
virtual void send_raw(const byte*, int) override;
|
||||||
virtual const char* class_name() const override { return "LoopbackAdapter"; }
|
virtual const char* class_name() const override { return "LoopbackAdapter"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~LoopbackAdapter() override;
|
LoopbackAdapter();
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <Kernel/Net/EtherType.h>
|
#include <Kernel/Net/EtherType.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
#include <AK/Eternal.h>
|
|
||||||
|
|
||||||
//#define ETHERNET_DEBUG
|
//#define ETHERNET_DEBUG
|
||||||
#define IPV4_DEBUG
|
#define IPV4_DEBUG
|
||||||
|
@ -28,8 +28,10 @@ static void handle_tcp(const EthernetFrameHeader&, int frame_size);
|
||||||
|
|
||||||
Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
|
Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
|
||||||
{
|
{
|
||||||
static Eternal<Lockable<HashMap<IPv4Address, MACAddress>>> the;
|
static Lockable<HashMap<IPv4Address, MACAddress>>* the;
|
||||||
return the;
|
if (!the)
|
||||||
|
the = new Lockable<HashMap<IPv4Address, MACAddress>>;
|
||||||
|
return *the;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkTask_main()
|
void NetworkTask_main()
|
||||||
|
|
|
@ -145,14 +145,4 @@ int memcmp(const void* v1, const void* v2, size_t n)
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __cxa_guard_acquire(void*)
|
|
||||||
{
|
|
||||||
// FIXME: Lock somehow?
|
|
||||||
}
|
|
||||||
|
|
||||||
void __cxa_guard_release(void*)
|
|
||||||
{
|
|
||||||
// FIXME: Unlock somehow?
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,19 @@
|
||||||
#include <WindowServer/WSAPITypes.h>
|
#include <WindowServer/WSAPITypes.h>
|
||||||
#include <LibC/SharedBuffer.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;
|
WSAPI_ClientMessage request;
|
||||||
request.type = WSAPI_ClientMessage::Type::GetClipboardContents;
|
request.type = WSAPI_ClientMessage::Type::GetClipboardContents;
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
class GClipboard {
|
class GClipboard {
|
||||||
public:
|
public:
|
||||||
static String data();
|
static GClipboard& the();
|
||||||
static void set_data(const String&);
|
|
||||||
|
String data() const;
|
||||||
|
void set_data(const String&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
GClipboard();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#include <LibGUI/GDesktop.h>
|
#include <LibGUI/GDesktop.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GEventLoop.h>
|
||||||
#include <AK/Eternal.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
GDesktop& GDesktop::the()
|
GDesktop& GDesktop::the()
|
||||||
{
|
{
|
||||||
static Eternal<GDesktop> the;
|
static GDesktop* the;
|
||||||
return the;
|
if (!the)
|
||||||
|
the = new GDesktop;
|
||||||
|
return *the;
|
||||||
}
|
}
|
||||||
|
|
||||||
GDesktop::GDesktop()
|
GDesktop::GDesktop()
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
#include <LibGUI/GFontDatabase.h>
|
#include <LibGUI/GFontDatabase.h>
|
||||||
#include <SharedGraphics/Font.h>
|
#include <SharedGraphics/Font.h>
|
||||||
#include <AK/Eternal.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static GFontDatabase* s_the;
|
||||||
|
|
||||||
GFontDatabase& GFontDatabase::the()
|
GFontDatabase& GFontDatabase::the()
|
||||||
{
|
{
|
||||||
static Eternal<GFontDatabase> the;
|
if (!s_the)
|
||||||
return the;
|
s_the = new GFontDatabase;
|
||||||
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
GFontDatabase::GFontDatabase()
|
GFontDatabase::GFontDatabase()
|
||||||
|
|
|
@ -9,13 +9,13 @@ class Font;
|
||||||
class GFontDatabase {
|
class GFontDatabase {
|
||||||
public:
|
public:
|
||||||
static GFontDatabase& the();
|
static GFontDatabase& the();
|
||||||
GFontDatabase();
|
|
||||||
|
|
||||||
RetainPtr<Font> get_by_name(const String&);
|
RetainPtr<Font> get_by_name(const String&);
|
||||||
void for_each_font(Function<void(const String&)>);
|
void for_each_font(Function<void(const String&)>);
|
||||||
void for_each_fixed_width_font(Function<void(const String&)>);
|
void for_each_fixed_width_font(Function<void(const String&)>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GFontDatabase();
|
||||||
~GFontDatabase();
|
~GFontDatabase();
|
||||||
|
|
||||||
struct Metadata {
|
struct Metadata {
|
||||||
|
|
|
@ -785,7 +785,7 @@ void GTextEditor::cut()
|
||||||
{
|
{
|
||||||
auto selected_text = this->selected_text();
|
auto selected_text = this->selected_text();
|
||||||
printf("Cut: \"%s\"\n", selected_text.characters());
|
printf("Cut: \"%s\"\n", selected_text.characters());
|
||||||
GClipboard::set_data(selected_text);
|
GClipboard::the().set_data(selected_text);
|
||||||
delete_selection();
|
delete_selection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,12 +793,12 @@ void GTextEditor::copy()
|
||||||
{
|
{
|
||||||
auto selected_text = this->selected_text();
|
auto selected_text = this->selected_text();
|
||||||
printf("Copy: \"%s\"\n", selected_text.characters());
|
printf("Copy: \"%s\"\n", selected_text.characters());
|
||||||
GClipboard::set_data(selected_text);
|
GClipboard::the().set_data(selected_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::paste()
|
void GTextEditor::paste()
|
||||||
{
|
{
|
||||||
auto paste_text = GClipboard::data();
|
auto paste_text = GClipboard::the().data();
|
||||||
printf("Paste: \"%s\"\n", paste_text.characters());
|
printf("Paste: \"%s\"\n", paste_text.characters());
|
||||||
insert_at_cursor_or_replace_selection(paste_text);
|
insert_at_cursor_or_replace_selection(paste_text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include <WindowServer/WSClipboard.h>
|
#include <WindowServer/WSClipboard.h>
|
||||||
#include <AK/Eternal.h>
|
|
||||||
|
|
||||||
WSClipboard& WSClipboard::the()
|
WSClipboard& WSClipboard::the()
|
||||||
{
|
{
|
||||||
static Eternal<WSClipboard> the;
|
static WSClipboard* s_the;
|
||||||
return the;
|
if (!s_the)
|
||||||
|
s_the = new WSClipboard;
|
||||||
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
WSClipboard::WSClipboard()
|
WSClipboard::WSClipboard()
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
class WSClipboard final : public WSMessageReceiver {
|
class WSClipboard final : public WSMessageReceiver {
|
||||||
public:
|
public:
|
||||||
static WSClipboard& the();
|
static WSClipboard& the();
|
||||||
WSClipboard();
|
virtual ~WSClipboard() override;
|
||||||
|
|
||||||
bool has_data() const
|
bool has_data() const
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ public:
|
||||||
void set_data(Retained<SharedBuffer>&&, int contents_size);
|
void set_data(Retained<SharedBuffer>&&, int contents_size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~WSClipboard() override;
|
WSClipboard();
|
||||||
virtual void on_message(const WSMessage&) override;
|
virtual void on_message(const WSMessage&) override;
|
||||||
|
|
||||||
RetainPtr<SharedBuffer> m_shared_buffer;
|
RetainPtr<SharedBuffer> m_shared_buffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue