feat: add threading to Scheduler, fix desktop background selection freeze issue

This commit is contained in:
2026-05-23 16:08:25 +02:00
parent a44a65d432
commit cd159235ca
15 changed files with 895 additions and 117 deletions
+21
View File
@@ -98,6 +98,8 @@ namespace Montauk {
for (int i = 0; i < Sched::MaxProcesses && count < maxCount; i++) {
auto* proc = Sched::GetProcessSlot(i);
if (!proc || proc->state == Sched::ProcessState::Free) continue;
// Skip sibling-thread slots; only show one entry per process.
if (proc->primarySlot != i) continue;
buf[count].pid = (int32_t)proc->pid;
buf[count].parentPid = (int32_t)proc->parentPid;
@@ -154,6 +156,25 @@ namespace Montauk {
return i;
}
// ====================================================================
// Threading
// ====================================================================
static int Sys_ThreadSpawn(uint64_t entry, uint64_t arg, uint64_t userStackTop) {
return Sched::SpawnThread(entry, arg, userStackTop);
}
[[noreturn]] static void Sys_ThreadExit(int exitCode) {
Sched::ExitCurrentThread(exitCode);
}
static int Sys_ThreadJoin(int tid, int* outExitCode) {
return Sched::JoinThread(tid, outExitCode);
}
static int Sys_ThreadSelf() {
return Sched::GetCurrentTid();
}
static int Sys_Chdir(const char* path) {
auto* proc = Sched::GetCurrentProcessPtr();
if (proc == nullptr || path == nullptr) return -1;
+10
View File
@@ -340,6 +340,16 @@ namespace Montauk {
return Sys_AudioList((AudioStreamInfo*)frame->arg1, (int)frame->arg2);
case SYS_AUDIOWAIT:
return Sys_AudioWait(frame->arg1, frame->arg2);
case SYS_THREAD_SPAWN:
return Sys_ThreadSpawn(frame->arg1, frame->arg2, frame->arg3);
case SYS_THREAD_EXIT:
Sys_ThreadExit((int)frame->arg1);
return 0;
case SYS_THREAD_JOIN:
if (frame->arg2 != 0 && !UserMemory::Writable<int>(frame->arg2)) return -1;
return Sys_ThreadJoin((int)frame->arg1, (int*)frame->arg2);
case SYS_THREAD_SELF:
return Sys_ThreadSelf();
case SYS_BTSCAN:
if ((int64_t)frame->arg2 < 0) return -1;
if (!UserMemory::Range(frame->arg1, (uint64_t)frame->arg2 * sizeof(BtScanResult), true)) return -1;
+6
View File
@@ -243,6 +243,12 @@ namespace Montauk {
static constexpr uint64_t SYS_AUDIOLIST = 128;
static constexpr uint64_t SYS_AUDIOWAIT = 129;
/* Process.hpp -- threading */
static constexpr uint64_t SYS_THREAD_SPAWN = 130;
static constexpr uint64_t SYS_THREAD_EXIT = 131;
static constexpr uint64_t SYS_THREAD_JOIN = 132;
static constexpr uint64_t SYS_THREAD_SELF = 133;
static constexpr uint32_t CLIPBOARD_MAX_TEXT_BYTES = 256 * 1024;
static constexpr uint32_t IPC_SIGNAL_READABLE = 1u << 0;