pkgsrc/emulators/gnuboy-sdl/patches/patch-aa
nat 1328f0e811 Fix freeze in audio callback on close.
Bump PKGREVISION.

This commit was approved by wiz@.
2015-01-03 11:21:07 +00:00

82 lines
1.7 KiB
Text

$NetBSD: patch-aa,v 1.2 2015/01/03 11:21:07 nat Exp $
--- sys/sdl/sdl.c.orig 2001-09-17 16:40:14.000000000 +0000
+++ sys/sdl/sdl.c
@@ -28,6 +28,7 @@ static int use_joy = 1, sdl_joy_num;
static SDL_Joystick * sdl_joy = NULL;
static const int joy_commit_range = 3276;
static char Xstatus, Ystatus;
+static int closing = 0;
static SDL_Surface *screen;
static SDL_Overlay *overlay;
@@ -441,6 +442,8 @@ static int sound = 1;
static int samplerate = 44100;
static int stereo = 1;
static volatile int audio_done;
+static SDL_sem *pcm_rsem, *pcm_wsem;
+static int atexit_done = 0;
rcvar_t pcm_exports[] =
{
@@ -453,8 +456,19 @@ rcvar_t pcm_exports[] =
static void audio_callback(void *blah, byte *stream, int len)
{
- memcpy(stream, pcm.buf, len);
- audio_done = 1;
+ if (!closing) {
+ SDL_SemWait(pcm_rsem);
+ memcpy(stream, pcm.buf, len);
+ SDL_SemPost(pcm_wsem);
+ }
+}
+
+
+static void audio_atexit(void)
+{
+ closing = 1;
+ if (pcm_wsem)
+ SDL_SemPost(pcm_rsem);
}
@@ -466,6 +480,13 @@ void pcm_init()
if (!sound) return;
SDL_InitSubSystem(SDL_INIT_AUDIO);
+ /* XXX: check for NULL */
+ pcm_rsem = SDL_CreateSemaphore(0);
+ pcm_wsem = SDL_CreateSemaphore(0);
+ if (!atexit_done) {
+ atexit(audio_atexit);
+ atexit_done = 1;
+ }
as.freq = samplerate;
as.format = AUDIO_U8;
as.channels = 1 + stereo;
@@ -491,16 +512,20 @@ int pcm_submit()
{
if (!pcm.buf) return 0;
if (pcm.pos < pcm.len) return 1;
- while (!audio_done)
- SDL_Delay(4);
- audio_done = 0;
+ SDL_SemPost(pcm_rsem);
+ SDL_SemWait(pcm_wsem);
pcm.pos = 0;
return 1;
}
void pcm_close()
{
- if (sound) SDL_CloseAudio();
+ if (sound) {
+ SDL_CloseAudio();
+ SDL_DestroySemaphore(pcm_rsem);
+ SDL_DestroySemaphore(pcm_wsem);
+ pcm_rsem = pcm_wsem = 0;
+ }
}