mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
UI/Qt: Support usage of pthread_t as a hash map key on Windows
https://programmerall.com/article/10061564414/ describes the slight differences in how pthread_t is implemented on Windows. This is a hack to get Windows building and running again, but long term it'd be ideal to create an abstraction for any usage of pthread_t in the codebase.
This commit is contained in:
parent
ef8dcb2a43
commit
6e79c14ed0
Notes:
github-actions[bot]
2025-11-03 01:29:53 +00:00
Author: https://github.com/ayeteadoe
Commit: 6e79c14ed0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6667
Reviewed-by: https://github.com/kalenikaliaksandr ✅
1 changed files with 19 additions and 5 deletions
|
|
@ -29,19 +29,33 @@ namespace WebView {
|
|||
|
||||
struct ThreadData;
|
||||
static thread_local OwnPtr<ThreadData> s_this_thread_data;
|
||||
static HashMap<pthread_t, ThreadData*> s_thread_data;
|
||||
#if defined(AK_OS_WINDOWS)
|
||||
# define THREAD_ID_KEY intptr_t
|
||||
#else
|
||||
# define THREAD_ID_KEY pthread_t
|
||||
#endif
|
||||
static HashMap<THREAD_ID_KEY, ThreadData*> s_thread_data;
|
||||
static Threading::RWLock s_thread_data_lock;
|
||||
static thread_local pthread_t s_thread_id;
|
||||
|
||||
static THREAD_ID_KEY thread_id_key(pthread_t thread_id)
|
||||
{
|
||||
#if defined(AK_OS_WINDOWS)
|
||||
return reinterpret_cast<intptr_t>(thread_id.p);
|
||||
#else
|
||||
return thread_id;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct ThreadData {
|
||||
static ThreadData& the()
|
||||
{
|
||||
if (s_thread_id == 0)
|
||||
if (thread_id_key(s_thread_id) == 0)
|
||||
s_thread_id = pthread_self();
|
||||
if (!s_this_thread_data) {
|
||||
s_this_thread_data = make<ThreadData>();
|
||||
Threading::RWLockLocker<Threading::LockMode::Write> locker(s_thread_data_lock);
|
||||
s_thread_data.set(s_thread_id, s_this_thread_data.ptr());
|
||||
s_thread_data.set(thread_id_key(s_thread_id), s_this_thread_data.ptr());
|
||||
}
|
||||
return *s_this_thread_data;
|
||||
}
|
||||
|
|
@ -49,13 +63,13 @@ struct ThreadData {
|
|||
static ThreadData* for_thread(pthread_t thread_id)
|
||||
{
|
||||
Threading::RWLockLocker<Threading::LockMode::Read> locker(s_thread_data_lock);
|
||||
return s_thread_data.get(thread_id).value_or(nullptr);
|
||||
return s_thread_data.get(thread_id_key(thread_id)).value_or(nullptr);
|
||||
}
|
||||
|
||||
~ThreadData()
|
||||
{
|
||||
Threading::RWLockLocker<Threading::LockMode::Write> locker(s_thread_data_lock);
|
||||
s_thread_data.remove(s_thread_id);
|
||||
s_thread_data.remove(thread_id_key(s_thread_id));
|
||||
}
|
||||
|
||||
Threading::Mutex mutex;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue