diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-20 15:11:28 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-20 15:11:28 +0100 |
| commit | 5238a2a14d4132994fda7df8cb4a22d24900c4b4 (patch) | |
| tree | ba3e9ddaff9da1d82704e875aab70d8f1c7f6607 /frameworks/libThread.fwrk | |
| parent | cd3a358ab2635d825b716786d0b85481af7cd3a3 (diff) | |
[CHORE] ThreadManager.cpp: Update Thread manager code to account for semaphores and exit codes.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'frameworks/libThread.fwrk')
| -rw-r--r-- | frameworks/libThread.fwrk/src/ThreadManager.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/frameworks/libThread.fwrk/src/ThreadManager.cpp b/frameworks/libThread.fwrk/src/ThreadManager.cpp index 9b222ab..f01bbfe 100644 --- a/frameworks/libThread.fwrk/src/ThreadManager.cpp +++ b/frameworks/libThread.fwrk/src/ThreadManager.cpp @@ -11,9 +11,29 @@ /// @brief The registered thread for a specific process. static ThreadRef kThreadMap[kThreadMapMax]; +/// @brief Exit codes as we want to track them. +static SInt32 kThreadExitCodes[kThreadMapMax]; + /// @brief This hash-list stores the thread to be run. static ThreadRef kThreadHeads[kThreadMapMax]; +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"); + + if (sem_ref) return; + + auto ret = procedure(argument_count, (Char**) args); + kThreadExitCodes[kThreadMapMax % ref->__hash] = ret; + + if (ref == kCurrentThread) kCurrentThread = nullptr; + + SemClose(sem_ref); + sem_ref = nullptr; +} + IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedure, SInt32 argument_count, VoidPtr args, SInt32 flags) { ThreadRef ref = new REF_TYPE; @@ -26,12 +46,16 @@ IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedur } ref->__hash = *(UInt32*) thread_name; - ref->__hash += kThreadBaseHash; + ref->__hash += kThreadBaseHash; // pad hash with a seed. ref->__self = (VoidPtr) procedure; - kThreadMap[kThreadMapMax % ref->__hash] = ref; + kThreadMap[kThreadMapMax % ref->__hash] = ref; kThreadHeads[kThreadMapMax % ref->__hash] = ref; + kCurrentThread = ref; + + _ThrRunThread(argument_count, args, procedure, ref); + return ref; } |
