Atlas - SDL_systhread.c
Home / ext / SDL / src / thread / psp Lines: 1 | Size: 3503 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 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_PSP 24 25// PSP thread management routines for SDL 26 27#include <stdio.h> 28#include <stdlib.h> 29 30#include "../SDL_systhread.h" 31#include "../SDL_thread_c.h" 32#include <pspkerneltypes.h> 33#include <pspthreadman.h> 34 35#define PSP_THREAD_NAME_MAX 32 36 37static int ThreadEntry(SceSize args, void *argp) 38{ 39 SDL_RunThread(*(SDL_Thread **)argp); 40 return 0; 41} 42 43bool SDL_SYS_CreateThread(SDL_Thread *thread, 44 SDL_FunctionPointer pfnBeginThread, 45 SDL_FunctionPointer pfnEndThread) 46{ 47 SceKernelThreadInfo status; 48 int priority = 32; 49 char thread_name[PSP_THREAD_NAME_MAX]; 50 51 // Set priority of new thread to the same as the current thread 52 status.size = sizeof(SceKernelThreadInfo); 53 if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) { 54 priority = status.currentPriority; 55 } 56 57 SDL_strlcpy(thread_name, "SDL thread", PSP_THREAD_NAME_MAX); 58 if (thread->name) { 59 SDL_strlcpy(thread_name, thread->name, PSP_THREAD_NAME_MAX); 60 } 61 62 thread->handle = sceKernelCreateThread(thread_name, ThreadEntry, 63 priority, thread->stacksize ? ((int)thread->stacksize) : 0x8000, 64 PSP_THREAD_ATTR_VFPU, NULL); 65 if (thread->handle < 0) { 66 return SDL_SetError("sceKernelCreateThread() failed"); 67 } 68 69 sceKernelStartThread(thread->handle, 4, &thread); 70 return true; 71} 72 73void SDL_SYS_SetupThread(const char *name) 74{ 75 // Do nothing. 76} 77 78SDL_ThreadID SDL_GetCurrentThreadID(void) 79{ 80 return (SDL_ThreadID)sceKernelGetThreadId(); 81} 82 83void SDL_SYS_WaitThread(SDL_Thread *thread) 84{ 85 sceKernelWaitThreadEnd(thread->handle, NULL); 86 sceKernelDeleteThread(thread->handle); 87} 88 89void SDL_SYS_DetachThread(SDL_Thread *thread) 90{ 91 // !!! FIXME: is this correct? 92 sceKernelDeleteThread(thread->handle); 93} 94 95void SDL_SYS_KillThread(SDL_Thread *thread) 96{ 97 sceKernelTerminateDeleteThread(thread->handle); 98} 99 100bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) 101{ 102 int value; 103 104 if (priority == SDL_THREAD_PRIORITY_LOW) { 105 value = 111; 106 } else if (priority == SDL_THREAD_PRIORITY_HIGH) { 107 value = 32; 108 } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) { 109 value = 16; 110 } else { 111 value = 50; 112 } 113 114 if (sceKernelChangeThreadPriority(sceKernelGetThreadId(), value) < 0) { 115 return SDL_SetError("sceKernelChangeThreadPriority() failed"); 116 } 117 return true; 118} 119 120#endif // SDL_THREAD_PSP 121[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.