Commit a55059b4 authored by Sam Lantinga's avatar Sam Lantinga

The audio lock and unlock functions are now a part of the driver.

The MacOS audio locking has been implemented, courtesy of Ryan Gordon

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40323
parent 2341158b
...@@ -230,6 +230,22 @@ int SDL_RunAudio(void *audiop) ...@@ -230,6 +230,22 @@ int SDL_RunAudio(void *audiop)
return(0); return(0);
} }
static void SDL_LockAudio_Default(SDL_AudioDevice *audio)
{
if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) {
return;
}
SDL_mutexP(audio->mixer_lock);
}
static void SDL_UnlockAudio_Default(SDL_AudioDevice *audio)
{
if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) {
return;
}
SDL_mutexV(audio->mixer_lock);
}
int SDL_AudioInit(const char *driver_name) int SDL_AudioInit(const char *driver_name)
{ {
SDL_AudioDevice *audio; SDL_AudioDevice *audio;
...@@ -309,6 +325,10 @@ int SDL_AudioInit(const char *driver_name) ...@@ -309,6 +325,10 @@ int SDL_AudioInit(const char *driver_name)
current_audio = audio; current_audio = audio;
if ( current_audio ) { if ( current_audio ) {
current_audio->name = bootstrap[i]->name; current_audio->name = bootstrap[i]->name;
if ( !current_audio->LockAudio && !current_audio->UnlockAudio ) {
current_audio->LockAudio = SDL_LockAudio_Default;
current_audio->UnlockAudio = SDL_UnlockAudio_Default;
}
} }
return(0); return(0);
} }
...@@ -506,11 +526,8 @@ void SDL_LockAudio (void) ...@@ -506,11 +526,8 @@ void SDL_LockAudio (void)
SDL_AudioDevice *audio = current_audio; SDL_AudioDevice *audio = current_audio;
/* Obtain a lock on the mixing buffers */ /* Obtain a lock on the mixing buffers */
if ( audio ) { if ( audio && audio->LockAudio ) {
if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) { audio->LockAudio(audio);
return;
}
SDL_mutexP(audio->mixer_lock);
} }
} }
...@@ -519,11 +536,8 @@ void SDL_UnlockAudio (void) ...@@ -519,11 +536,8 @@ void SDL_UnlockAudio (void)
SDL_AudioDevice *audio = current_audio; SDL_AudioDevice *audio = current_audio;
/* Release lock on the mixing buffers */ /* Release lock on the mixing buffers */
if ( audio ) { if ( audio && audio->UnlockAudio ) {
if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) { audio->UnlockAudio(audio);
return;
}
SDL_mutexV(audio->mixer_lock);
} }
} }
......
...@@ -58,6 +58,11 @@ struct SDL_AudioDevice { ...@@ -58,6 +58,11 @@ struct SDL_AudioDevice {
void (*WaitDone)(_THIS); void (*WaitDone)(_THIS);
void (*CloseAudio)(_THIS); void (*CloseAudio)(_THIS);
/* * * */
/* Lock / Unlock functions added for the Mac port */
void (*LockAudio)(_THIS);
void (*UnlockAudio)(_THIS);
/* * * */ /* * * */
/* Data common to all devices */ /* Data common to all devices */
......
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