Skip to content

Commit 6e79c14

Browse files
ayeteadoekalenikaliaksandr
authored andcommitted
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.
1 parent ef8dcb2 commit 6e79c14

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,47 @@ namespace WebView {
2929

3030
struct ThreadData;
3131
static thread_local OwnPtr<ThreadData> s_this_thread_data;
32-
static HashMap<pthread_t, ThreadData*> s_thread_data;
32+
#if defined(AK_OS_WINDOWS)
33+
# define THREAD_ID_KEY intptr_t
34+
#else
35+
# define THREAD_ID_KEY pthread_t
36+
#endif
37+
static HashMap<THREAD_ID_KEY, ThreadData*> s_thread_data;
3338
static Threading::RWLock s_thread_data_lock;
3439
static thread_local pthread_t s_thread_id;
3540

41+
static THREAD_ID_KEY thread_id_key(pthread_t thread_id)
42+
{
43+
#if defined(AK_OS_WINDOWS)
44+
return reinterpret_cast<intptr_t>(thread_id.p);
45+
#else
46+
return thread_id;
47+
#endif
48+
}
49+
3650
struct ThreadData {
3751
static ThreadData& the()
3852
{
39-
if (s_thread_id == 0)
53+
if (thread_id_key(s_thread_id) == 0)
4054
s_thread_id = pthread_self();
4155
if (!s_this_thread_data) {
4256
s_this_thread_data = make<ThreadData>();
4357
Threading::RWLockLocker<Threading::LockMode::Write> locker(s_thread_data_lock);
44-
s_thread_data.set(s_thread_id, s_this_thread_data.ptr());
58+
s_thread_data.set(thread_id_key(s_thread_id), s_this_thread_data.ptr());
4559
}
4660
return *s_this_thread_data;
4761
}
4862

4963
static ThreadData* for_thread(pthread_t thread_id)
5064
{
5165
Threading::RWLockLocker<Threading::LockMode::Read> locker(s_thread_data_lock);
52-
return s_thread_data.get(thread_id).value_or(nullptr);
66+
return s_thread_data.get(thread_id_key(thread_id)).value_or(nullptr);
5367
}
5468

5569
~ThreadData()
5670
{
5771
Threading::RWLockLocker<Threading::LockMode::Write> locker(s_thread_data_lock);
58-
s_thread_data.remove(s_thread_id);
72+
s_thread_data.remove(thread_id_key(s_thread_id));
5973
}
6074

6175
Threading::Mutex mutex;

0 commit comments

Comments
 (0)