mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Migrate to lightweight mutexes
This commit is contained in:
parent
f1ad942a11
commit
e3ea5b6468
@ -30,28 +30,30 @@
|
|||||||
|
|
||||||
struct SDL_mutex
|
struct SDL_mutex
|
||||||
{
|
{
|
||||||
SceUID uid;
|
SceKernelLwMutexWork lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Create a mutex */
|
/* Create a mutex */
|
||||||
SDL_mutex *
|
SDL_mutex *
|
||||||
SDL_CreateMutex(void)
|
SDL_CreateMutex(void)
|
||||||
{
|
{
|
||||||
SDL_mutex *mutex;
|
SDL_mutex *mutex = NULL;
|
||||||
|
SceInt32 res = 0;
|
||||||
|
|
||||||
/* Allocate mutex memory */
|
/* Allocate mutex memory */
|
||||||
mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
|
mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
|
||||||
if (mutex) {
|
if (mutex) {
|
||||||
|
|
||||||
mutex->uid = sceKernelCreateMutex("SDL mutex",
|
res = sceKernelCreateLwMutex(
|
||||||
|
&mutex->lock,
|
||||||
|
"SDL mutex",
|
||||||
SCE_KERNEL_MUTEX_ATTR_RECURSIVE,
|
SCE_KERNEL_MUTEX_ATTR_RECURSIVE,
|
||||||
0,
|
0,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mutex->uid <= 0) {
|
if (res < 0) {
|
||||||
printf("Error creating mutex: %x\n", mutex->uid);
|
SDL_SetError("Error trying to create mutex: %x", res);
|
||||||
SDL_OutOfMemory(); // TODO: proper error
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
@ -64,7 +66,7 @@ void
|
|||||||
SDL_DestroyMutex(SDL_mutex * mutex)
|
SDL_DestroyMutex(SDL_mutex * mutex)
|
||||||
{
|
{
|
||||||
if (mutex) {
|
if (mutex) {
|
||||||
sceKernelDeleteMutex(mutex->uid);
|
sceKernelDeleteLwMutex(&mutex->lock);
|
||||||
SDL_free(mutex);
|
SDL_free(mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,7 +83,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
|
|||||||
return SDL_SetError("Passed a NULL mutex");
|
return SDL_SetError("Passed a NULL mutex");
|
||||||
}
|
}
|
||||||
|
|
||||||
res = sceKernelTryLockMutex(mutex->uid, 1);
|
res = sceKernelTryLockLwMutex(&mutex->lock, 1);
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case SCE_KERNEL_OK:
|
case SCE_KERNEL_OK:
|
||||||
return 0;
|
return 0;
|
||||||
@ -111,7 +113,7 @@ SDL_mutexP(SDL_mutex * mutex)
|
|||||||
return SDL_SetError("Passed a NULL mutex");
|
return SDL_SetError("Passed a NULL mutex");
|
||||||
}
|
}
|
||||||
|
|
||||||
res = sceKernelLockMutex(mutex->uid, 1, NULL);
|
res = sceKernelLockLwMutex(&mutex->lock, 1, NULL);
|
||||||
if (res != SCE_KERNEL_OK) {
|
if (res != SCE_KERNEL_OK) {
|
||||||
return SDL_SetError("Error trying to lock mutex: %x", res);
|
return SDL_SetError("Error trying to lock mutex: %x", res);
|
||||||
}
|
}
|
||||||
@ -133,7 +135,7 @@ SDL_mutexV(SDL_mutex * mutex)
|
|||||||
return SDL_SetError("Passed a NULL mutex");
|
return SDL_SetError("Passed a NULL mutex");
|
||||||
}
|
}
|
||||||
|
|
||||||
res = sceKernelUnlockMutex(mutex->uid, 1);
|
res = sceKernelUnlockLwMutex(&mutex->lock, 1);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return SDL_SetError("Error trying to unlock mutex: %x", res);
|
return SDL_SetError("Error trying to unlock mutex: %x", res);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user