LibThreading: Build on Windows

This commit is contained in:
stasoid 2024-11-28 13:04:39 +05:00 committed by Andrew Kaster
parent e2b6ab4a69
commit 85da489f39
Notes: github-actions[bot] 2024-12-09 00:20:34 +00:00
4 changed files with 17 additions and 5 deletions

View file

@ -9,7 +9,6 @@
#include <LibThreading/BackgroundAction.h>
#include <LibThreading/Mutex.h>
#include <LibThreading/Thread.h>
#include <unistd.h>
static pthread_mutex_t s_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t s_condition = PTHREAD_COND_INITIALIZER;

View file

@ -5,3 +5,9 @@ set(SOURCES
serenity_lib(LibThreading threading)
target_link_libraries(LibThreading PRIVATE LibCore)
if (WIN32)
find_package(pthread REQUIRED)
target_include_directories(LibThreading PRIVATE ${PTHREAD_INCLUDE_DIR})
target_link_libraries(LibThreading PUBLIC ${PTHREAD_LIBRARY})
endif()

View file

@ -5,9 +5,6 @@
*/
#include <LibThreading/Thread.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
namespace Threading {

View file

@ -79,7 +79,7 @@ public:
private:
explicit Thread(ESCAPING Function<intptr_t()> action, StringView thread_name = {});
Function<intptr_t()> m_action;
pthread_t m_tid { 0 };
pthread_t m_tid {};
ByteString m_thread_name;
Atomic<ThreadState> m_state { ThreadState::Startable };
};
@ -108,6 +108,16 @@ Result<T, ThreadError> Thread::join()
}
#ifdef AK_OS_WINDOWS
template<>
struct AK::Formatter<pthread_t> : AK::Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, pthread_t const& tid)
{
return Formatter<FormatString>::format(builder, "{}"sv, pthread_getw32threadid_np(tid));
}
};
#endif
template<>
struct AK::Formatter<Threading::Thread> : AK::Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, Threading::Thread const& thread)