summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-03 16:50:08 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-03 16:52:25 +0200
commitc02c9880b61569455eeea1dacaa15d29c33021ea (patch)
tree35580c7110f28edd9ef5b41a043f38619c0f96f1 /Kernel
parent528054d192448f93789fedc3782550b3a80bee27 (diff)
downloadserenity-c02c9880b61569455eeea1dacaa15d29c33021ea.zip
AK: Add Eternal<T> and use it in various places.
This is useful for static locals that never need to be destroyed: Thing& Thing::the() { static Eternal<Thing> the; return the; } The object will be allocated in data segment memory and will never have its destructor invoked.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Net/LoopbackAdapter.cpp7
-rw-r--r--Kernel/Net/LoopbackAdapter.h5
-rw-r--r--Kernel/Net/NetworkTask.cpp8
-rw-r--r--Kernel/StdLib.cpp10
4 files changed, 18 insertions, 12 deletions
diff --git a/Kernel/Net/LoopbackAdapter.cpp b/Kernel/Net/LoopbackAdapter.cpp
index 1593f3b3cf..c21944c5cc 100644
--- a/Kernel/Net/LoopbackAdapter.cpp
+++ b/Kernel/Net/LoopbackAdapter.cpp
@@ -1,11 +1,10 @@
#include <Kernel/Net/LoopbackAdapter.h>
+#include <AK/Eternal.h>
LoopbackAdapter& LoopbackAdapter::the()
{
- static LoopbackAdapter* the;
- if (!the)
- the = new LoopbackAdapter;
- return *the;
+ static Eternal<LoopbackAdapter> the;
+ return the;
}
LoopbackAdapter::LoopbackAdapter()
diff --git a/Kernel/Net/LoopbackAdapter.h b/Kernel/Net/LoopbackAdapter.h
index e22c146330..dad949bc59 100644
--- a/Kernel/Net/LoopbackAdapter.h
+++ b/Kernel/Net/LoopbackAdapter.h
@@ -6,12 +6,11 @@ class LoopbackAdapter final : public NetworkAdapter {
AK_MAKE_ETERNAL
public:
static LoopbackAdapter& the();
-
- virtual ~LoopbackAdapter() override;
+ LoopbackAdapter();
virtual void send_raw(const byte*, int) override;
virtual const char* class_name() const override { return "LoopbackAdapter"; }
private:
- LoopbackAdapter();
+ virtual ~LoopbackAdapter() override;
};
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp
index fbd73671af..4251a22f4a 100644
--- a/Kernel/Net/NetworkTask.cpp
+++ b/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,10 +28,8 @@ static void handle_tcp(const EthernetFrameHeader&, int frame_size);
Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
{
- static Lockable<HashMap<IPv4Address, MACAddress>>* the;
- if (!the)
- the = new Lockable<HashMap<IPv4Address, MACAddress>>;
- return *the;
+ static Eternal<Lockable<HashMap<IPv4Address, MACAddress>>> the;
+ return the;
}
void NetworkTask_main()
diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp
index 20c07f9341..4f25a84455 100644
--- a/Kernel/StdLib.cpp
+++ b/Kernel/StdLib.cpp
@@ -145,4 +145,14 @@ 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?
+}
+
}