From 9392f90f768fefb01b555caeb4211ba3e074a743 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 23 Mar 2026 09:44:36 +0100 Subject: [FEAT] Improve libThread with additional ThrExitThread function, X11 and al versioning. Signed-off-by: Amlal El Mahrouss --- frameworks/libThread.fwrk/headers/Config.h | 2 ++ frameworks/libThread.fwrk/src/ThreadMgr.cpp | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'frameworks/libThread.fwrk') diff --git a/frameworks/libThread.fwrk/headers/Config.h b/frameworks/libThread.fwrk/headers/Config.h index c6734a4..f69f0f5 100644 --- a/frameworks/libThread.fwrk/headers/Config.h +++ b/frameworks/libThread.fwrk/headers/Config.h @@ -8,4 +8,6 @@ #include +#define LIBTHREAD_VERSION 0x100000 + #endif // LIBTHREAD_FOUNDATION_H diff --git a/frameworks/libThread.fwrk/src/ThreadMgr.cpp b/frameworks/libThread.fwrk/src/ThreadMgr.cpp index 7361f86..6a7843f 100644 --- a/frameworks/libThread.fwrk/src/ThreadMgr.cpp +++ b/frameworks/libThread.fwrk/src/ThreadMgr.cpp @@ -3,6 +3,7 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/ne_system +#include #include #define kThreadMapMax (1024UL) @@ -21,15 +22,15 @@ static ThreadRef kCurrentThread; static __THREAD_UNSAFE Void _ThrRunThread(SInt32 argument_count, VoidPtr args, ThrProcKind procedure, ThreadRef ref) { - static SemaphoreRef sem_ref = SemCreate(0, 1000, "ThreadSem"); - + static SemaphoreRef sem_ref = SemCreate(0, 1000, "ThreadSem"); + if (sem_ref) return; - - auto ret = procedure(argument_count, (Char**) args); + + auto ret = procedure(argument_count, (Char**) args); kThreadExitCodes[kThreadMapMax % ref->__hash] = ret; if (ref == kCurrentThread) kCurrentThread = nullptr; - + SemClose(sem_ref); sem_ref = nullptr; } @@ -46,7 +47,7 @@ IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedur } ref->__hash = *(UInt32*) thread_name; - ref->__hash += kThreadBaseHash; // pad hash with a seed. + ref->__hash += kThreadBaseHash; // pad hash with a seed. ref->__self = (VoidPtr) procedure; @@ -59,3 +60,15 @@ IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedur return ref; } + +IMPORT_C SInt32 ThrExitThread(_Input ThreadRef ref, _Input SInt32 exit_code) { + if (!ref) return kErrorInvalidData; + + kThreadMap[kThreadMapMax % ref->__hash] = nullptr; + kThreadHeads[kThreadMapMax % ref->__hash] = nullptr; + + if (kCurrentThread == ref) kCurrentThread = nullptr; + + kThreadExitCodes[kThreadMapMax % ref->__hash] = exit_code; + return kErrorSuccess; +} \ No newline at end of file -- cgit v1.2.3