mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-24 05:45:40 +00:00
Updates SDL to 2.0.5
This commit is contained in:
parent
00a4a21e3f
commit
1e671bfc7a
274 changed files with 11502 additions and 4656 deletions
|
|
@ -24,7 +24,7 @@
|
|||
#include "SDL_timer_c.h"
|
||||
#include "SDL_atomic.h"
|
||||
#include "SDL_cpuinfo.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../thread/SDL_systhread.h"
|
||||
|
||||
/* #define DEBUG_TIMERS */
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ typedef struct _SDL_Timer
|
|||
void *param;
|
||||
Uint32 interval;
|
||||
Uint32 scheduled;
|
||||
volatile SDL_bool canceled;
|
||||
SDL_atomic_t canceled;
|
||||
struct _SDL_Timer *next;
|
||||
} SDL_Timer;
|
||||
|
||||
|
|
@ -60,9 +60,9 @@ typedef struct {
|
|||
/* Data used to communicate with the timer thread */
|
||||
SDL_SpinLock lock;
|
||||
SDL_sem *sem;
|
||||
SDL_Timer * volatile pending;
|
||||
SDL_Timer * volatile freelist;
|
||||
volatile SDL_bool active;
|
||||
SDL_Timer *pending;
|
||||
SDL_Timer *freelist;
|
||||
SDL_atomic_t active;
|
||||
|
||||
/* List of timers - this is only touched by the timer thread */
|
||||
SDL_Timer *timers;
|
||||
|
|
@ -138,7 +138,7 @@ SDL_TimerThread(void *_data)
|
|||
freelist_tail = NULL;
|
||||
|
||||
/* Check to see if we're still running, after maintenance */
|
||||
if (!data->active) {
|
||||
if (!SDL_AtomicGet(&data->active)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ SDL_TimerThread(void *_data)
|
|||
/* We're going to do something with this timer */
|
||||
data->timers = current->next;
|
||||
|
||||
if (current->canceled) {
|
||||
if (SDL_AtomicGet(¤t->canceled)) {
|
||||
interval = 0;
|
||||
} else {
|
||||
interval = current->callback(current->interval, current->param);
|
||||
|
|
@ -179,7 +179,7 @@ SDL_TimerThread(void *_data)
|
|||
}
|
||||
freelist_tail = current;
|
||||
|
||||
current->canceled = SDL_TRUE;
|
||||
SDL_AtomicSet(¤t->canceled, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ SDL_TimerInit(void)
|
|||
{
|
||||
SDL_TimerData *data = &SDL_timer_data;
|
||||
|
||||
if (!data->active) {
|
||||
if (!SDL_AtomicGet(&data->active)) {
|
||||
const char *name = "SDLTimer";
|
||||
data->timermap_lock = SDL_CreateMutex();
|
||||
if (!data->timermap_lock) {
|
||||
|
|
@ -220,18 +220,10 @@ SDL_TimerInit(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
data->active = SDL_TRUE;
|
||||
/* !!! FIXME: this is nasty. */
|
||||
#if defined(__WIN32__) && !defined(HAVE_LIBC)
|
||||
#undef SDL_CreateThread
|
||||
#if SDL_DYNAMIC_API
|
||||
data->thread = SDL_CreateThread_REAL(SDL_TimerThread, name, data, NULL, NULL);
|
||||
#else
|
||||
data->thread = SDL_CreateThread(SDL_TimerThread, name, data, NULL, NULL);
|
||||
#endif
|
||||
#else
|
||||
data->thread = SDL_CreateThread(SDL_TimerThread, name, data);
|
||||
#endif
|
||||
SDL_AtomicSet(&data->active, 1);
|
||||
|
||||
/* Timer threads use a callback into the app, so we can't set a limited stack size here. */
|
||||
data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
|
||||
if (!data->thread) {
|
||||
SDL_TimerQuit();
|
||||
return -1;
|
||||
|
|
@ -249,9 +241,7 @@ SDL_TimerQuit(void)
|
|||
SDL_Timer *timer;
|
||||
SDL_TimerMap *entry;
|
||||
|
||||
if (data->active) {
|
||||
data->active = SDL_FALSE;
|
||||
|
||||
if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */
|
||||
/* Shutdown the timer thread */
|
||||
if (data->thread) {
|
||||
SDL_SemPost(data->sem);
|
||||
|
|
@ -291,21 +281,14 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
|
|||
SDL_Timer *timer;
|
||||
SDL_TimerMap *entry;
|
||||
|
||||
if (!data->active) {
|
||||
int status = 0;
|
||||
|
||||
SDL_AtomicLock(&data->lock);
|
||||
if (!data->active) {
|
||||
status = SDL_TimerInit();
|
||||
}
|
||||
SDL_AtomicUnlock(&data->lock);
|
||||
|
||||
if (status < 0) {
|
||||
SDL_AtomicLock(&data->lock);
|
||||
if (!SDL_AtomicGet(&data->active)) {
|
||||
if (SDL_TimerInit() < 0) {
|
||||
SDL_AtomicUnlock(&data->lock);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_AtomicLock(&data->lock);
|
||||
timer = data->freelist;
|
||||
if (timer) {
|
||||
data->freelist = timer->next;
|
||||
|
|
@ -326,7 +309,7 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
|
|||
timer->param = param;
|
||||
timer->interval = interval;
|
||||
timer->scheduled = SDL_GetTicks() + interval;
|
||||
timer->canceled = SDL_FALSE;
|
||||
SDL_AtomicSet(&timer->canceled, 0);
|
||||
|
||||
entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
|
||||
if (!entry) {
|
||||
|
|
@ -377,8 +360,8 @@ SDL_RemoveTimer(SDL_TimerID id)
|
|||
SDL_UnlockMutex(data->timermap_lock);
|
||||
|
||||
if (entry) {
|
||||
if (!entry->timer->canceled) {
|
||||
entry->timer->canceled = SDL_TRUE;
|
||||
if (!SDL_AtomicGet(&entry->timer->canceled)) {
|
||||
SDL_AtomicSet(&entry->timer->canceled, 1);
|
||||
canceled = SDL_TRUE;
|
||||
}
|
||||
SDL_free(entry);
|
||||
|
|
|
|||
|
|
@ -107,10 +107,8 @@ SDL_TicksInit(void)
|
|||
void
|
||||
SDL_TicksQuit(void)
|
||||
{
|
||||
if (!hires_timer_available) {
|
||||
SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
|
||||
SDL_TimerResolutionChanged, NULL);
|
||||
}
|
||||
SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
|
||||
SDL_TimerResolutionChanged, NULL);
|
||||
|
||||
SDL_SetSystemTimerResolution(0); /* always release our timer resolution request. */
|
||||
|
||||
|
|
@ -189,6 +187,10 @@ SDL_Delay(Uint32 ms)
|
|||
}
|
||||
WaitForSingleObjectEx(mutex, ms, FALSE);
|
||||
#else
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
Sleep(ms);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue