summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/thread/psp/SDL_systhread.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/src/thread/psp/SDL_systhread.c')
-rw-r--r--contrib/SDL-3.2.8/src/thread/psp/SDL_systhread.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/thread/psp/SDL_systhread.c b/contrib/SDL-3.2.8/src/thread/psp/SDL_systhread.c
new file mode 100644
index 0000000..3d60718
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/thread/psp/SDL_systhread.c
@@ -0,0 +1,112 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
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
35static int ThreadEntry(SceSize args, void *argp)
36{
37 SDL_RunThread(*(SDL_Thread **)argp);
38 return 0;
39}
40
41bool SDL_SYS_CreateThread(SDL_Thread *thread,
42 SDL_FunctionPointer pfnBeginThread,
43 SDL_FunctionPointer pfnEndThread)
44{
45 SceKernelThreadInfo status;
46 int priority = 32;
47
48 // Set priority of new thread to the same as the current thread
49 status.size = sizeof(SceKernelThreadInfo);
50 if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
51 priority = status.currentPriority;
52 }
53
54 thread->handle = sceKernelCreateThread(thread->name, ThreadEntry,
55 priority, thread->stacksize ? ((int)thread->stacksize) : 0x8000,
56 PSP_THREAD_ATTR_VFPU, NULL);
57 if (thread->handle < 0) {
58 return SDL_SetError("sceKernelCreateThread() failed");
59 }
60
61 sceKernelStartThread(thread->handle, 4, &thread);
62 return true;
63}
64
65void SDL_SYS_SetupThread(const char *name)
66{
67 // Do nothing.
68}
69
70SDL_ThreadID SDL_GetCurrentThreadID(void)
71{
72 return (SDL_ThreadID)sceKernelGetThreadId();
73}
74
75void SDL_SYS_WaitThread(SDL_Thread *thread)
76{
77 sceKernelWaitThreadEnd(thread->handle, NULL);
78 sceKernelDeleteThread(thread->handle);
79}
80
81void SDL_SYS_DetachThread(SDL_Thread *thread)
82{
83 // !!! FIXME: is this correct?
84 sceKernelDeleteThread(thread->handle);
85}
86
87void SDL_SYS_KillThread(SDL_Thread *thread)
88{
89 sceKernelTerminateDeleteThread(thread->handle);
90}
91
92bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
93{
94 int value;
95
96 if (priority == SDL_THREAD_PRIORITY_LOW) {
97 value = 111;
98 } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
99 value = 32;
100 } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
101 value = 16;
102 } else {
103 value = 50;
104 }
105
106 if (sceKernelChangeThreadPriority(sceKernelGetThreadId(), value) < 0) {
107 return SDL_SetError("sceKernelChangeThreadPriority() failed");
108 }
109 return true;
110}
111
112#endif // SDL_THREAD_PSP