diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-23 09:44:36 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-23 09:44:36 +0100 |
| commit | 9392f90f768fefb01b555caeb4211ba3e074a743 (patch) | |
| tree | 3abc3848792ed1b58b1154df48eefbefd9bffe88 /frameworks/libThread.fwrk/src | |
| parent | 8c317ab239e71233de0d8783408b39fbd402d456 (diff) | |
[FEAT] Improve libThread with additional ThrExitThread function, X11 and al versioning.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'frameworks/libThread.fwrk/src')
| -rw-r--r-- | frameworks/libThread.fwrk/src/ThreadMgr.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
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 <libSystem/SystemKit/Err.h> #include <libThread.fwrk/headers/Config.h> #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 |
