src/audio/SDL_audio.c
changeset 9010 6d059ed9b6ca
parent 8919 c9be8299ba6b
child 9012 aa058c87737b
equal deleted inserted replaced
9009:ddbca09f8f9d 9010:6d059ed9b6ca
   203 SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
   203 SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
   204 {
   204 {
   205     return -1;
   205     return -1;
   206 }
   206 }
   207 
   207 
       
   208 static SDL_INLINE SDL_bool
       
   209 is_in_audio_device_thread(SDL_AudioDevice * device)
       
   210 {
       
   211     /* The device thread locks the same mutex, but not through the public API.
       
   212        This check is in case the application, in the audio callback,
       
   213        tries to lock the thread that we've already locked from the
       
   214        device thread...just in case we only have non-recursive mutexes. */
       
   215     if (device->thread && (SDL_ThreadID() == device->threadid)) {
       
   216         return SDL_TRUE;
       
   217     }
       
   218 
       
   219     return SDL_FALSE;
       
   220 }
       
   221 
   208 static void
   222 static void
   209 SDL_AudioLockDevice_Default(SDL_AudioDevice * device)
   223 SDL_AudioLockDevice_Default(SDL_AudioDevice * device)
   210 {
   224 {
   211     if (device->thread && (SDL_ThreadID() == device->threadid)) {
   225     if (!is_in_audio_device_thread(device)) {
   212         return;
   226         SDL_LockMutex(device->mixer_lock);
   213     }
   227     }
   214     SDL_LockMutex(device->mixer_lock);
       
   215 }
   228 }
   216 
   229 
   217 static void
   230 static void
   218 SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
   231 SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
   219 {
   232 {
   220     if (device->thread && (SDL_ThreadID() == device->threadid)) {
   233     if (!is_in_audio_device_thread(device)) {
   221         return;
   234         SDL_UnlockMutex(device->mixer_lock);
   222     }
   235     }
   223     SDL_UnlockMutex(device->mixer_lock);
       
   224 }
   236 }
   225 
   237 
   226 
   238 
   227 static void
   239 static void
   228 finalize_audio_entry_points(void)
   240 finalize_audio_entry_points(void)