summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/thread/vita/SDL_systhread.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/src/thread/vita/SDL_systhread.c')
-rw-r--r--contrib/SDL-3.2.8/src/thread/vita/SDL_systhread.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/thread/vita/SDL_systhread.c b/contrib/SDL-3.2.8/src/thread/vita/SDL_systhread.c
new file mode 100644
index 0000000..344d911
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/thread/vita/SDL_systhread.c
@@ -0,0 +1,139 @@
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_VITA
24
25// VITA 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 <psp2/types.h>
33#include <psp2/kernel/threadmgr.h>
34
35#define VITA_THREAD_STACK_SIZE_MIN 0x1000 // 4KiB
36#define VITA_THREAD_STACK_SIZE_MAX 0x2000000 // 32MiB
37#define VITA_THREAD_STACK_SIZE_DEFAULT 0x10000 // 64KiB
38#define VITA_THREAD_NAME_MAX 32
39
40#define VITA_THREAD_PRIORITY_LOW 191
41#define VITA_THREAD_PRIORITY_NORMAL 160
42#define VITA_THREAD_PRIORITY_HIGH 112
43#define VITA_THREAD_PRIORITY_TIME_CRITICAL 64
44
45static int ThreadEntry(SceSize args, void *argp)
46{
47 SDL_RunThread(*(SDL_Thread **)argp);
48 return 0;
49}
50
51bool SDL_SYS_CreateThread(SDL_Thread *thread,
52 SDL_FunctionPointer pfnBeginThread,
53 SDL_FunctionPointer pfnEndThread)
54
55{
56 char thread_name[VITA_THREAD_NAME_MAX];
57 size_t stack_size = VITA_THREAD_STACK_SIZE_DEFAULT;
58
59 SDL_strlcpy(thread_name, "SDL thread", VITA_THREAD_NAME_MAX);
60 if (thread->name) {
61 SDL_strlcpy(thread_name, thread->name, VITA_THREAD_NAME_MAX);
62 }
63
64 if (thread->stacksize) {
65 if (thread->stacksize < VITA_THREAD_STACK_SIZE_MIN) {
66 thread->stacksize = VITA_THREAD_STACK_SIZE_MIN;
67 }
68 if (thread->stacksize > VITA_THREAD_STACK_SIZE_MAX) {
69 thread->stacksize = VITA_THREAD_STACK_SIZE_MAX;
70 }
71 stack_size = thread->stacksize;
72 }
73
74 // Create new thread with the same priority as the current thread
75 thread->handle = sceKernelCreateThread(
76 thread_name, // name
77 ThreadEntry, // function to run
78 0, // priority. 0 means priority of calling thread
79 stack_size, // stack size
80 0, // attributes. always 0
81 0, // cpu affinity mask. 0 = all CPUs
82 NULL // opt. always NULL
83 );
84
85 if (thread->handle < 0) {
86 return SDL_SetError("sceKernelCreateThread() failed");
87 }
88
89 sceKernelStartThread(thread->handle, 4, &thread);
90 return true;
91}
92
93void SDL_SYS_SetupThread(const char *name)
94{
95 // Do nothing.
96}
97
98SDL_ThreadID SDL_GetCurrentThreadID(void)
99{
100 return (SDL_ThreadID)sceKernelGetThreadId();
101}
102
103void SDL_SYS_WaitThread(SDL_Thread *thread)
104{
105 sceKernelWaitThreadEnd(thread->handle, NULL, NULL);
106 sceKernelDeleteThread(thread->handle);
107}
108
109void SDL_SYS_DetachThread(SDL_Thread *thread)
110{
111 // Do nothing.
112}
113
114bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
115{
116 int value = VITA_THREAD_PRIORITY_NORMAL;
117
118 switch (priority) {
119 case SDL_THREAD_PRIORITY_LOW:
120 value = VITA_THREAD_PRIORITY_LOW;
121 break;
122 case SDL_THREAD_PRIORITY_NORMAL:
123 value = VITA_THREAD_PRIORITY_NORMAL;
124 break;
125 case SDL_THREAD_PRIORITY_HIGH:
126 value = VITA_THREAD_PRIORITY_HIGH;
127 break;
128 case SDL_THREAD_PRIORITY_TIME_CRITICAL:
129 value = VITA_THREAD_PRIORITY_TIME_CRITICAL;
130 break;
131 }
132
133 if (sceKernelChangeThreadPriority(0, value) < 0) {
134 return SDL_SetError("sceKernelChangeThreadPriority() failed");
135 }
136 return true;
137}
138
139#endif // SDL_THREAD_VITA