This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via b549f66c9fc9e0ccb125692a7a2570bbe2016cdc (commit) from 4d4ca995c2d6ae58d85863cae26c4369d5bd0967 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/b549f66c9fc9e0ccb125692a7a2570bbe2016...
commit b549f66c9fc9e0ccb125692a7a2570bbe2016cdc Author: Cyril Hrubis metan@ucw.cz Date: Tue Jan 17 11:59:23 2012 +0100
backends: Make the SDL backend thread safe.
The SDL_Flip, SDL_UpdateRect, SDL_Poll and SDL_Quit are not thread safe. If these clash while running on xserver, asynchronous communication is detected and the connection is aborted. Fix that by guarding these by a mutex.
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c index 0a97ada..f50cfed 100644 --- a/libs/backends/GP_SDL.c +++ b/libs/backends/GP_SDL.c @@ -32,39 +32,53 @@ #ifdef HAVE_LIBSDL
#include <SDL/SDL.h> +#include <SDL/SDL_mutex.h>
static SDL_Surface *sdl_surface; +static SDL_mutex *mutex; static GP_Context context;
/* Backend API funcitons */
static void sdl_flip(struct GP_Backend *self __attribute__((unused))) { - SDL_LockSurface(sdl_surface); + SDL_mutexP(mutex); + SDL_Flip(sdl_surface); context.pixels = sdl_surface->pixels; - SDL_UnlockSurface(sdl_surface); + + SDL_mutexV(mutex); }
static void sdl_update_rect(struct GP_Backend *self __attribute__((unused)), GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2) { - SDL_LockSurface(sdl_surface); + SDL_mutexP(mutex); + SDL_UpdateRect(sdl_surface, x1, y1, x2, y2); - SDL_UnlockSurface(sdl_surface); + + SDL_mutexV(mutex); }
static void sdl_exit(struct GP_Backend *self __attribute__((unused))) { + SDL_mutexP(mutex); + SDL_Quit(); + + SDL_DestroyMutex(mutex); }
static void sdl_poll(struct GP_Backend *self __attribute__((unused))) { SDL_Event ev;
+ SDL_mutexP(mutex); + while (SDL_PollEvent(&ev)) GP_InputDriverSDLEventPut(&ev); + + SDL_mutexV(mutex); }
static struct GP_Backend backend = { @@ -132,6 +146,8 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp) return NULL; }
+ mutex = SDL_CreateMutex(); + if (context_from_surface(&context, sdl_surface)) { GP_DEBUG(1, "ERROR: Failed to match pixel_type"); SDL_Quit();
-----------------------------------------------------------------------
Summary of changes: libs/backends/GP_SDL.c | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.