Truly independent web browser
LibCore+Compositor+WebWorker+UI: Use ThreadID for event loop lookups
Zaggy10248b52fa1b56d6
diff --git a/Libraries/LibCore/EventLoopImplementationUnix.cpp b/Libraries/LibCore/EventLoopImplementationUnix.cppindex c12c37be6bd..c22ee79d7dd 100644--- a/Libraries/LibCore/EventLoopImplementationUnix.cpp+++ b/Libraries/LibCore/EventLoopImplementationUnix.cpp@@ -12,6 +12,7 @@#include <AK/RWLock.h>#include <AK/Singleton.h>#include <AK/TemporaryChange.h>+#include <AK/ThreadID.h>#include <AK/Time.h>#include <AK/WeakPtr.h>#include <AK/kmalloc.h>@@ -46,7 +47,7 @@ static void destroy_thread_data(void*);static auto& thread_data(){- static NeverDestroyed<HashMap<pthread_t, ThreadData*>> thread_data;+ static NeverDestroyed<HashMap<AK::ThreadID, ThreadData*>> thread_data;return *thread_data;}@@ -123,7 +124,7 @@ public:AK::Duration interval;bool should_reload { false };WeakPtr<EventReceiver> owner;- pthread_t owner_thread { 0 };+ AK::ThreadID owner_thread;Atomic<bool> is_being_deleted { false };};@@ -147,7 +148,7 @@ struct ThreadData {return *data;}- static ThreadData* for_thread(pthread_t thread_id)+ static ThreadData* for_thread(AK::ThreadID thread_id){// NOTE: thread_data_lock() is supposed to be held by the caller.return thread_data().get(thread_id).value_or(nullptr);@@ -155,7 +156,7 @@ struct ThreadData {ThreadData(){- thread_id = pthread_self();+ thread_id = AK::ThreadID::current();auto result = Core::System::pipe2(O_CLOEXEC | O_NONBLOCK);if (result.is_error()) {@@ -195,7 +196,7 @@ struct ThreadData {Array<int, 2> wake_pipe_fds { -1, -1 };bool wake_pipe_is_signal_target { false };- pthread_t thread_id { 0 };+ AK::ThreadID thread_id;};static void destroy_thread_data(void* value)diff --git a/Libraries/LibCore/Notifier.h b/Libraries/LibCore/Notifier.hindex ab774dd18bd..2fadf9fa38f 100644--- a/Libraries/LibCore/Notifier.h+++ b/Libraries/LibCore/Notifier.h@@ -7,10 +7,10 @@#pragma once#include <AK/Function.h>+#include <AK/ThreadID.h>#include <LibCore/Event.h>#include <LibCore/EventReceiver.h>#include <LibCore/Export.h>-#include <pthread.h>namespace Core {@@ -44,13 +44,13 @@ public:void event(Core::Event&) override;- void set_owner_thread(pthread_t owner_thread) { m_owner_thread = owner_thread; }- pthread_t owner_thread() const { return m_owner_thread; }+ void set_owner_thread(AK::ThreadID owner_thread) { m_owner_thread = owner_thread; }+ AK::ThreadID owner_thread() const { return m_owner_thread; }private:Notifier(int fd, Type type);- pthread_t m_owner_thread {};+ AK::ThreadID m_owner_thread;int m_fd { -1 };Type m_type { Type::None };bool m_is_enabled { false };diff --git a/Services/Compositor/CMakeLists.txt b/Services/Compositor/CMakeLists.txtindex 86f66fc28eb..487e8eedd3d 100644--- a/Services/Compositor/CMakeLists.txt+++ b/Services/Compositor/CMakeLists.txt@@ -78,8 +78,6 @@ if (APPLE)endif()if (WIN32)- target_include_directories(Compositor PRIVATE $<BUILD_INTERFACE:${PTHREAD_INCLUDE_DIR}>)- target_include_directories(compositorservice PRIVATE $<BUILD_INTERFACE:${PTHREAD_INCLUDE_DIR}>)ladybird_windows_bin(Compositor CONSOLE)endif()diff --git a/Services/WebWorker/CMakeLists.txt b/Services/WebWorker/CMakeLists.txtindex 28ccb246d08..c2489da3ce6 100644--- a/Services/WebWorker/CMakeLists.txt+++ b/Services/WebWorker/CMakeLists.txt@@ -34,7 +34,6 @@ target_include_directories(WebWorker PRIVATE ${LADYBIRD_SOURCE_DIR})target_link_libraries(WebWorker PRIVATE webworkerservice LibSandbox OpenSSL::Crypto OpenSSL::SSL)if(WIN32)- target_include_directories(WebWorker PRIVATE $<BUILD_INTERFACE:${PTHREAD_INCLUDE_DIR}>)ladybird_windows_bin(WebWorker CONSOLE)endif()diff --git a/UI/Qt/EventLoopImplementationQt.cpp b/UI/Qt/EventLoopImplementationQt.cppindex 8dcab8e1df6..ce78d4aeceb 100644--- a/UI/Qt/EventLoopImplementationQt.cpp+++ b/UI/Qt/EventLoopImplementationQt.cpp@@ -12,6 +12,7 @@#include <AK/RWLock.h>#include <AK/Singleton.h>#include <AK/TemporaryChange.h>+#include <AK/ThreadID.h>#include <AK/Time.h>#include <AK/kmalloc.h>#include <LibCore/Event.h>@@ -125,9 +126,8 @@ private:struct ThreadData;static thread_local OwnPtr<ThreadData> s_this_thread_data;-static HashMap<pthread_t, ThreadData*> s_thread_data;+static HashMap<AK::ThreadID, ThreadData*> s_thread_data;static RWLock s_thread_data_lock;-static thread_local Optional<pthread_t> s_thread_id;#if defined(AK_OS_WINDOWS)static MutexProtected<HashMap<pid_t, QWinEventNotifier*>> s_processes;#endif@@ -137,17 +137,15 @@ struct ThreadData {static ThreadData& the(){- if (!s_thread_id.has_value())- s_thread_id = pthread_self();if (!s_this_thread_data) {s_this_thread_data = make<ThreadData>();RWLockLocker<RWLock::Mode::Write> locker(s_thread_data_lock);- s_thread_data.set(s_thread_id.value(), s_this_thread_data.ptr());+ s_thread_data.set(AK::ThreadID::current(), s_this_thread_data.ptr());}return *s_this_thread_data;}- static ThreadData* for_thread(pthread_t thread_id)+ static ThreadData* for_thread(AK::ThreadID thread_id){RWLockLocker<RWLock::Mode::Read> locker(s_thread_data_lock);return s_thread_data.get(thread_id).value_or(nullptr);@@ -157,7 +155,7 @@ struct ThreadData {{Core::ThreadEventQueue::destroy_current();RWLockLocker<RWLock::Mode::Write> locker(s_thread_data_lock);- s_thread_data.remove(s_thread_id.value());+ s_thread_data.remove(AK::ThreadID::current());}Mutex mutex;@@ -457,7 +455,7 @@ void EventLoopManagerQt::register_notifier(Core::Notifier& notifier)MutexLocker locker(thread_data.mutex);thread_data.notifiers.set(¬ifier, move(qt_notifier));}- notifier.set_owner_thread(s_thread_id.value());+ notifier.set_owner_thread(AK::ThreadID::current());}void EventLoopManagerQt::unregister_notifier(Core::Notifier& notifier)@@ -627,23 +625,3 @@ NonnullOwnPtr<Core::EventLoopImplementation> EventLoopManagerQt::make_implementa}}--#if defined(AK_OS_WINDOWS)-namespace AK {--template<>-struct Traits<pthread_t> : public DefaultTraits<pthread_t> {- static unsigned hash(pthread_t thread_id)- {- return Traits<intptr_t>::hash(reinterpret_cast<intptr_t>(thread_id.p));- }-- static constexpr bool equals(pthread_t a, pthread_t b)- {- return Traits<intptr_t>::equals(reinterpret_cast<intptr_t>(a.p), reinterpret_cast<intptr_t>(b.p));- }-};--}--#endif