Assign names to threads

Visible in debuggers etc
This commit is contained in:
PJB3005
2026-03-14 14:16:49 +01:00
parent 002a34f18b
commit dca0964f27
7 changed files with 76 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
#ifndef DUSK_OS_H
#define DUSK_OS_H
#ifdef __cplusplus
extern "C" {
#endif
void OSSetCurrentThreadName(const char* name);
#ifdef __cplusplus
}
#endif
#endif // DUSK_OS_H
@@ -132,6 +132,10 @@ public:
static JSUList<JKRThread> sThreadList;
// static u8 sThreadList[12];
#if TARGET_PC
const char* mThreadName;
#endif
};
class JKRIdleThread : public JKRThread {
+12
View File
@@ -7,6 +7,10 @@
#include "global.h"
#include <stdint.h>
#if TARGET_PC
#include "dusk/os.h"
#endif
JSUList<JKRThread> JKRThread::sThreadList(0);
void* JKRIdleThread::sThread;
@@ -88,6 +92,14 @@ void JKRThread::setCommon_heapSpecified(JKRHeap* heap, u32 stack_size, int param
}
void* JKRThread::start(void* thread) {
#if TARGET_PC
auto& thd = *static_cast<JKRThread*>(thread);
if (thd.mThreadName == nullptr) {
thd.mThreadName = typeid(thd).name();
}
OSSetCurrentThreadName(thd.mThreadName);
#endif
return ((JKRThread*)thread)->run();
}
+30
View File
@@ -17,6 +17,12 @@
#include <memory>
#include "JSystem/JKernel/JKRHeap.h"
#include "dusk/os.h"
#if _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif
// ============================================================================
// Malloc-based allocator to bypass JKRHeap operator new/delete
@@ -744,6 +750,30 @@ OSInterruptMask __OSUnmaskInterrupts(OSInterruptMask mask) {
return 0;
}
void OSSetCurrentThreadName(const char* name) {
// "Why is this current thread only?", you might ask?
// Because macOS requires that. For some reason.
#if _WIN32
wchar_t buffer[256];
const auto converted = MultiByteToWideChar(
CP_UTF8,
0,
name,
-1,
buffer,
sizeof(buffer)/sizeof(wchar_t));
if (converted == 0) {
CRASH("OSSetThreadName: MultiByteToWideChar failed");
}
const auto result = SetThreadDescription(GetCurrentThread(), buffer);
if (!SUCCEEDED(result)) {
CRASH("OSSetThreadName: SetThreadDescription failed");
}
#endif
}
#ifdef __cplusplus
}
#endif
+7
View File
@@ -14,6 +14,8 @@
#include <chrono>
#include <thread>
#include "dusk/os.h"
#if PLATFORM_GCN
const int stack_size = 3072;
#else
@@ -65,6 +67,11 @@ static void mDoDvdErr_Watch(void*) {
OSDisableInterrupts();
#endif
#endif
#if TARGET_PC
OSSetCurrentThreadName("DVD error thread");
#endif
JKRThread(OSGetCurrentThread(), 0);
JKRSetCurrentHeap(mDoExt_getAssertHeap());
+5
View File
@@ -10,6 +10,7 @@
#include "m_Do/m_Do_MemCardRWmng.h"
#include "m_Do/m_Do_Reset.h"
#include "os_report.h"
#include "dusk/os.h"
#if PLATFORM_WII || PLATFORM_SHIELD
#include <revolution/nand.h>
@@ -866,6 +867,10 @@ mDoMemCd_Ctrl_c g_mDoMemCd_control;
static int mDoMemCd_main(void*) {
JKRThread(OSGetCurrentThread(), 0);
#if TARGET_PC
OSSetCurrentThreadName("MemCardThread");
#endif
JKRSetCurrentHeap(mDoExt_getAssertHeap());
g_mDoMemCd_control.main();
+4
View File
@@ -10,6 +10,7 @@
#include "JSystem/JKernel/JKRDvdRipper.h"
#include "JSystem/JKernel/JKRExpHeap.h"
#include "JSystem/JKernel/JKRMemArchive.h"
#include "dusk/os.h"
#include "m_Do/m_Do_Reset.h"
#include "m_Do/m_Do_controller_pad.h"
#include "m_Do/m_Do_ext.h"
@@ -17,6 +18,9 @@
s32 mDoDvdThd::main(void* param_0) {
JKRThread(OSGetCurrentThread(), 0);
#if TARGET_PC
OSSetCurrentThreadName("DVD thread");
#endif
JKRSetCurrentHeap(mDoExt_getAssertHeap());
mDoDvdThd_param_c* param = static_cast<mDoDvdThd_param_c*>(param_0);
param->mainLoop();