early-access version 2835
This commit is contained in:
2
externals/SDL/src/thread/SDL_systhread.h
vendored
2
externals/SDL/src/thread/SDL_systhread.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
2
externals/SDL/src/thread/SDL_thread.c
vendored
2
externals/SDL/src/thread/SDL_thread.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
6
externals/SDL/src/thread/SDL_thread_c.h
vendored
6
externals/SDL/src/thread/SDL_thread_c.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "pthread/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_WINDOWS
|
||||
#include "windows/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_PS2
|
||||
#include "ps2/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_PSP
|
||||
#include "psp/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_VITA
|
||||
@@ -40,6 +42,8 @@
|
||||
#include "stdcpp/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_OS2
|
||||
#include "os2/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_NGAGE
|
||||
#include "ngage/SDL_systhread_c.h"
|
||||
#else
|
||||
#error Need thread implementation for this platform
|
||||
#include "generic/SDL_systhread_c.h"
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -99,7 +99,7 @@ SDL_CondSignal_generic(SDL_cond * _cond)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* If there are waiting threads not already signalled, then
|
||||
@@ -124,7 +124,7 @@ SDL_CondBroadcast_generic(SDL_cond * _cond)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* If there are waiting threads not already signalled, then
|
||||
@@ -181,7 +181,7 @@ SDL_CondWaitTimeout_generic(SDL_cond * _cond, SDL_mutex * mutex, Uint32 ms)
|
||||
int retval;
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* Obtain the protection mutex, and increment the number of waiters.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -78,7 +78,7 @@ SDL_LockMutex(SDL_mutex * mutex)
|
||||
SDL_threadID this_thread;
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
this_thread = SDL_ThreadID();
|
||||
@@ -109,7 +109,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
|
||||
SDL_threadID this_thread;
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
this_thread = SDL_ThreadID();
|
||||
@@ -139,7 +139,7 @@ SDL_mutexV(SDL_mutex * mutex)
|
||||
return 0;
|
||||
#else
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
/* If we don't own the mutex, we can't unlock it */
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -132,7 +132,7 @@ SDL_SemTryWait(SDL_sem * sem)
|
||||
int retval;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
@@ -152,7 +152,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||
int retval;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
/* A timeout of 0 is an easy case */
|
||||
@@ -200,7 +200,7 @@ int
|
||||
SDL_SemPost(SDL_sem * sem)
|
||||
{
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
SDL_LockMutex(sem->count_lock);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
123
externals/SDL/src/thread/ngage/SDL_sysmutex.cpp
vendored
Executable file
123
externals/SDL/src/thread/ngage/SDL_sysmutex.cpp
vendored
Executable file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
/* An implementation of mutexes using the Symbian API. */
|
||||
|
||||
#include <e32std.h>
|
||||
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_systhread_c.h"
|
||||
|
||||
struct SDL_mutex
|
||||
{
|
||||
TInt handle;
|
||||
};
|
||||
|
||||
extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
|
||||
|
||||
static TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*)
|
||||
{
|
||||
return ((RMutex*)aPtr1)->CreateGlobal(aName);
|
||||
}
|
||||
|
||||
/* Create a mutex */
|
||||
SDL_mutex *
|
||||
SDL_CreateMutex(void)
|
||||
{
|
||||
RMutex rmutex;
|
||||
|
||||
TInt status = CreateUnique(NewMutex, &rmutex, NULL);
|
||||
if(status != KErrNone)
|
||||
{
|
||||
SDL_SetError("Couldn't create mutex.");
|
||||
}
|
||||
SDL_mutex* mutex = new /*(ELeave)*/ SDL_mutex;
|
||||
mutex->handle = rmutex.Handle();
|
||||
return(mutex);
|
||||
}
|
||||
|
||||
/* Free the mutex */
|
||||
void
|
||||
SDL_DestroyMutex(SDL_mutex * mutex)
|
||||
{
|
||||
if (mutex)
|
||||
{
|
||||
RMutex rmutex;
|
||||
rmutex.SetHandle(mutex->handle);
|
||||
rmutex.Signal();
|
||||
rmutex.Close();
|
||||
delete(mutex);
|
||||
mutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Try to lock the mutex */
|
||||
#if 0
|
||||
int
|
||||
SDL_TryLockMutex(SDL_mutex * mutex)
|
||||
{
|
||||
if (mutex == NULL)
|
||||
{
|
||||
SDL_SetError("Passed a NULL mutex.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Not yet implemented.
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Lock the mutex */
|
||||
int
|
||||
SDL_LockMutex(SDL_mutex * mutex)
|
||||
{
|
||||
if (mutex == NULL)
|
||||
{
|
||||
SDL_SetError("Passed a NULL mutex.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
RMutex rmutex;
|
||||
rmutex.SetHandle(mutex->handle);
|
||||
rmutex.Wait();
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Unlock the mutex */
|
||||
int
|
||||
SDL_UnlockMutex(SDL_mutex * mutex)
|
||||
{
|
||||
if ( mutex == NULL )
|
||||
{
|
||||
SDL_SetError("Passed a NULL mutex.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
RMutex rmutex;
|
||||
rmutex.SetHandle(mutex->handle);
|
||||
rmutex.Signal();
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
195
externals/SDL/src/thread/ngage/SDL_syssem.cpp
vendored
Executable file
195
externals/SDL/src/thread/ngage/SDL_syssem.cpp
vendored
Executable file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
/* An implementation of semaphores using the Symbian API. */
|
||||
|
||||
#include <e32std.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
#define SDL_MUTEX_TIMEOUT -2
|
||||
|
||||
struct SDL_semaphore
|
||||
{
|
||||
TInt handle;
|
||||
TInt count;
|
||||
};
|
||||
|
||||
struct TInfo
|
||||
{
|
||||
TInfo(TInt aTime, TInt aHandle) :
|
||||
iTime(aTime), iHandle(aHandle), iVal(0) {}
|
||||
TInt iTime;
|
||||
TInt iHandle;
|
||||
TInt iVal;
|
||||
};
|
||||
|
||||
extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
|
||||
|
||||
static TBool RunThread(TAny* aInfo)
|
||||
{
|
||||
TInfo* info = STATIC_CAST(TInfo*, aInfo);
|
||||
User::After(info->iTime);
|
||||
RSemaphore sema;
|
||||
sema.SetHandle(info->iHandle);
|
||||
sema.Signal();
|
||||
info->iVal = SDL_MUTEX_TIMEOUT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static TInt
|
||||
NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
|
||||
{
|
||||
return ((RThread*)(aPtr1))->Create
|
||||
(aName,
|
||||
RunThread,
|
||||
KDefaultStackSize,
|
||||
NULL,
|
||||
aPtr2);
|
||||
}
|
||||
|
||||
static TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
|
||||
{
|
||||
TInt value = *((TInt*) aPtr2);
|
||||
return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value);
|
||||
}
|
||||
|
||||
static void WaitAll(SDL_sem *sem)
|
||||
{
|
||||
RSemaphore sema;
|
||||
sema.SetHandle(sem->handle);
|
||||
sema.Wait();
|
||||
while(sem->count < 0)
|
||||
{
|
||||
sema.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_sem *
|
||||
SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
RSemaphore s;
|
||||
TInt status = CreateUnique(NewSema, &s, &initial_value);
|
||||
if(status != KErrNone)
|
||||
{
|
||||
SDL_SetError("Couldn't create semaphore");
|
||||
}
|
||||
SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore;
|
||||
sem->handle = s.Handle();
|
||||
sem->count = initial_value;
|
||||
return(sem);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DestroySemaphore(SDL_sem * sem)
|
||||
{
|
||||
if (sem)
|
||||
{
|
||||
RSemaphore sema;
|
||||
sema.SetHandle(sem->handle);
|
||||
sema.Signal(sema.Count());
|
||||
sema.Close();
|
||||
delete sem;
|
||||
sem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||
{
|
||||
if (! sem)
|
||||
{
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (timeout == SDL_MUTEX_MAXWAIT)
|
||||
{
|
||||
WaitAll(sem);
|
||||
return SDL_MUTEX_MAXWAIT;
|
||||
}
|
||||
|
||||
RThread thread;
|
||||
TInfo* info = new (ELeave)TInfo(timeout, sem->handle);
|
||||
TInt status = CreateUnique(NewThread, &thread, info);
|
||||
|
||||
if(status != KErrNone)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
thread.Resume();
|
||||
WaitAll(sem);
|
||||
|
||||
if(thread.ExitType() == EExitPending)
|
||||
{
|
||||
thread.Kill(SDL_MUTEX_TIMEOUT);
|
||||
}
|
||||
|
||||
thread.Close();
|
||||
return info->iVal;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemTryWait(SDL_sem *sem)
|
||||
{
|
||||
if(sem->count > 0)
|
||||
{
|
||||
sem->count--;
|
||||
}
|
||||
return SDL_MUTEX_TIMEOUT;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWait(SDL_sem * sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_SemValue(SDL_sem * sem)
|
||||
{
|
||||
if (! sem)
|
||||
{
|
||||
SDL_SetError("Passed a NULL sem.");
|
||||
return 0;
|
||||
}
|
||||
return sem->count;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemPost(SDL_sem * sem)
|
||||
{
|
||||
if (! sem)
|
||||
{
|
||||
SDL_SetError("Passed a NULL sem.");
|
||||
return -1;
|
||||
}
|
||||
sem->count++;
|
||||
RSemaphore sema;
|
||||
sema.SetHandle(sem->handle);
|
||||
sema.Signal();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
134
externals/SDL/src/thread/ngage/SDL_systhread.cpp
vendored
Executable file
134
externals/SDL/src/thread/ngage/SDL_systhread.cpp
vendored
Executable file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_THREAD_NGAGE
|
||||
|
||||
/* N-Gage thread management routines for SDL */
|
||||
|
||||
#include <e32std.h>
|
||||
|
||||
extern "C" {
|
||||
#undef NULL
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../SDL_systhread.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
};
|
||||
|
||||
static int object_count;
|
||||
|
||||
static int
|
||||
RunThread(TAny* data)
|
||||
{
|
||||
SDL_RunThread((SDL_Thread*)data);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static TInt
|
||||
NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
|
||||
{
|
||||
return ((RThread*)(aPtr1))->Create
|
||||
(aName,
|
||||
RunThread,
|
||||
KDefaultStackSize,
|
||||
NULL,
|
||||
aPtr2);
|
||||
}
|
||||
|
||||
int
|
||||
CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2)
|
||||
{
|
||||
TBuf<16> name;
|
||||
TInt status = KErrNone;
|
||||
do
|
||||
{
|
||||
object_count++;
|
||||
name.Format(_L("SDL_%x"), object_count);
|
||||
status = aFunc(name, aPtr1, aPtr2);
|
||||
}
|
||||
while(status == KErrAlreadyExists);
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
RThread rthread;
|
||||
|
||||
TInt status = CreateUnique(NewThread, &rthread, thread);
|
||||
if (status != KErrNone)
|
||||
{
|
||||
delete(((RThread*)(thread->handle)));
|
||||
thread->handle = NULL;
|
||||
SDL_SetError("Not enough resources to create thread");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
rthread.Resume();
|
||||
thread->handle = rthread.Handle();
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_threadID
|
||||
SDL_ThreadID(void)
|
||||
{
|
||||
RThread current;
|
||||
TThreadId id = current.Id();
|
||||
return id;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
{
|
||||
RThread t;
|
||||
t.Open(thread->threadid);
|
||||
if(t.ExitReason() == EExitPending)
|
||||
{
|
||||
TRequestStatus status;
|
||||
t.Logon(status);
|
||||
User::WaitForRequest(status);
|
||||
}
|
||||
t.Close();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_NGAGE */
|
||||
|
||||
/* vim: ts=4 sw=4
|
||||
*/
|
25
externals/SDL/src/thread/ngage/SDL_systhread_c.h
vendored
Executable file
25
externals/SDL/src/thread/ngage/SDL_systhread_c.h
vendored
Executable file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
typedef int SYS_ThreadHandle;
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
18
externals/SDL/src/thread/os2/SDL_sysmutex.c
vendored
18
externals/SDL/src/thread/os2/SDL_sysmutex.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -56,12 +56,12 @@ SDL_CreateMutex(void)
|
||||
void
|
||||
SDL_DestroyMutex(SDL_mutex * mutex)
|
||||
{
|
||||
ULONG ulRC;
|
||||
HMTX hMtx = (HMTX)mutex;
|
||||
|
||||
ulRC = DosCloseMutexSem(hMtx);
|
||||
if (ulRC != NO_ERROR) {
|
||||
debug_os2("DosCloseMutexSem(), rc = %u", ulRC);
|
||||
if (hMtx != NULLHANDLE) {
|
||||
const ULONG ulRC = DosCloseMutexSem(hMtx);
|
||||
if (ulRC != NO_ERROR) {
|
||||
debug_os2("DosCloseMutexSem(), rc = %u", ulRC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ SDL_LockMutex(SDL_mutex * mutex)
|
||||
HMTX hMtx = (HMTX)mutex;
|
||||
|
||||
if (hMtx == NULLHANDLE)
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
|
||||
ulRC = DosRequestMutexSem(hMtx, SEM_INDEFINITE_WAIT);
|
||||
if (ulRC != NO_ERROR) {
|
||||
@@ -92,7 +92,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
|
||||
HMTX hMtx = (HMTX)mutex;
|
||||
|
||||
if (hMtx == NULLHANDLE)
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
|
||||
ulRC = DosRequestMutexSem(hMtx, SEM_IMMEDIATE_RETURN);
|
||||
|
||||
@@ -115,7 +115,7 @@ SDL_UnlockMutex(SDL_mutex * mutex)
|
||||
HMTX hMtx = (HMTX)mutex;
|
||||
|
||||
if (hMtx == NULLHANDLE)
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
|
||||
ulRC = DosReleaseMutexSem(hMtx);
|
||||
if (ulRC != NO_ERROR)
|
||||
|
8
externals/SDL/src/thread/os2/SDL_syssem.c
vendored
8
externals/SDL/src/thread/os2/SDL_syssem.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -89,7 +89,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||
ULONG cPost;
|
||||
|
||||
if (sem == NULL)
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
|
||||
if (timeout != SEM_INDEFINITE_WAIT)
|
||||
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulStartTime, sizeof(ULONG));
|
||||
@@ -147,7 +147,7 @@ SDL_SemValue(SDL_sem * sem)
|
||||
ULONG ulRC;
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ SDL_SemPost(SDL_sem * sem)
|
||||
ULONG ulRC;
|
||||
|
||||
if (sem == NULL)
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
|
||||
ulRC = DosRequestMutexSem(sem->hMtx, SEM_INDEFINITE_WAIT);
|
||||
if (ulRC != NO_ERROR)
|
||||
|
2
externals/SDL/src/thread/os2/SDL_systhread.c
vendored
2
externals/SDL/src/thread/os2/SDL_systhread.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
2
externals/SDL/src/thread/os2/SDL_systls.c
vendored
2
externals/SDL/src/thread/os2/SDL_systls.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
2
externals/SDL/src/thread/os2/SDL_systls_c.h
vendored
2
externals/SDL/src/thread/os2/SDL_systls_c.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
159
externals/SDL/src/thread/ps2/SDL_syssem.c
vendored
Executable file
159
externals/SDL/src/thread/ps2/SDL_syssem.c
vendored
Executable file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_THREAD_PS2
|
||||
|
||||
/* Semaphore functions for the PS2. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <timer_alarm.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
#include <kernel.h>
|
||||
|
||||
struct SDL_semaphore {
|
||||
s32 semid;
|
||||
};
|
||||
|
||||
static void usercb(struct timer_alarm_t *alarm, void *arg) {
|
||||
iReleaseWaitThread((int)arg);
|
||||
}
|
||||
|
||||
/* Create a semaphore */
|
||||
SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_sem *sem;
|
||||
ee_sema_t sema;
|
||||
|
||||
sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
sema.init_count = initial_value;
|
||||
sema.max_count = 255;
|
||||
sema.option = 0;
|
||||
sem->semid = CreateSema(&sema);
|
||||
|
||||
if (sem->semid < 0) {
|
||||
SDL_SetError("Couldn't create semaphore");
|
||||
SDL_free(sem);
|
||||
sem = NULL;
|
||||
}
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
return sem;
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
void SDL_DestroySemaphore(SDL_sem *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem->semid > 0) {
|
||||
DeleteSema(sem->semid);
|
||||
sem->semid = 0;
|
||||
}
|
||||
|
||||
SDL_free(sem);
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
{
|
||||
int ret;
|
||||
struct timer_alarm_t alarm;
|
||||
InitializeTimerAlarm(&alarm);
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (timeout == 0) {
|
||||
if (PollSema(sem->semid) < 0) {
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (timeout != SDL_MUTEX_MAXWAIT) {
|
||||
SetTimerAlarm(&alarm, MSec2TimerBusClock(timeout), &usercb, (void *)GetThreadId());
|
||||
}
|
||||
|
||||
ret = WaitSema(sem->semid);
|
||||
StopTimerAlarm(&alarm);
|
||||
|
||||
if (ret < 0)
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
return 0; //Wait condition satisfied.
|
||||
}
|
||||
|
||||
int SDL_SemTryWait(SDL_sem *sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, 0);
|
||||
}
|
||||
|
||||
int SDL_SemWait(SDL_sem *sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
Uint32 SDL_SemValue(SDL_sem *sem)
|
||||
{
|
||||
ee_sema_t info;
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ReferSemaStatus(sem->semid, &info) >= 0) {
|
||||
return info.count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_SemPost(SDL_sem *sem)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
res = SignalSema(sem->semid);
|
||||
if (res < 0) {
|
||||
return SDL_SetError("sceKernelSignalSema() failed");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_PS2 */
|
||||
|
||||
/* vim: ts=4 sw=4
|
||||
*/
|
140
externals/SDL/src/thread/ps2/SDL_systhread.c
vendored
Executable file
140
externals/SDL/src/thread/ps2/SDL_systhread.c
vendored
Executable file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_THREAD_PS2
|
||||
|
||||
/* PS2 thread management routines for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../SDL_systhread.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
#include <kernel.h>
|
||||
|
||||
static void FinishThread(SDL_Thread *thread) {
|
||||
ee_thread_status_t info;
|
||||
int res;
|
||||
|
||||
res = ReferThreadStatus(thread->handle, &info);
|
||||
TerminateThread(thread->handle);
|
||||
DeleteThread(thread->handle);
|
||||
DeleteSema((int)thread->endfunc);
|
||||
|
||||
if (res > 0) {
|
||||
SDL_free(info.stack);
|
||||
}
|
||||
}
|
||||
|
||||
static int childThread(void *arg)
|
||||
{
|
||||
SDL_Thread *thread = (SDL_Thread *)arg;
|
||||
int res = thread->userfunc(thread->userdata);
|
||||
SignalSema((int)thread->endfunc);
|
||||
return res;
|
||||
}
|
||||
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
ee_thread_status_t status;
|
||||
ee_thread_t eethread;
|
||||
ee_sema_t sema;
|
||||
size_t stack_size;
|
||||
int priority = 32;
|
||||
|
||||
/* Set priority of new thread to the same as the current thread */
|
||||
// status.size = sizeof(ee_thread_t);
|
||||
if (ReferThreadStatus(GetThreadId(), &status) == 0) {
|
||||
priority = status.current_priority;
|
||||
}
|
||||
|
||||
stack_size = thread->stacksize ? ((int) thread->stacksize) : 0x1800;
|
||||
|
||||
|
||||
/* Create EE Thread */
|
||||
eethread.attr = 0;
|
||||
eethread.option = 0;
|
||||
eethread.func = &childThread;
|
||||
eethread.stack = SDL_malloc(stack_size);
|
||||
eethread.stack_size = stack_size;
|
||||
eethread.gp_reg = &_gp;
|
||||
eethread.initial_priority = priority;
|
||||
thread->handle = CreateThread(&eethread);
|
||||
|
||||
if (thread->handle < 0) {
|
||||
return SDL_SetError("CreateThread() failed");
|
||||
}
|
||||
|
||||
// Prepare el semaphore for the ending function
|
||||
sema.init_count = 0;
|
||||
sema.max_count = 1;
|
||||
sema.option = 0;
|
||||
thread->endfunc = (void *)CreateSema(&sema);
|
||||
|
||||
return StartThread(thread->handle, thread);
|
||||
}
|
||||
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* Do nothing. */
|
||||
}
|
||||
|
||||
SDL_threadID SDL_ThreadID(void)
|
||||
{
|
||||
return (SDL_threadID) GetThreadId();
|
||||
}
|
||||
|
||||
void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
{
|
||||
WaitSema((int)thread->endfunc);
|
||||
ReleaseWaitThread(thread->handle);
|
||||
FinishThread(thread);
|
||||
}
|
||||
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
/* Do nothing. */
|
||||
}
|
||||
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||
value = 111;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
value = 32;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
|
||||
value = 16;
|
||||
} else {
|
||||
value = 50;
|
||||
}
|
||||
|
||||
return ChangeThreadPriority(GetThreadId(),value);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_PS2 */
|
||||
|
||||
/* vim: ts=4 sw=4
|
||||
*/
|
24
externals/SDL/src/thread/ps2/SDL_systhread_c.h
vendored
Executable file
24
externals/SDL/src/thread/ps2/SDL_systhread_c.h
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int32_t SYS_ThreadHandle;
|
8
externals/SDL/src/thread/psp/SDL_syscond.c
vendored
8
externals/SDL/src/thread/psp/SDL_syscond.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -84,7 +84,7 @@ int
|
||||
SDL_CondSignal(SDL_cond * cond)
|
||||
{
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* If there are waiting threads not already signalled, then
|
||||
@@ -108,7 +108,7 @@ int
|
||||
SDL_CondBroadcast(SDL_cond * cond)
|
||||
{
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* If there are waiting threads not already signalled, then
|
||||
@@ -164,7 +164,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
int retval;
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* Obtain the protection mutex, and increment the number of waiters.
|
||||
|
108
externals/SDL/src/thread/psp/SDL_sysmutex.c
vendored
108
externals/SDL/src/thread/psp/SDL_sysmutex.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -27,30 +27,37 @@
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_systhread_c.h"
|
||||
|
||||
#include <pspthreadman.h>
|
||||
#include <pspkerror.h>
|
||||
|
||||
#define SCE_KERNEL_MUTEX_ATTR_RECURSIVE 0x0200U
|
||||
|
||||
struct SDL_mutex
|
||||
{
|
||||
int recursive;
|
||||
SDL_threadID owner;
|
||||
SDL_sem *sem;
|
||||
SceLwMutexWorkarea lock;
|
||||
};
|
||||
|
||||
/* Create a mutex */
|
||||
SDL_mutex *
|
||||
SDL_CreateMutex(void)
|
||||
{
|
||||
SDL_mutex *mutex;
|
||||
SDL_mutex *mutex = NULL;
|
||||
SceInt32 res = 0;
|
||||
|
||||
/* Allocate mutex memory */
|
||||
mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
|
||||
if (mutex) {
|
||||
/* Create the mutex semaphore, with initial value 1 */
|
||||
mutex->sem = SDL_CreateSemaphore(1);
|
||||
mutex->recursive = 0;
|
||||
mutex->owner = 0;
|
||||
if (!mutex->sem) {
|
||||
SDL_free(mutex);
|
||||
mutex = NULL;
|
||||
|
||||
res = sceKernelCreateLwMutex(
|
||||
&mutex->lock,
|
||||
"SDL mutex",
|
||||
SCE_KERNEL_MUTEX_ATTR_RECURSIVE,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (res < 0) {
|
||||
SDL_SetError("Error trying to create mutex: %x", res);
|
||||
}
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
@@ -63,37 +70,56 @@ void
|
||||
SDL_DestroyMutex(SDL_mutex * mutex)
|
||||
{
|
||||
if (mutex) {
|
||||
if (mutex->sem) {
|
||||
SDL_DestroySemaphore(mutex->sem);
|
||||
}
|
||||
sceKernelDeleteLwMutex(&mutex->lock);
|
||||
SDL_free(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
/* Lock the semaphore */
|
||||
/* Try to lock the mutex */
|
||||
int
|
||||
SDL_TryLockMutex(SDL_mutex * mutex)
|
||||
{
|
||||
#if SDL_THREADS_DISABLED
|
||||
return 0;
|
||||
#else
|
||||
SceInt32 res = 0;
|
||||
if (mutex == NULL) {
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
res = sceKernelTryLockLwMutex(&mutex->lock, 1);
|
||||
switch (res) {
|
||||
case SCE_KERNEL_ERROR_OK:
|
||||
return 0;
|
||||
break;
|
||||
case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
break;
|
||||
default:
|
||||
return SDL_SetError("Error trying to lock mutex: %x", res);
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
#endif /* SDL_THREADS_DISABLED */
|
||||
}
|
||||
|
||||
|
||||
/* Lock the mutex */
|
||||
int
|
||||
SDL_mutexP(SDL_mutex * mutex)
|
||||
{
|
||||
#if SDL_THREADS_DISABLED
|
||||
return 0;
|
||||
#else
|
||||
SDL_threadID this_thread;
|
||||
|
||||
SceInt32 res = 0;
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
this_thread = SDL_ThreadID();
|
||||
if (mutex->owner == this_thread) {
|
||||
++mutex->recursive;
|
||||
} else {
|
||||
/* The order of operations is important.
|
||||
We set the locking thread id after we obtain the lock
|
||||
so unlocks from other threads will fail.
|
||||
*/
|
||||
SDL_SemWait(mutex->sem);
|
||||
mutex->owner = this_thread;
|
||||
mutex->recursive = 0;
|
||||
res = sceKernelLockLwMutex(&mutex->lock, 1, NULL);
|
||||
if (res != SCE_KERNEL_ERROR_OK) {
|
||||
return SDL_SetError("Error trying to lock mutex: %x", res);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -107,30 +133,20 @@ SDL_mutexV(SDL_mutex * mutex)
|
||||
#if SDL_THREADS_DISABLED
|
||||
return 0;
|
||||
#else
|
||||
SceInt32 res = 0;
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
/* If we don't own the mutex, we can't unlock it */
|
||||
if (SDL_ThreadID() != mutex->owner) {
|
||||
return SDL_SetError("mutex not owned by this thread");
|
||||
res = sceKernelUnlockLwMutex(&mutex->lock, 1);
|
||||
if (res != 0) {
|
||||
return SDL_SetError("Error trying to unlock mutex: %x", res);
|
||||
}
|
||||
|
||||
if (mutex->recursive) {
|
||||
--mutex->recursive;
|
||||
} else {
|
||||
/* The order of operations is important.
|
||||
First reset the owner so another thread doesn't lock
|
||||
the mutex and set the ownership before we reset it,
|
||||
then release the lock semaphore.
|
||||
*/
|
||||
mutex->owner = 0;
|
||||
SDL_SemPost(mutex->sem);
|
||||
}
|
||||
return 0;
|
||||
#endif /* SDL_THREADS_DISABLED */
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_PSP */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
8
externals/SDL/src/thread/psp/SDL_syssem.c
vendored
8
externals/SDL/src/thread/psp/SDL_syssem.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -82,7 +82,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ Uint32 SDL_SemValue(SDL_sem *sem)
|
||||
SceKernelSemaInfo info;
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ int SDL_SemPost(SDL_sem *sem)
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
res = sceKernelSignalSema(sem->semid, 1);
|
||||
|
10
externals/SDL/src/thread/psp/SDL_systhread.c
vendored
10
externals/SDL/src/thread/psp/SDL_systhread.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -95,13 +95,13 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
int value;
|
||||
|
||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||
value = 19;
|
||||
value = 111;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
value = -10;
|
||||
value = 32;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
|
||||
value = -20;
|
||||
value = 16;
|
||||
} else {
|
||||
value = 0;
|
||||
value = 50;
|
||||
}
|
||||
|
||||
return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
10
externals/SDL/src/thread/pthread/SDL_syscond.c
vendored
10
externals/SDL/src/thread/pthread/SDL_syscond.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -68,7 +68,7 @@ SDL_CondSignal(SDL_cond * cond)
|
||||
int retval;
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
retval = 0;
|
||||
@@ -85,7 +85,7 @@ SDL_CondBroadcast(SDL_cond * cond)
|
||||
int retval;
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
retval = 0;
|
||||
@@ -105,7 +105,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
struct timespec abstime;
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
@@ -148,7 +148,7 @@ int
|
||||
SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
|
||||
{
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
} else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) {
|
||||
return SDL_SetError("pthread_cond_wait() failed");
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -85,7 +85,7 @@ SDL_LockMutex(SDL_mutex * mutex)
|
||||
#endif
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
#if FAKE_RECURSIVE_MUTEX
|
||||
@@ -122,7 +122,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
|
||||
#endif
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
retval = 0;
|
||||
@@ -162,7 +162,7 @@ int
|
||||
SDL_UnlockMutex(SDL_mutex * mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
#if FAKE_RECURSIVE_MUTEX
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
10
externals/SDL/src/thread/pthread/SDL_syssem.c
vendored
10
externals/SDL/src/thread/pthread/SDL_syssem.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -73,7 +73,7 @@ SDL_SemTryWait(SDL_sem * sem)
|
||||
int retval;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
if (sem_trywait(&sem->sem) == 0) {
|
||||
@@ -88,7 +88,7 @@ SDL_SemWait(SDL_sem * sem)
|
||||
int retval;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -115,7 +115,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||
#endif
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
/* Try the easy cases first */
|
||||
@@ -195,7 +195,7 @@ SDL_SemPost(SDL_sem * sem)
|
||||
int retval;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
retval = sem_post(&sem->sem);
|
||||
|
21
externals/SDL/src/thread/pthread/SDL_systhread.c
vendored
21
externals/SDL/src/thread/pthread/SDL_systhread.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -30,13 +30,13 @@
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __LINUX__
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../../core/linux/SDL_dbus.h"
|
||||
#endif /* __LINUX__ */
|
||||
@@ -137,22 +137,29 @@ SDL_SYS_SetupThread(const char *name)
|
||||
#if defined(__MACOSX__) || defined(__IPHONEOS__)
|
||||
ppthread_setname_np(name);
|
||||
#elif defined(__LINUX__)
|
||||
ppthread_setname_np(pthread_self(), name);
|
||||
if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
|
||||
char namebuf[16]; /* Limited to 16 char */
|
||||
SDL_strlcpy(namebuf, name, sizeof (namebuf));
|
||||
ppthread_setname_np(pthread_self(), namebuf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#elif HAVE_PTHREAD_SETNAME_NP
|
||||
#if defined(__NETBSD__)
|
||||
pthread_setname_np(pthread_self(), "%s", name);
|
||||
#else
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
if (pthread_setname_np(pthread_self(), name) == ERANGE) {
|
||||
char namebuf[16]; /* Limited to 16 char */
|
||||
SDL_strlcpy(namebuf, name, sizeof (namebuf));
|
||||
pthread_setname_np(pthread_self(), namebuf);
|
||||
}
|
||||
#endif
|
||||
#elif HAVE_PTHREAD_SET_NAME_NP
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#elif defined(__HAIKU__)
|
||||
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
|
||||
char namebuf[B_OS_NAME_LENGTH];
|
||||
SDL_snprintf(namebuf, sizeof (namebuf), "%s", name);
|
||||
namebuf[sizeof (namebuf) - 1] = '\0';
|
||||
SDL_strlcpy(namebuf, name, sizeof (namebuf));
|
||||
rename_thread(find_thread(NULL), namebuf);
|
||||
#endif
|
||||
}
|
||||
@@ -186,7 +193,7 @@ SDL_ThreadID(void)
|
||||
int
|
||||
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
#if __NACL__ || __RISCOS__
|
||||
#if __NACL__ || __RISCOS__ || __OS2__
|
||||
/* FIXME: Setting thread priority does not seem to be supported in NACL */
|
||||
return 0;
|
||||
#else
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
17
externals/SDL/src/thread/stdcpp/SDL_syscond.cpp
vendored
17
externals/SDL/src/thread/stdcpp/SDL_syscond.cpp
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -70,8 +70,7 @@ int
|
||||
SDL_CondSignal(SDL_cond * cond)
|
||||
{
|
||||
if (!cond) {
|
||||
SDL_SetError("Passed a NULL condition variable");
|
||||
return -1;
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
cond->cpp_cond.notify_one();
|
||||
@@ -84,8 +83,7 @@ int
|
||||
SDL_CondBroadcast(SDL_cond * cond)
|
||||
{
|
||||
if (!cond) {
|
||||
SDL_SetError("Passed a NULL condition variable");
|
||||
return -1;
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
cond->cpp_cond.notify_all();
|
||||
@@ -118,13 +116,11 @@ int
|
||||
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
{
|
||||
if (!cond) {
|
||||
SDL_SetError("Passed a NULL condition variable");
|
||||
return -1;
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
if (!mutex) {
|
||||
SDL_SetError("Passed a NULL mutex variable");
|
||||
return -1;
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -148,8 +144,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
}
|
||||
}
|
||||
} catch (std::system_error & ex) {
|
||||
SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
|
||||
return -1;
|
||||
return SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
13
externals/SDL/src/thread/stdcpp/SDL_sysmutex.cpp
vendored
13
externals/SDL/src/thread/stdcpp/SDL_sysmutex.cpp
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -65,16 +65,14 @@ int
|
||||
SDL_mutexP(SDL_mutex * mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
SDL_SetError("Passed a NULL mutex");
|
||||
return -1;
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
try {
|
||||
mutex->cpp_mutex.lock();
|
||||
return 0;
|
||||
} catch (std::system_error & ex) {
|
||||
SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
|
||||
return -1;
|
||||
return SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +82,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
|
||||
{
|
||||
int retval = 0;
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
if (mutex->cpp_mutex.try_lock() == false) {
|
||||
@@ -99,8 +97,7 @@ int
|
||||
SDL_mutexV(SDL_mutex * mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
SDL_SetError("Passed a NULL mutex");
|
||||
return -1;
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
mutex->cpp_mutex.unlock();
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -52,11 +52,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread)
|
||||
thread->handle = (void *) new std::thread(std::move(cpp_thread));
|
||||
return 0;
|
||||
} catch (std::system_error & ex) {
|
||||
SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
|
||||
return -1;
|
||||
return SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
|
||||
} catch (std::bad_alloc &) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
8
externals/SDL/src/thread/vita/SDL_syscond.c
vendored
8
externals/SDL/src/thread/vita/SDL_syscond.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -84,7 +84,7 @@ int
|
||||
SDL_CondSignal(SDL_cond * cond)
|
||||
{
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* If there are waiting threads not already signalled, then
|
||||
@@ -108,7 +108,7 @@ int
|
||||
SDL_CondBroadcast(SDL_cond * cond)
|
||||
{
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* If there are waiting threads not already signalled, then
|
||||
@@ -164,7 +164,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
int retval;
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
/* Obtain the protection mutex, and increment the number of waiters.
|
||||
|
8
externals/SDL/src/thread/vita/SDL_sysmutex.c
vendored
8
externals/SDL/src/thread/vita/SDL_sysmutex.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -80,7 +80,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
|
||||
#else
|
||||
SceInt32 res = 0;
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
res = sceKernelTryLockLwMutex(&mutex->lock, 1);
|
||||
@@ -110,7 +110,7 @@ SDL_mutexP(SDL_mutex * mutex)
|
||||
#else
|
||||
SceInt32 res = 0;
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
res = sceKernelLockLwMutex(&mutex->lock, 1, NULL);
|
||||
@@ -132,7 +132,7 @@ SDL_mutexV(SDL_mutex * mutex)
|
||||
SceInt32 res = 0;
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
res = sceKernelUnlockLwMutex(&mutex->lock, 1);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
8
externals/SDL/src/thread/vita/SDL_syssem.c
vendored
8
externals/SDL/src/thread/vita/SDL_syssem.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -83,7 +83,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
unsigned int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ Uint32 SDL_SemValue(SDL_sem *sem)
|
||||
info.size = sizeof(info);
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ int SDL_SemPost(SDL_sem *sem)
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
res = sceKernelSignalSema(sem->semid, 1);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -109,7 +109,7 @@ SDL_CondSignal_cv(SDL_cond * _cond)
|
||||
{
|
||||
SDL_cond_cv *cond = (SDL_cond_cv *)_cond;
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
pWakeConditionVariable(&cond->cond);
|
||||
@@ -122,7 +122,7 @@ SDL_CondBroadcast_cv(SDL_cond * _cond)
|
||||
{
|
||||
SDL_cond_cv *cond = (SDL_cond_cv *)_cond;
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
pWakeAllConditionVariable(&cond->cond);
|
||||
@@ -138,10 +138,10 @@ SDL_CondWaitTimeout_cv(SDL_cond * _cond, SDL_mutex * _mutex, Uint32 ms)
|
||||
int ret;
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
if (!_mutex) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
if (ms == SDL_MUTEX_MAXWAIT) {
|
||||
|
14
externals/SDL/src/thread/windows/SDL_sysmutex.c
vendored
14
externals/SDL/src/thread/windows/SDL_sysmutex.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -88,7 +88,7 @@ SDL_LockMutex_srw(SDL_mutex * _mutex)
|
||||
DWORD this_thread;
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
this_thread = GetCurrentThreadId();
|
||||
@@ -115,7 +115,7 @@ SDL_TryLockMutex_srw(SDL_mutex * _mutex)
|
||||
int retval = 0;
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
this_thread = GetCurrentThreadId();
|
||||
@@ -139,7 +139,7 @@ SDL_UnlockMutex_srw(SDL_mutex * _mutex)
|
||||
SDL_mutex_srw *mutex = (SDL_mutex_srw *)_mutex;
|
||||
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
if (mutex->owner == GetCurrentThreadId()) {
|
||||
@@ -208,7 +208,7 @@ SDL_LockMutex_cs(SDL_mutex * mutex_)
|
||||
{
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
EnterCriticalSection(&mutex->cs);
|
||||
@@ -222,7 +222,7 @@ SDL_TryLockMutex_cs(SDL_mutex * mutex_)
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
|
||||
int retval = 0;
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
if (TryEnterCriticalSection(&mutex->cs) == 0) {
|
||||
@@ -237,7 +237,7 @@ SDL_UnlockMutex_cs(SDL_mutex * mutex_)
|
||||
{
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&mutex->cs);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
18
externals/SDL/src/thread/windows/SDL_syssem.c
vendored
18
externals/SDL/src/thread/windows/SDL_syssem.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -122,7 +122,7 @@ SDL_SemTryWait_atom(SDL_sem * _sem)
|
||||
LONG count;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
count = sem->count;
|
||||
@@ -144,7 +144,7 @@ SDL_SemWait_atom(SDL_sem * _sem)
|
||||
LONG count;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -176,7 +176,7 @@ SDL_SemWaitTimeout_atom(SDL_sem * _sem, Uint32 timeout)
|
||||
}
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +219,7 @@ SDL_SemValue_atom(SDL_sem * _sem)
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
|
||||
if (!sem) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ SDL_SemPost_atom(SDL_sem * _sem)
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
InterlockedIncrement(&sem->count);
|
||||
@@ -313,7 +313,7 @@ SDL_SemWaitTimeout_kern(SDL_sem * _sem, Uint32 timeout)
|
||||
DWORD dwMilliseconds;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
if (timeout == SDL_MUTEX_MAXWAIT) {
|
||||
@@ -354,7 +354,7 @@ SDL_SemValue_kern(SDL_sem * _sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (!sem) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
return (Uint32)sem->count;
|
||||
@@ -365,7 +365,7 @@ SDL_SemPost_kern(SDL_sem * _sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
/* Increase the counter in the first place, because
|
||||
* after a successful release the semaphore may
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
Reference in New Issue
Block a user