summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/thread/vita/SDL_sysmutex.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/src/thread/vita/SDL_sysmutex.c')
-rw-r--r--contrib/SDL-3.2.8/src/thread/vita/SDL_sysmutex.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/thread/vita/SDL_sysmutex.c b/contrib/SDL-3.2.8/src/thread/vita/SDL_sysmutex.c
new file mode 100644
index 0000000..8a3664c
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/thread/vita/SDL_sysmutex.c
@@ -0,0 +1,97 @@
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#include "SDL_systhread_c.h"
26
27#include <psp2/kernel/threadmgr.h>
28#include <psp2/kernel/error.h>
29
30struct SDL_Mutex
31{
32 SceKernelLwMutexWork lock;
33};
34
35SDL_Mutex *SDL_CreateMutex(void)
36{
37 SDL_Mutex *mutex = (SDL_Mutex *)SDL_malloc(sizeof(*mutex));
38 if (mutex) {
39 const SceInt32 res = sceKernelCreateLwMutex(
40 &mutex->lock,
41 "SDL mutex",
42 SCE_KERNEL_MUTEX_ATTR_RECURSIVE,
43 0,
44 NULL);
45
46 if (res < 0) {
47 SDL_free(mutex);
48 mutex = NULL;
49 SDL_SetError("Error trying to create mutex: %x", res);
50 }
51 }
52 return mutex;
53}
54
55void SDL_DestroyMutex(SDL_Mutex *mutex)
56{
57 if (mutex) {
58 sceKernelDeleteLwMutex(&mutex->lock);
59 SDL_free(mutex);
60 }
61}
62
63void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
64{
65 if (mutex) {
66 const SceInt32 res = sceKernelLockLwMutex(&mutex->lock, 1, NULL);
67 SDL_assert(res == SCE_KERNEL_OK); // assume we're in a lot of trouble if this assert fails.
68 }
69}
70
71bool SDL_TryLockMutex(SDL_Mutex *mutex)
72{
73 bool result = true;
74
75 if (mutex) {
76 const SceInt32 res = sceKernelTryLockLwMutex(&mutex->lock, 1);
77 if (res == SCE_KERNEL_OK) {
78 result = true;
79 } else if (res == SCE_KERNEL_ERROR_MUTEX_FAILED_TO_OWN) {
80 result = false;
81 } else {
82 SDL_assert(res == SCE_KERNEL_OK); // assume we're in a lot of trouble if this assert fails.
83 result = false;
84 }
85 }
86 return result;
87}
88
89void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
90{
91 if (mutex) {
92 const SceInt32 res = sceKernelUnlockLwMutex(&mutex->lock, 1);
93 SDL_assert(res == SCE_KERNEL_OK); // assume we're in a lot of trouble if this assert fails.
94 }
95}
96
97#endif // SDL_THREAD_VITA