WinRT: merged with latest SDL 2.x/HG code
SDL 2.x recently accepted patches to enable OpenGL ES 2 support via Google's ANGLE library. The thought is to try to eventually merge SDL/WinRT's OpenGL code with SDL-official's.
This commit is contained in:
commit
ebfac58560
999 changed files with 140431 additions and 5035 deletions
|
@ -51,6 +51,9 @@ extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority);
|
|||
*/
|
||||
extern void SDL_SYS_WaitThread(SDL_Thread * thread);
|
||||
|
||||
/* Mark thread as cleaned up as soon as it exits, without joining. */
|
||||
extern void SDL_SYS_DetachThread(SDL_Thread * thread);
|
||||
|
||||
/* Get the thread local storage for this thread */
|
||||
extern SDL_TLSData *SDL_SYS_GetTLSData();
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
/* System independent thread management routines for SDL */
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_thread_c.h"
|
||||
#include "SDL_systhread.h"
|
||||
|
@ -265,13 +266,14 @@ SDL_RunThread(void *data)
|
|||
thread_args *args = (thread_args *) data;
|
||||
int (SDLCALL * userfunc) (void *) = args->func;
|
||||
void *userdata = args->data;
|
||||
int *statusloc = &args->info->status;
|
||||
SDL_Thread *thread = args->info;
|
||||
int *statusloc = &thread->status;
|
||||
|
||||
/* Perform any system-dependent setup - this function may not fail */
|
||||
SDL_SYS_SetupThread(args->info->name);
|
||||
SDL_SYS_SetupThread(thread->name);
|
||||
|
||||
/* Get the thread id */
|
||||
args->info->threadid = SDL_ThreadID();
|
||||
thread->threadid = SDL_ThreadID();
|
||||
|
||||
/* Wake up the parent thread */
|
||||
SDL_SemPost(args->wait);
|
||||
|
@ -281,6 +283,17 @@ SDL_RunThread(void *data)
|
|||
|
||||
/* Clean up thread-local storage */
|
||||
SDL_TLSCleanup();
|
||||
|
||||
/* Mark us as ready to be joined (or detached) */
|
||||
if (!SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) {
|
||||
/* Clean up if something already detached us. */
|
||||
if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_CLEANED)) {
|
||||
if (thread->name) {
|
||||
SDL_free(thread->name);
|
||||
}
|
||||
SDL_free(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
|
@ -306,8 +319,9 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
|
|||
SDL_OutOfMemory();
|
||||
return (NULL);
|
||||
}
|
||||
SDL_memset(thread, 0, (sizeof *thread));
|
||||
SDL_zerop(thread);
|
||||
thread->status = -1;
|
||||
SDL_AtomicSet(&thread->state, SDL_THREAD_STATE_ALIVE);
|
||||
|
||||
/* Set up the arguments for the thread */
|
||||
if (name != NULL) {
|
||||
|
@ -410,4 +424,27 @@ SDL_WaitThread(SDL_Thread * thread, int *status)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Grab dibs if the state is alive+joinable. */
|
||||
if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED)) {
|
||||
SDL_SYS_DetachThread(thread);
|
||||
} else {
|
||||
/* all other states are pretty final, see where we landed. */
|
||||
const int state = SDL_AtomicGet(&thread->state);
|
||||
if ((state == SDL_THREAD_STATE_DETACHED) || (state == SDL_THREAD_STATE_CLEANED)) {
|
||||
return; /* already detached (you shouldn't call this twice!) */
|
||||
} else if (state == SDL_THREAD_STATE_ZOMBIE) {
|
||||
SDL_WaitThread(thread, NULL); /* already done, clean it up. */
|
||||
} else {
|
||||
SDL_assert(0 && "Unexpected thread state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -28,10 +28,6 @@
|
|||
/* Need the definitions of SYS_ThreadHandle */
|
||||
#if SDL_THREADS_DISABLED
|
||||
#include "generic/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_BEOS
|
||||
#include "beos/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_EPOC
|
||||
#include "epoc/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_PTHREAD
|
||||
#include "pthread/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_WINDOWS
|
||||
|
@ -46,12 +42,21 @@
|
|||
#endif
|
||||
#include "../SDL_error_c.h"
|
||||
|
||||
typedef enum SDL_ThreadState
|
||||
{
|
||||
SDL_THREAD_STATE_ALIVE,
|
||||
SDL_THREAD_STATE_DETACHED,
|
||||
SDL_THREAD_STATE_ZOMBIE,
|
||||
SDL_THREAD_STATE_CLEANED,
|
||||
} SDL_ThreadState;
|
||||
|
||||
/* This is the system-independent thread info structure */
|
||||
struct SDL_Thread
|
||||
{
|
||||
SDL_threadID threadid;
|
||||
SYS_ThreadHandle handle;
|
||||
int status;
|
||||
SDL_atomic_t state; /* SDL_THREAD_STATE_* */
|
||||
SDL_error errbuf;
|
||||
char *name;
|
||||
void *data;
|
||||
|
|
|
@ -1,151 +0,0 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifdef SDL_THREAD_BEOS
|
||||
|
||||
/* Semaphores in the BeOS environment */
|
||||
|
||||
#include <be/kernel/OS.h>
|
||||
|
||||
#include "SDL_thread.h"
|
||||
|
||||
|
||||
struct SDL_semaphore
|
||||
{
|
||||
sem_id id;
|
||||
};
|
||||
|
||||
/* Create a counting semaphore */
|
||||
SDL_sem *
|
||||
SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_sem *sem;
|
||||
|
||||
sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
|
||||
if (sem) {
|
||||
sem->id = create_sem(initial_value, "SDL semaphore");
|
||||
if (sem->id < B_NO_ERROR) {
|
||||
SDL_SetError("create_sem() failed");
|
||||
SDL_free(sem);
|
||||
sem = NULL;
|
||||
}
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
return (sem);
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
void
|
||||
SDL_DestroySemaphore(SDL_sem * sem)
|
||||
{
|
||||
if (sem) {
|
||||
if (sem->id >= B_NO_ERROR) {
|
||||
delete_sem(sem->id);
|
||||
}
|
||||
SDL_free(sem);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||
{
|
||||
int32 val;
|
||||
int retval;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
}
|
||||
|
||||
tryagain:
|
||||
if (timeout == SDL_MUTEX_MAXWAIT) {
|
||||
val = acquire_sem(sem->id);
|
||||
} else {
|
||||
timeout *= 1000; /* BeOS uses a timeout in microseconds */
|
||||
val = acquire_sem_etc(sem->id, 1, B_RELATIVE_TIMEOUT, timeout);
|
||||
}
|
||||
switch (val) {
|
||||
case B_INTERRUPTED:
|
||||
goto tryagain;
|
||||
case B_NO_ERROR:
|
||||
retval = 0;
|
||||
break;
|
||||
case B_TIMED_OUT:
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
break;
|
||||
case B_WOULD_BLOCK:
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
break;
|
||||
default:
|
||||
retval = SDL_SetError("acquire_sem() failed");
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int32 count;
|
||||
Uint32 value;
|
||||
|
||||
value = 0;
|
||||
if (sem) {
|
||||
get_sem_count(sem->id, &count);
|
||||
if (count > 0) {
|
||||
value = (Uint32) count;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Atomically increases the semaphore's count (not blocking) */
|
||||
int
|
||||
SDL_SemPost(SDL_sem * sem)
|
||||
{
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
}
|
||||
|
||||
if (release_sem(sem->id) != B_NO_ERROR) {
|
||||
return SDL_SetError("release_sem() failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_BEOS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifdef SDL_THREAD_BEOS
|
||||
|
||||
/* BeOS thread management routines for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <be/kernel/OS.h>
|
||||
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
#include "../SDL_systhread.h"
|
||||
|
||||
|
||||
static int sig_list[] = {
|
||||
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
|
||||
};
|
||||
|
||||
void
|
||||
SDL_MaskSignals(sigset_t * omask)
|
||||
{
|
||||
sigset_t mask;
|
||||
int i;
|
||||
|
||||
sigemptyset(&mask);
|
||||
for (i = 0; sig_list[i]; ++i) {
|
||||
sigaddset(&mask, sig_list[i]);
|
||||
}
|
||||
sigprocmask(SIG_BLOCK, &mask, omask);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UnmaskSignals(sigset_t * omask)
|
||||
{
|
||||
sigprocmask(SIG_SETMASK, omask, NULL);
|
||||
}
|
||||
|
||||
static int32
|
||||
RunThread(void *data)
|
||||
{
|
||||
SDL_RunThread(data);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||
{
|
||||
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
|
||||
const char *threadname = thread->name ? thread->name : "SDL Thread";
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
SDL_snprintf(name, sizeof (name), "%s", threadname);
|
||||
name[sizeof (name) - 1] = '\0';
|
||||
|
||||
/* Create the thread and go! */
|
||||
thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args);
|
||||
if ((thread->handle == B_NO_MORE_THREADS) ||
|
||||
(thread->handle == B_NO_MEMORY)) {
|
||||
return SDL_SetError("Not enough resources to create thread");
|
||||
}
|
||||
resume_thread(thread->handle);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* We set the thread name during SDL_SYS_CreateThread(). */
|
||||
/* Mask asynchronous signals for this thread */
|
||||
SDL_MaskSignals(NULL);
|
||||
}
|
||||
|
||||
SDL_threadID
|
||||
SDL_ThreadID(void)
|
||||
{
|
||||
return ((SDL_threadID) find_thread(NULL));
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
int32 value;
|
||||
|
||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||
value = B_LOW_PRIORITY;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
value = B_URGENT_DISPLAY_PRIORITY;
|
||||
} else {
|
||||
value = B_NORMAL_PRIORITY;
|
||||
}
|
||||
set_thread_priority(find_thread(NULL), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
{
|
||||
status_t the_status;
|
||||
|
||||
wait_for_thread(thread->handle, &the_status);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_BEOS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <be/kernel/OS.h>
|
||||
|
||||
typedef thread_id SYS_ThreadHandle;
|
||||
|
||||
/* Functions needed to work with system threads in other portions of SDL */
|
||||
extern void SDL_MaskSignals(sigset_t * omask);
|
||||
extern void SDL_UnmaskSignals(sigset_t * omask);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
|
||||
#if SDL_THREAD_BEOS
|
||||
|
||||
#include <support/TLS.h>
|
||||
|
||||
|
||||
static int32 thread_local_storage = B_NO_MEMORY;
|
||||
static SDL_bool generic_local_storage = SDL_FALSE;
|
||||
|
||||
SDL_TLSData *
|
||||
SDL_SYS_GetTLSData()
|
||||
{
|
||||
if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) {
|
||||
static SDL_SpinLock lock;
|
||||
SDL_AtomicLock(&lock);
|
||||
if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) {
|
||||
int32 storage = tls_allocate();
|
||||
if (storage != B_NO_MEMORY) {
|
||||
SDL_MemoryBarrierRelease();
|
||||
thread_local_storage = storage;
|
||||
} else {
|
||||
generic_local_storage = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
SDL_AtomicUnlock(&lock);
|
||||
}
|
||||
if (generic_local_storage) {
|
||||
return SDL_Generic_GetTLSData();
|
||||
}
|
||||
SDL_MemoryBarrierAcquire();
|
||||
return (SDL_TLSData *)tls_get(thread_local_storage);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetTLSData(SDL_TLSData *data)
|
||||
{
|
||||
if (generic_local_storage) {
|
||||
return SDL_Generic_SetTLSData(data);
|
||||
}
|
||||
tls_set(thread_local_storage, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_BEOS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -62,4 +62,10 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
|
|||
return;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -77,6 +77,12 @@ void SDL_SYS_WaitThread(SDL_Thread *thread)
|
|||
sceKernelDeleteThread(thread->handle);
|
||||
}
|
||||
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
/* !!! FIXME: is this correct? */
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
}
|
||||
|
||||
void SDL_SYS_KillThread(SDL_Thread *thread)
|
||||
{
|
||||
sceKernelTerminateDeleteThread(thread->handle);
|
||||
|
|
|
@ -51,6 +51,10 @@
|
|||
#include "../../core/android/SDL_android.h"
|
||||
#endif
|
||||
|
||||
#ifdef __HAIKU__
|
||||
#include <be/kernel/OS.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_assert.h"
|
||||
|
||||
/* List of signals to mask in the subthreads */
|
||||
|
@ -59,7 +63,6 @@ static const int sig_list[] = {
|
|||
SIGVTALRM, SIGPROF, 0
|
||||
};
|
||||
|
||||
|
||||
static void *
|
||||
RunThread(void *data)
|
||||
{
|
||||
|
@ -129,6 +132,12 @@ SDL_SYS_SetupThread(const char *name)
|
|||
pthread_setname_np(pthread_self(), name);
|
||||
#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';
|
||||
rename_thread(find_thread(NULL), namebuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -204,4 +213,10 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
|
|||
pthread_join(thread->handle, 0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
pthread_detach(thread->handle);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -234,6 +234,12 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
|
|||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_WINDOWS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue