lock critical SDL calls against (Display *), FastDXT small fix

This commit is contained in:
Martin Pulec
2011-11-26 17:19:05 +01:00
parent c85d98fde8
commit a61024853e
3 changed files with 41 additions and 15 deletions

View File

@@ -98,7 +98,7 @@ struct video_compress {
int tx_aux;
codec_t tx_color_spec;
sem_t thread_compress[MAX_THREADS];
sem_t threads_done;
sem_t thread_done[MAX_THREADS];
int dxt_height;
@@ -245,9 +245,9 @@ void *fastdxt_init(const char *num_threads_str)
exit(128);
}
platform_sem_init(&compress->threads_done, 0, 0);
for (x = 0; x < compress->num_threads; x++) {
platform_sem_init(&compress->thread_compress[x], 0, 0);
platform_sem_init(&compress->thread_done[x], 0, 0);
}
pthread_mutex_lock(&(compress->lock));
@@ -261,6 +261,11 @@ void *fastdxt_init(const char *num_threads_str)
}
}
pthread_mutex_unlock(&(compress->lock));
while(compress->num_threads != compress->thread_count) /* wait for all threads online */
;
fprintf(stderr, "All compression threads are online.\n");
return compress;
}
@@ -305,7 +310,7 @@ struct video_frame * fastdxt_compress(void *args, struct video_frame *tx)
}
for (x = 0; x < compress->num_threads; x++) {
platform_sem_wait(&compress->threads_done);
platform_sem_wait(&compress->thread_done[x]);
}
compress->tile->data_len = compress->tile->width * compress->tile->height / 2;
@@ -367,10 +372,10 @@ static void compress_thread(void *args)
((unsigned char *) compress->tile->data) + myId * range / 2,
compress->tile->width, my_height);
platform_sem_post(&compress->threads_done);
platform_sem_post(&compress->thread_done[myId]);
}
platform_sem_post(&compress->threads_done);
platform_sem_post(&compress->thread_done[myId]);
}
void fastdxt_done(void *args)
@@ -386,7 +391,7 @@ void fastdxt_done(void *args)
}
for (x = 0; x < compress->num_threads; x++) {
platform_sem_wait(&compress->threads_done);
platform_sem_wait(&compress->thread_done[x]);
}
pthread_mutex_unlock(&(compress->lock));

View File

@@ -115,6 +115,9 @@ struct state_sdl {
int rshift, gshift, bshift;
int pitch;
#ifndef HAVE_MACOS_X
Display *display;
#endif
};
extern int should_exit;
@@ -432,6 +435,9 @@ void display_sdl_reconfigure(void *state, struct video_desc desc)
s->buffer_writable_lock);
SDL_mutexV(s->buffer_writable_lock);
#ifndef HAVE_MACOS_X
if(s->display) XLockDisplay(s->display);
#endif
cleanup_screen(s);
s->tile->width = desc.width;
@@ -549,6 +555,11 @@ void display_sdl_reconfigure(void *state, struct video_desc desc)
s->pitch = PITCH_DEFAULT;
}
#ifndef HAVE_MACOS_X
if(s->display) XUnlockDisplay(s->display);
#endif
s->rshift = s->sdl_screen->format->Rshift;
s->gshift = s->sdl_screen->format->Gshift;
s->bshift = s->sdl_screen->format->Bshift;
@@ -624,24 +635,25 @@ void *display_sdl_init(char *fmt, unsigned int flags)
s->screen_w = video_info->current_w;
s->screen_h = video_info->current_h;
struct video_desc desc = {500, 500, RGBA, 0, 30.0};
display_sdl_reconfigure(s, desc);
loadSplashscreen(s);
SDL_SysWMinfo info;
memset(&info, 0, sizeof(SDL_SysWMinfo));
ret = SDL_GetWMInfo(&info);
#ifndef HAVE_MACOS_X
s->display = NULL;
if (ret == 1) {
x11_set_display(info.info.x11.display);
s->display = info.info.x11.display;
} else if (ret == 0) {
fprintf(stderr, "[SDL] Warning: SDL_GetWMInfo unimplemented\n");
} else if (ret == -1) {
fprintf(stderr, "[SDL] Warning: SDL_GetWMInfo failure: %s\n", SDL_GetError());
}
} else abort();
#endif
struct video_desc desc = {500, 500, RGBA, 0, 30.0};
display_sdl_reconfigure(s, desc);
loadSplashscreen(s);
/*if (pthread_create(&(s->thread_id), NULL,
display_thread_sdl, (void *)s) != 0) {
@@ -665,6 +677,10 @@ void display_sdl_done(void *state)
assert(s->magic == MAGIC_SDL);
#ifndef HAVE_MACOS_X
if(s->display) XLockDisplay(s->display);
#endif
SDL_DestroyCond(s->buffer_writable_cond);
SDL_DestroyMutex(s->buffer_writable_lock);
cleanup_screen(s);
@@ -672,7 +688,11 @@ void display_sdl_done(void *state)
/*FIXME: free all the stuff */
SDL_ShowCursor(SDL_ENABLE);
#ifndef HAVE_MACOS_X
if(s->display) XUnlockDisplay(s->display);
#endif
SDL_Quit();
}
struct video_frame *display_sdl_getf(void *state)

View File

@@ -121,8 +121,9 @@ void glx_free(void *arg)
pthread_mutex_lock(&lock);
glXMakeCurrent( display, context->win, context->ctx );
XLockDisplay(display);
glXMakeCurrent( display, context->win, context->ctx );
glXDestroyContext( display, context->ctx );
fprintf(stderr, "GLX context destroyed\n");
@@ -138,9 +139,9 @@ void glx_free(void *arg)
XUnlockDisplay(display);
if(display_opened_here && ref_num == 0) {
fprintf(stderr, "Display closed\n");
fprintf(stderr, "Display closed (last client disconnected)\n");
XCloseDisplay( display );
display = NULL; /* should it be here? eg. is legal to reopen display? */
display = NULL;
}
free(context);