diff --git a/AK/Singleton.h b/AK/Singleton.h index 19ebaaff36..a5c19a95e4 100644 --- a/AK/Singleton.h +++ b/AK/Singleton.h @@ -37,19 +37,19 @@ public: Singleton() = default; template - static T* get(T*& obj_var) + static T* get(Atomic& obj_var) { - T* obj = AK::atomic_load(&obj_var, AK::memory_order_acquire); + T* obj = obj_var.load(AK::memory_order_acquire); if (FlatPtr(obj) <= 0x1) { // If this is the first time, see if we get to initialize it #ifdef KERNEL Kernel::ScopedCritical critical; #endif if constexpr (allow_create) { - if (obj == nullptr && AK::atomic_compare_exchange_strong(&obj_var, obj, (T*)0x1, AK::memory_order_acq_rel)) { + if (obj == nullptr && obj_var.compare_exchange_strong(obj, (T*)0x1, AK::memory_order_acq_rel)) { // We're the first one obj = InitFunction(); - AK::atomic_store(&obj_var, obj, AK::memory_order_release); + obj_var.store(obj, AK::memory_order_release); return obj; } } @@ -60,7 +60,7 @@ public: #else // TODO: yield #endif - obj = AK::atomic_load(&obj_var, AK::memory_order_acquire); + obj = obj_var.load(AK::memory_order_acquire); } if constexpr (allow_create) { // We should always return an instance if we allow creating one @@ -98,7 +98,7 @@ public: bool is_initialized() const { - T* obj = AK::atomic_load(&m_obj, AK::memory_order_consume); + T* obj = m_obj.load(AK::MemoryOrder::memory_order_consume); return FlatPtr(obj) > 0x1; } @@ -108,7 +108,6 @@ public: } private: - mutable T* m_obj { nullptr }; // atomic + mutable Atomic m_obj { nullptr }; }; - } diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index c9c4b78b27..87e04188e8 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -112,11 +112,11 @@ struct SignalHandlersInfo { int next_signal_id { 0 }; }; +static AK::Singleton s_signals; template inline SignalHandlersInfo* signals_info() { - static SignalHandlersInfo* s_signals; - return AK::Singleton::get(s_signals); + return s_signals.ptr(); } pid_t EventLoop::s_pid;