Commit c3daf0f0 authored by Sam Lantinga's avatar Sam Lantinga

Removed completely non-portable event thread hack.

Next I'll be working on generalizing the event sources and making the event queue lock-free. :)
parent 95dbe47c
...@@ -116,7 +116,6 @@ extern "C" { ...@@ -116,7 +116,6 @@ extern "C" {
#define SDL_INIT_JOYSTICK 0x00000200 #define SDL_INIT_JOYSTICK 0x00000200
#define SDL_INIT_HAPTIC 0x00001000 #define SDL_INIT_HAPTIC 0x00001000
#define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */ #define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */
#define SDL_INIT_EVENTTHREAD 0x01000000 /**< Not supported on all OS's */
#define SDL_INIT_EVERYTHING 0x0000FFFF #define SDL_INIT_EVERYTHING 0x0000FFFF
/*@}*/ /*@}*/
......
...@@ -278,8 +278,6 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); ...@@ -278,8 +278,6 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index);
* \param driver_name Initialize a specific driver by name, or NULL for the * \param driver_name Initialize a specific driver by name, or NULL for the
* default video driver. * default video driver.
* *
* \param flags FIXME: Still needed?
*
* \return 0 on success, -1 on error * \return 0 on success, -1 on error
* *
* This function initializes the video subsystem; setting up a connection * This function initializes the video subsystem; setting up a connection
...@@ -288,8 +286,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); ...@@ -288,8 +286,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index);
* *
* \sa SDL_VideoQuit() * \sa SDL_VideoQuit()
*/ */
extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name);
Uint32 flags);
/** /**
* \brief Shuts down the video subsystem. * \brief Shuts down the video subsystem.
......
...@@ -59,7 +59,7 @@ SDL_InitSubSystem(Uint32 flags) ...@@ -59,7 +59,7 @@ SDL_InitSubSystem(Uint32 flags)
#if !SDL_VIDEO_DISABLED #if !SDL_VIDEO_DISABLED
/* Initialize the video/event subsystem */ /* Initialize the video/event subsystem */
if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) { if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL, (flags & SDL_INIT_EVENTTHREAD)) < 0) { if (SDL_VideoInit(NULL) < 0) {
return (-1); return (-1);
} }
SDL_initialized |= SDL_INIT_VIDEO; SDL_initialized |= SDL_INIT_VIDEO;
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
#include "SDL_events.h" #include "SDL_events.h"
#include "SDL_syswm.h" #include "SDL_syswm.h"
#include "SDL_thread.h" #include "SDL_thread.h"
#include "SDL_sysevents.h"
#include "SDL_events_c.h" #include "SDL_events_c.h"
#include "../timer/SDL_timer_c.h" #include "../timer/SDL_timer_c.h"
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
#include "../joystick/SDL_joystick_c.h" #include "../joystick/SDL_joystick_c.h"
#endif #endif
#include "../video/SDL_sysvideo.h"
/* Public data -- the event filter */ /* Public data -- the event filter */
SDL_EventFilter SDL_EventOK = NULL; SDL_EventFilter SDL_EventOK = NULL;
...@@ -58,36 +58,6 @@ static struct ...@@ -58,36 +58,6 @@ static struct
struct SDL_SysWMmsg wmmsg[MAXEVENTS]; struct SDL_SysWMmsg wmmsg[MAXEVENTS];
} SDL_EventQ; } SDL_EventQ;
/* Private data -- event locking structure */
static struct
{
SDL_mutex *lock;
int safe;
} SDL_EventLock;
/* Thread functions */
static SDL_Thread *SDL_EventThread = NULL; /* Thread handle */
static SDL_threadID event_thread; /* The event thread id */
void
SDL_Lock_EventThread(void)
{
if (SDL_EventThread && (SDL_ThreadID() != event_thread)) {
/* Grab lock and spin until we're sure event thread stopped */
SDL_mutexP(SDL_EventLock.lock);
while (!SDL_EventLock.safe) {
SDL_Delay(1);
}
}
}
void
SDL_Unlock_EventThread(void)
{
if (SDL_EventThread && (SDL_ThreadID() != event_thread)) {
SDL_mutexV(SDL_EventLock.lock);
}
}
static __inline__ SDL_bool static __inline__ SDL_bool
SDL_ShouldPollJoystick() SDL_ShouldPollJoystick()
...@@ -102,106 +72,6 @@ SDL_ShouldPollJoystick() ...@@ -102,106 +72,6 @@ SDL_ShouldPollJoystick()
return SDL_FALSE; return SDL_FALSE;
} }
static int SDLCALL
SDL_GobbleEvents(void *unused)
{
event_thread = SDL_ThreadID();
while (SDL_EventQ.active) {
SDL_VideoDevice *_this = SDL_GetVideoDevice();
/* Get events from the video subsystem */
if (_this) {
_this->PumpEvents(_this);
}
#if !SDL_JOYSTICK_DISABLED
/* Check for joystick state change */
if (SDL_ShouldPollJoystick()) {
SDL_JoystickUpdate();
}
#endif
/* Give up the CPU for the rest of our timeslice */
SDL_EventLock.safe = 1;
SDL_Delay(1);
/* Check for event locking.
On the P of the lock mutex, if the lock is held, this thread
will wait until the lock is released before continuing. The
safe flag will be set, meaning that the other thread can go
about it's business. The safe flag is reset before the V,
so as soon as the mutex is free, other threads can see that
it's not safe to interfere with the event thread.
*/
SDL_mutexP(SDL_EventLock.lock);
SDL_EventLock.safe = 0;
SDL_mutexV(SDL_EventLock.lock);
}
event_thread = 0;
return (0);
}
static int
SDL_StartEventThread(Uint32 flags)
{
/* Reset everything to zero */
SDL_EventThread = NULL;
SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
/* Create the lock and set ourselves active */
#if !SDL_THREADS_DISABLED
SDL_EventQ.lock = SDL_CreateMutex();
if (SDL_EventQ.lock == NULL) {
return (-1);
}
#endif /* !SDL_THREADS_DISABLED */
SDL_EventQ.active = 1;
if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
SDL_EventLock.lock = SDL_CreateMutex();
if (SDL_EventLock.lock == NULL) {
return (-1);
}
SDL_EventLock.safe = 0;
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
SDL_EventThread =
SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
#else
SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
#endif
if (SDL_EventThread == NULL) {
return (-1);
}
} else {
event_thread = 0;
}
return (0);
}
static void
SDL_StopEventThread(void)
{
SDL_EventQ.active = 0;
if (SDL_EventThread) {
SDL_WaitThread(SDL_EventThread, NULL);
SDL_EventThread = NULL;
SDL_DestroyMutex(SDL_EventLock.lock);
SDL_EventLock.lock = NULL;
}
if (SDL_EventQ.lock) {
SDL_DestroyMutex(SDL_EventQ.lock);
SDL_EventQ.lock = NULL;
}
}
SDL_threadID
SDL_EventThreadID(void)
{
return (event_thread);
}
/* Public functions */ /* Public functions */
void void
...@@ -209,13 +79,10 @@ SDL_StopEventLoop(void) ...@@ -209,13 +79,10 @@ SDL_StopEventLoop(void)
{ {
int i; int i;
/* Halt the event thread, if running */ if (SDL_EventQ.lock) {
SDL_StopEventThread(); SDL_DestroyMutex(SDL_EventQ.lock);
SDL_EventQ.lock = NULL;
/* Shutdown event handlers */ }
SDL_KeyboardQuit();
SDL_MouseQuit();
SDL_QuitQuit();
/* Clean out EventQ */ /* Clean out EventQ */
SDL_EventQ.head = 0; SDL_EventQ.head = 0;
...@@ -233,12 +100,11 @@ SDL_StopEventLoop(void) ...@@ -233,12 +100,11 @@ SDL_StopEventLoop(void)
/* This function (and associated calls) may be called more than once */ /* This function (and associated calls) may be called more than once */
int int
SDL_StartEventLoop(Uint32 flags) SDL_StartEventLoop(void)
{ {
int retcode; int retcode;
/* Clean out the event queue */ /* Clean out the event queue */
SDL_EventThread = NULL;
SDL_EventQ.lock = NULL; SDL_EventQ.lock = NULL;
SDL_StopEventLoop(); SDL_StopEventLoop();
...@@ -246,22 +112,15 @@ SDL_StartEventLoop(Uint32 flags) ...@@ -246,22 +112,15 @@ SDL_StartEventLoop(Uint32 flags)
SDL_EventOK = NULL; SDL_EventOK = NULL;
SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
/* Initialize event handlers */ /* Create the lock and set ourselves active */
retcode = 0; #if !SDL_THREADS_DISABLED
retcode += SDL_KeyboardInit(); SDL_EventQ.lock = SDL_CreateMutex();
retcode += SDL_MouseInit(); if (SDL_EventQ.lock == NULL) {
retcode += SDL_TouchInit();
retcode += SDL_QuitInit();
if (retcode < 0) {
/* We don't expect them to fail, but... */
return (-1); return (-1);
} }
#endif /* !SDL_THREADS_DISABLED */
SDL_EventQ.active = 1;
/* Create the lock and event thread */
if (SDL_StartEventThread(flags) < 0) {
SDL_StopEventLoop();
return (-1);
}
return (0); return (0);
} }
...@@ -420,20 +279,18 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType) ...@@ -420,20 +279,18 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType)
void void
SDL_PumpEvents(void) SDL_PumpEvents(void)
{ {
if (!SDL_EventThread) { SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_VideoDevice *_this = SDL_GetVideoDevice();
/* Get events from the video subsystem */ /* Get events from the video subsystem */
if (_this) { if (_this) {
_this->PumpEvents(_this); _this->PumpEvents(_this);
} }
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
/* Check for joystick state change */ /* Check for joystick state change */
if (SDL_ShouldPollJoystick()) { if (SDL_ShouldPollJoystick()) {
SDL_JoystickUpdate(); SDL_JoystickUpdate();
}
#endif
} }
#endif
} }
/* Public functions */ /* Public functions */
......
...@@ -29,15 +29,12 @@ ...@@ -29,15 +29,12 @@
#include "SDL_touch_c.h" #include "SDL_touch_c.h"
#include "SDL_windowevents_c.h" #include "SDL_windowevents_c.h"
#include "SDL_gesture_c.h" #include "SDL_gesture_c.h"
/* Start and stop the event processing loop */ /* Start and stop the event processing loop */
extern int SDL_StartEventLoop(Uint32 flags); extern int SDL_StartEventLoop(void);
extern void SDL_StopEventLoop(void); extern void SDL_StopEventLoop(void);
extern void SDL_QuitInterrupt(void); extern void SDL_QuitInterrupt(void);
extern void SDL_Lock_EventThread(void);
extern void SDL_Unlock_EventThread(void);
extern SDL_threadID SDL_EventThreadID(void);
extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message); extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
extern int SDL_QuitInit(void); extern int SDL_QuitInit(void);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "SDL_timer.h" #include "SDL_timer.h"
#include "SDL_events.h" #include "SDL_events.h"
#include "SDL_events_c.h" #include "SDL_events_c.h"
#include "SDL_sysevents.h" #include "../video/SDL_sysvideo.h"
/* Global keyboard information */ /* Global keyboard information */
......
...@@ -30,12 +30,6 @@ ...@@ -30,12 +30,6 @@
#include "../events/SDL_events_c.h" #include "../events/SDL_events_c.h"
#endif #endif
/* This is used for Quake III Arena */
#if SDL_EVENTS_DISABLED
#define SDL_Lock_EventThread()
#define SDL_Unlock_EventThread()
#endif
Uint8 SDL_numjoysticks = 0; Uint8 SDL_numjoysticks = 0;
SDL_Joystick **SDL_joysticks = NULL; SDL_Joystick **SDL_joysticks = NULL;
static SDL_Joystick *default_joystick = NULL; static SDL_Joystick *default_joystick = NULL;
...@@ -165,11 +159,9 @@ SDL_JoystickOpen(int device_index) ...@@ -165,11 +159,9 @@ SDL_JoystickOpen(int device_index)
/* Add joystick to list */ /* Add joystick to list */
++joystick->ref_count; ++joystick->ref_count;
SDL_Lock_EventThread();
for (i = 0; SDL_joysticks[i]; ++i) for (i = 0; SDL_joysticks[i]; ++i)
/* Skip to next joystick */ ; /* Skip to next joystick */ ;
SDL_joysticks[i] = joystick; SDL_joysticks[i] = joystick;
SDL_Unlock_EventThread();
return (joystick); return (joystick);
} }
...@@ -379,9 +371,6 @@ SDL_JoystickClose(SDL_Joystick * joystick) ...@@ -379,9 +371,6 @@ SDL_JoystickClose(SDL_Joystick * joystick)
return; return;
} }
/* Lock the event queue - prevent joystick polling */
SDL_Lock_EventThread();
if (joystick == default_joystick) { if (joystick == default_joystick) {
default_joystick = NULL; default_joystick = NULL;
} }
...@@ -396,9 +385,6 @@ SDL_JoystickClose(SDL_Joystick * joystick) ...@@ -396,9 +385,6 @@ SDL_JoystickClose(SDL_Joystick * joystick)
} }
} }
/* Let the event thread keep running */
SDL_Unlock_EventThread();
/* Free the data associated with this joystick */ /* Free the data associated with this joystick */
if (joystick->axes) { if (joystick->axes) {
SDL_free(joystick->axes); SDL_free(joystick->axes);
...@@ -419,9 +405,7 @@ void ...@@ -419,9 +405,7 @@ void
SDL_JoystickQuit(void) SDL_JoystickQuit(void)
{ {
/* Stop the event polling */ /* Stop the event polling */
SDL_Lock_EventThread();
SDL_numjoysticks = 0; SDL_numjoysticks = 0;
SDL_Unlock_EventThread();
/* Quit the joystick setup */ /* Quit the joystick setup */
SDL_SYS_JoystickQuit(); SDL_SYS_JoystickQuit();
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "SDL_renderer_gl.h" #include "SDL_renderer_gl.h"
#include "SDL_renderer_gles.h" #include "SDL_renderer_gles.h"
#include "SDL_renderer_sw.h" #include "SDL_renderer_sw.h"
#include "../events/SDL_sysevents.h"
#include "../events/SDL_events_c.h" #include "../events/SDL_events_c.h"
#if SDL_VIDEO_DRIVER_WINDOWS #if SDL_VIDEO_DRIVER_WINDOWS
...@@ -172,7 +171,7 @@ SDL_GetVideoDriver(int index) ...@@ -172,7 +171,7 @@ SDL_GetVideoDriver(int index)
* Initialize the video and event subsystems -- determine native pixel format * Initialize the video and event subsystems -- determine native pixel format
*/ */
int int
SDL_VideoInit(const char *driver_name, Uint32 flags) SDL_VideoInit(const char *driver_name)
{ {
SDL_VideoDevice *video; SDL_VideoDevice *video;
int index; int index;
...@@ -183,18 +182,12 @@ SDL_VideoInit(const char *driver_name, Uint32 flags) ...@@ -183,18 +182,12 @@ SDL_VideoInit(const char *driver_name, Uint32 flags)
SDL_VideoQuit(); SDL_VideoQuit();
} }
/* Toggle the event thread flags, based on OS requirements */
#if defined(MUST_THREAD_EVENTS)
flags |= SDL_INIT_EVENTTHREAD;
#elif defined(CANT_THREAD_EVENTS)
if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
SDL_SetError("OS doesn't support threaded events");
return -1;
}
#endif
/* Start the event loop */ /* Start the event loop */
if (SDL_StartEventLoop(flags) < 0) { if (SDL_StartEventLoop() < 0 ||
SDL_KeyboardInit() < 0 ||
SDL_MouseInit() < 0 ||
SDL_TouchInit() < 0 ||
SDL_QuitInit() < 0) {
return -1; return -1;
} }
...@@ -887,7 +880,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) ...@@ -887,7 +880,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (!_this) { if (!_this) {
/* Initialize the video system if needed */ /* Initialize the video system if needed */
if (SDL_VideoInit(NULL, 0) < 0) { if (SDL_VideoInit(NULL) < 0) {
return NULL; return NULL;
} }
} }
...@@ -2807,8 +2800,13 @@ SDL_VideoQuit(void) ...@@ -2807,8 +2800,13 @@ SDL_VideoQuit(void)
if (!_this) { if (!_this) {
return; return;
} }
/* Halt event processing before doing anything else */ /* Halt event processing before doing anything else */
SDL_QuitQuit();
SDL_MouseQuit();
SDL_KeyboardQuit();
SDL_StopEventLoop(); SDL_StopEventLoop();
SDL_EnableScreenSaver(); SDL_EnableScreenSaver();
/* Clean up the system video */ /* Clean up the system video */
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <directfb.h> #include <directfb.h>
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h" #include "../../events/SDL_keyboard_c.h"
#include "../../events/scancodes_linux.h" #include "../../events/scancodes_linux.h"
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
/* Being a null driver, there's no event stream. We just define stubs for /* Being a null driver, there's no event stream. We just define stubs for
most of the API. */ most of the API. */
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "SDL_nullvideo.h" #include "SDL_nullvideo.h"
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <nds.h> #include <nds.h>
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "SDL_ndsvideo.h" #include "SDL_ndsvideo.h"
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
/* Being a null driver, there's no event stream. We just define stubs for /* Being a null driver, there's no event stream. We just define stubs for
most of the API. */ most of the API. */
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
void void
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "SDL_uikitvideo.h" #include "SDL_uikitvideo.h"
......
...@@ -616,7 +616,7 @@ CommonInit(CommonState * state) ...@@ -616,7 +616,7 @@ CommonInit(CommonState * state)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
} }
if (SDL_VideoInit(state->videodriver, 0) < 0) { if (SDL_VideoInit(state->videodriver) < 0) {
fprintf(stderr, "Couldn't initialize video driver: %s\n", fprintf(stderr, "Couldn't initialize video driver: %s\n",
SDL_GetError()); SDL_GetError());
return SDL_FALSE; return SDL_FALSE;
......
...@@ -60,7 +60,7 @@ int main(int argc,char** argv) { ...@@ -60,7 +60,7 @@ int main(int argc,char** argv) {
exit(-1); exit(-1);
} }
if(SDL_VideoInit(NULL,0) == -1) { if(SDL_VideoInit(NULL) == -1) {
printf("Could not initialize SDL video.\n"); printf("Could not initialize SDL video.\n");
exit(-2); exit(-2);
} }
......
...@@ -241,16 +241,7 @@ main(int argc, char *argv[]) ...@@ -241,16 +241,7 @@ main(int argc, char *argv[])
video_flags = SDL_SWSURFACE; video_flags = SDL_SWSURFACE;
parsed = 1; parsed = 1;
while (parsed) { while (parsed) {
/* If the threaded option is enabled, and the SDL library hasn't if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) {
been compiled with threaded events enabled, then the mouse and
keyboard won't respond.
*/
if ((argc >= 2) && (strcmp(argv[1], "-threaded") == 0)) {
init_flags |= SDL_INIT_EVENTTHREAD;
argc -= 1;
argv += 1;
printf("Running with threaded events\n");
} else if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) {
video_flags |= SDL_FULLSCREEN; video_flags |= SDL_FULLSCREEN;
argc -= 1; argc -= 1;
argv += 1; argv += 1;
...@@ -320,9 +311,8 @@ main(int argc, char *argv[]) ...@@ -320,9 +311,8 @@ main(int argc, char *argv[])
/* Loop, waiting for QUIT */ /* Loop, waiting for QUIT */
while (!done) { while (!done) {
if (!(init_flags & SDL_INIT_EVENTTHREAD)) { SDL_PumpEvents();
SDL_PumpEvents(); /* Needed when event thread is off */
}
if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT)) { if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT)) {
done = 1; done = 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment