src/events/SDL_events.c
changeset 5123 dc0dfdd58f27
parent 5111 481dabb098ef
child 5146 3052772b59db
     1.1 --- a/src/events/SDL_events.c	Thu Jan 27 20:51:54 2011 -0800
     1.2 +++ b/src/events/SDL_events.c	Thu Jan 27 22:44:08 2011 -0800
     1.3 @@ -27,12 +27,12 @@
     1.4  #include "SDL_events.h"
     1.5  #include "SDL_syswm.h"
     1.6  #include "SDL_thread.h"
     1.7 -#include "SDL_sysevents.h"
     1.8  #include "SDL_events_c.h"
     1.9  #include "../timer/SDL_timer_c.h"
    1.10  #if !SDL_JOYSTICK_DISABLED
    1.11  #include "../joystick/SDL_joystick_c.h"
    1.12  #endif
    1.13 +#include "../video/SDL_sysvideo.h"
    1.14  
    1.15  /* Public data -- the event filter */
    1.16  SDL_EventFilter SDL_EventOK = NULL;
    1.17 @@ -58,36 +58,6 @@
    1.18      struct SDL_SysWMmsg wmmsg[MAXEVENTS];
    1.19  } SDL_EventQ;
    1.20  
    1.21 -/* Private data -- event locking structure */
    1.22 -static struct
    1.23 -{
    1.24 -    SDL_mutex *lock;
    1.25 -    int safe;
    1.26 -} SDL_EventLock;
    1.27 -
    1.28 -/* Thread functions */
    1.29 -static SDL_Thread *SDL_EventThread = NULL;      /* Thread handle */
    1.30 -static SDL_threadID event_thread;     /* The event thread id */
    1.31 -
    1.32 -void
    1.33 -SDL_Lock_EventThread(void)
    1.34 -{
    1.35 -    if (SDL_EventThread && (SDL_ThreadID() != event_thread)) {
    1.36 -        /* Grab lock and spin until we're sure event thread stopped */
    1.37 -        SDL_mutexP(SDL_EventLock.lock);
    1.38 -        while (!SDL_EventLock.safe) {
    1.39 -            SDL_Delay(1);
    1.40 -        }
    1.41 -    }
    1.42 -}
    1.43 -
    1.44 -void
    1.45 -SDL_Unlock_EventThread(void)
    1.46 -{
    1.47 -    if (SDL_EventThread && (SDL_ThreadID() != event_thread)) {
    1.48 -        SDL_mutexV(SDL_EventLock.lock);
    1.49 -    }
    1.50 -}
    1.51  
    1.52  static __inline__ SDL_bool
    1.53  SDL_ShouldPollJoystick()
    1.54 @@ -102,106 +72,6 @@
    1.55      return SDL_FALSE;
    1.56  }
    1.57  
    1.58 -static int SDLCALL
    1.59 -SDL_GobbleEvents(void *unused)
    1.60 -{
    1.61 -    event_thread = SDL_ThreadID();
    1.62 -
    1.63 -    while (SDL_EventQ.active) {
    1.64 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.65 -
    1.66 -        /* Get events from the video subsystem */
    1.67 -        if (_this) {
    1.68 -            _this->PumpEvents(_this);
    1.69 -        }
    1.70 -#if !SDL_JOYSTICK_DISABLED
    1.71 -        /* Check for joystick state change */
    1.72 -        if (SDL_ShouldPollJoystick()) {
    1.73 -            SDL_JoystickUpdate();
    1.74 -        }
    1.75 -#endif
    1.76 -
    1.77 -        /* Give up the CPU for the rest of our timeslice */
    1.78 -        SDL_EventLock.safe = 1;
    1.79 -        SDL_Delay(1);
    1.80 -
    1.81 -        /* Check for event locking.
    1.82 -           On the P of the lock mutex, if the lock is held, this thread
    1.83 -           will wait until the lock is released before continuing.  The
    1.84 -           safe flag will be set, meaning that the other thread can go
    1.85 -           about it's business.  The safe flag is reset before the V,
    1.86 -           so as soon as the mutex is free, other threads can see that
    1.87 -           it's not safe to interfere with the event thread.
    1.88 -         */
    1.89 -        SDL_mutexP(SDL_EventLock.lock);
    1.90 -        SDL_EventLock.safe = 0;
    1.91 -        SDL_mutexV(SDL_EventLock.lock);
    1.92 -    }
    1.93 -    event_thread = 0;
    1.94 -    return (0);
    1.95 -}
    1.96 -
    1.97 -static int
    1.98 -SDL_StartEventThread(Uint32 flags)
    1.99 -{
   1.100 -    /* Reset everything to zero */
   1.101 -    SDL_EventThread = NULL;
   1.102 -    SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
   1.103 -
   1.104 -    /* Create the lock and set ourselves active */
   1.105 -#if !SDL_THREADS_DISABLED
   1.106 -    SDL_EventQ.lock = SDL_CreateMutex();
   1.107 -    if (SDL_EventQ.lock == NULL) {
   1.108 -        return (-1);
   1.109 -    }
   1.110 -#endif /* !SDL_THREADS_DISABLED */
   1.111 -    SDL_EventQ.active = 1;
   1.112 -
   1.113 -    if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
   1.114 -        SDL_EventLock.lock = SDL_CreateMutex();
   1.115 -        if (SDL_EventLock.lock == NULL) {
   1.116 -            return (-1);
   1.117 -        }
   1.118 -        SDL_EventLock.safe = 0;
   1.119 -
   1.120 -#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
   1.121 -#undef SDL_CreateThread
   1.122 -        SDL_EventThread =
   1.123 -            SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
   1.124 -#else
   1.125 -        SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
   1.126 -#endif
   1.127 -        if (SDL_EventThread == NULL) {
   1.128 -            return (-1);
   1.129 -        }
   1.130 -    } else {
   1.131 -        event_thread = 0;
   1.132 -    }
   1.133 -    return (0);
   1.134 -}
   1.135 -
   1.136 -static void
   1.137 -SDL_StopEventThread(void)
   1.138 -{
   1.139 -    SDL_EventQ.active = 0;
   1.140 -    if (SDL_EventThread) {
   1.141 -        SDL_WaitThread(SDL_EventThread, NULL);
   1.142 -        SDL_EventThread = NULL;
   1.143 -        SDL_DestroyMutex(SDL_EventLock.lock);
   1.144 -        SDL_EventLock.lock = NULL;
   1.145 -    }
   1.146 -    if (SDL_EventQ.lock) {
   1.147 -        SDL_DestroyMutex(SDL_EventQ.lock);
   1.148 -        SDL_EventQ.lock = NULL;
   1.149 -    }
   1.150 -}
   1.151 -
   1.152 -SDL_threadID
   1.153 -SDL_EventThreadID(void)
   1.154 -{
   1.155 -    return (event_thread);
   1.156 -}
   1.157 -
   1.158  /* Public functions */
   1.159  
   1.160  void
   1.161 @@ -209,13 +79,10 @@
   1.162  {
   1.163      int i;
   1.164  
   1.165 -    /* Halt the event thread, if running */
   1.166 -    SDL_StopEventThread();
   1.167 -
   1.168 -    /* Shutdown event handlers */
   1.169 -    SDL_KeyboardQuit();
   1.170 -    SDL_MouseQuit();
   1.171 -    SDL_QuitQuit();
   1.172 +    if (SDL_EventQ.lock) {
   1.173 +        SDL_DestroyMutex(SDL_EventQ.lock);
   1.174 +        SDL_EventQ.lock = NULL;
   1.175 +    }
   1.176  
   1.177      /* Clean out EventQ */
   1.178      SDL_EventQ.head = 0;
   1.179 @@ -233,12 +100,11 @@
   1.180  
   1.181  /* This function (and associated calls) may be called more than once */
   1.182  int
   1.183 -SDL_StartEventLoop(Uint32 flags)
   1.184 +SDL_StartEventLoop(void)
   1.185  {
   1.186      int retcode;
   1.187  
   1.188      /* Clean out the event queue */
   1.189 -    SDL_EventThread = NULL;
   1.190      SDL_EventQ.lock = NULL;
   1.191      SDL_StopEventLoop();
   1.192  
   1.193 @@ -246,22 +112,15 @@
   1.194      SDL_EventOK = NULL;
   1.195      SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
   1.196  
   1.197 -    /* Initialize event handlers */
   1.198 -    retcode = 0;
   1.199 -    retcode += SDL_KeyboardInit();
   1.200 -    retcode += SDL_MouseInit();
   1.201 -    retcode += SDL_TouchInit();
   1.202 -    retcode += SDL_QuitInit();
   1.203 -    if (retcode < 0) {
   1.204 -        /* We don't expect them to fail, but... */
   1.205 +    /* Create the lock and set ourselves active */
   1.206 +#if !SDL_THREADS_DISABLED
   1.207 +    SDL_EventQ.lock = SDL_CreateMutex();
   1.208 +    if (SDL_EventQ.lock == NULL) {
   1.209          return (-1);
   1.210      }
   1.211 +#endif /* !SDL_THREADS_DISABLED */
   1.212 +    SDL_EventQ.active = 1;
   1.213  
   1.214 -    /* Create the lock and event thread */
   1.215 -    if (SDL_StartEventThread(flags) < 0) {
   1.216 -        SDL_StopEventLoop();
   1.217 -        return (-1);
   1.218 -    }
   1.219      return (0);
   1.220  }
   1.221  
   1.222 @@ -420,20 +279,18 @@
   1.223  void
   1.224  SDL_PumpEvents(void)
   1.225  {
   1.226 -    if (!SDL_EventThread) {
   1.227 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.228 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.229  
   1.230 -        /* Get events from the video subsystem */
   1.231 -        if (_this) {
   1.232 -            _this->PumpEvents(_this);
   1.233 -        }
   1.234 +    /* Get events from the video subsystem */
   1.235 +    if (_this) {
   1.236 +        _this->PumpEvents(_this);
   1.237 +    }
   1.238  #if !SDL_JOYSTICK_DISABLED
   1.239 -        /* Check for joystick state change */
   1.240 -        if (SDL_ShouldPollJoystick()) {
   1.241 -            SDL_JoystickUpdate();
   1.242 -        }
   1.243 +    /* Check for joystick state change */
   1.244 +    if (SDL_ShouldPollJoystick()) {
   1.245 +        SDL_JoystickUpdate();
   1.246 +    }
   1.247  #endif
   1.248 -    }
   1.249  }
   1.250  
   1.251  /* Public functions */