Threading: Backport thread ID not getting set

Don't think it's causing any issues here, but just in case.
pull/3699/head
Stenzek 7 months ago
parent 234f263e78
commit dd3d7d372c
No known key found for this signature in database

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#include "threading.h"
@ -122,6 +122,7 @@ Threading::ThreadHandle::ThreadHandle(const ThreadHandle& handle)
THREAD_QUERY_INFORMATION | THREAD_SET_LIMITED_INFORMATION, FALSE, 0))
{
m_native_handle = (void*)new_handle;
m_native_id = handle.m_native_id;
}
}
}
@ -137,9 +138,11 @@ Threading::ThreadHandle::ThreadHandle(const ThreadHandle& handle)
#endif
#ifdef _WIN32
Threading::ThreadHandle::ThreadHandle(ThreadHandle&& handle) : m_native_handle(handle.m_native_handle)
Threading::ThreadHandle::ThreadHandle(ThreadHandle&& handle)
: m_native_handle(handle.m_native_handle), m_native_id(handle.m_native_id)
{
handle.m_native_handle = nullptr;
handle.m_native_id = 0;
}
#else
Threading::ThreadHandle::ThreadHandle(ThreadHandle&& handle)
@ -231,6 +234,24 @@ Threading::ThreadHandle& Threading::ThreadHandle::operator=(const ThreadHandle&
return *this;
}
bool Threading::ThreadHandle::operator==(const ThreadHandle& other) const
{
#ifdef _WIN32
return m_native_id == other.m_native_id;
#else
return pthread_equal((pthread_t)m_native_handle, (pthread_t)other.m_native_handle);
#endif
}
bool Threading::ThreadHandle::operator!=(const ThreadHandle& other) const
{
#ifdef _WIN32
return m_native_id != other.m_native_id;
#else
return !pthread_equal((pthread_t)m_native_handle, (pthread_t)other.m_native_handle);
#endif
}
u64 Threading::ThreadHandle::GetCPUTime() const
{
#if defined(_WIN32) && !defined(_M_ARM64)
@ -375,9 +396,8 @@ bool Threading::Thread::Start(EntryPoint func)
AssertMsg(!m_native_handle, "Can't start an already-started thread");
std::unique_ptr<EntryPoint> func_clone(std::make_unique<EntryPoint>(std::move(func)));
unsigned thread_id;
m_native_handle =
reinterpret_cast<void*>(_beginthreadex(nullptr, m_stack_size, ThreadProc, func_clone.get(), 0, &thread_id));
reinterpret_cast<void*>(_beginthreadex(nullptr, m_stack_size, ThreadProc, func_clone.get(), 0, &m_native_id));
if (!m_native_handle)
return false;

@ -1,7 +1,8 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#pragma once
#include "types.h"
#if defined(__APPLE__)
@ -46,6 +47,9 @@ public:
operator void*() const { return m_native_handle; }
operator bool() const { return (m_native_handle != nullptr); }
bool operator==(const ThreadHandle& other) const;
bool operator!=(const ThreadHandle& other) const;
/// Returns the amount of CPU time consumed by the thread, at the GetThreadTicksPerSecond() frequency.
u64 GetCPUTime() const;

Loading…
Cancel
Save