Atlas - SDL_systhread.c

Home / ext / SDL / src / thread / dos Lines: 1 | Size: 2664 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef SDL_THREAD_DOS 24 25/* DOS thread management routines for SDL — cooperative threading via 26 the DOS mini-scheduler (no OS-level threads on DOS). */ 27 28#include "../../core/dos/SDL_dos_scheduler.h" 29#include "../SDL_systhread.h" 30#include "../SDL_thread_c.h" 31 32static int ThreadEntry(void *arg) 33{ 34 SDL_Thread *thread = (SDL_Thread *)arg; 35 SDL_RunThread(thread); 36 return 0; 37} 38 39bool SDL_SYS_CreateThread(SDL_Thread *thread, 40 SDL_FunctionPointer pfnBeginThread, 41 SDL_FunctionPointer pfnEndThread) 42{ 43 /* Ensure the scheduler is initialized (idempotent) */ 44 DOS_SchedulerInit(); 45 46 size_t stack_size = thread->stacksize; 47 48 int tid = DOS_CreateThread(ThreadEntry, thread, stack_size); 49 if (tid < 0) { 50 return SDL_SetError("DOS_CreateThread() failed — no free thread slots"); 51 } 52 53 thread->handle = tid; 54 return true; 55} 56 57void SDL_SYS_SetupThread(const char *name) 58{ 59 /* Nothing to do on DOS */ 60} 61 62SDL_ThreadID SDL_GetCurrentThreadID(void) 63{ 64 return (SDL_ThreadID)DOS_GetCurrentThreadID(); 65} 66 67void SDL_SYS_WaitThread(SDL_Thread *thread) 68{ 69 DOS_JoinThread(thread->handle); 70 DOS_DestroyThread(thread->handle); 71} 72 73void SDL_SYS_DetachThread(SDL_Thread *thread) 74{ 75 /* For cooperative threads, detach is a no-op. The thread will clean 76 itself up when it finishes. In practice, SDL's thread code handles 77 the detach lifecycle via atomics in SDL_RunThread. */ 78} 79 80bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) 81{ 82 /* DOS cooperative scheduler uses round-robin — priority is not 83 meaningful. Accept any value without error. */ 84 return true; 85} 86 87#endif /* SDL_THREAD_DOS */ 88
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.