Skip to content

Commit

Permalink
Merge pull request cebix#12 from spolsley/mutex_test
Browse files Browse the repository at this point in the history
SDL mutex deadlock and video fix, try 2
  • Loading branch information
kanjitalk755 committed Feb 27, 2019
2 parents 1b6a63e + 1889560 commit a8bb479
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions BasiliskII/src/SDL/video_sdl2.cpp
Expand Up @@ -875,23 +875,24 @@ static int present_sdl_video()
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 0); // Use black
SDL_RenderClear(sdl_renderer); // Clear the display

// We're about to work with sdl_update_video_rect, so stop other threads from
// modifying it!
LOCK_PALETTE;
SDL_LockMutex(sdl_update_video_mutex);
// Convert from the guest OS' pixel format, to the host OS' texture, if necessary.
if (host_surface != guest_surface &&
host_surface != NULL &&
guest_surface != NULL)
{
SDL_Rect destRect = sdl_update_video_rect;
LOCK_PALETTE;
SDL_LockMutex(sdl_update_video_mutex);
int result = SDL_BlitSurface(guest_surface, &sdl_update_video_rect, host_surface, &destRect);
SDL_UnlockMutex(sdl_update_video_mutex);
UNLOCK_PALETTE;
if (result != 0) return -1;
if (result != 0) {
SDL_UnlockMutex(sdl_update_video_mutex);
UNLOCK_PALETTE;
return -1;
}
}

// We're about to work with sdl_update_video_rect, so stop other threads from
// modifying it!
SDL_LockMutex(sdl_update_video_mutex);
UNLOCK_PALETTE; // passed potential deadlock, can unlock palette

// Update the host OS' texture
void * srcPixels = (void *)((uint8_t *)host_surface->pixels +
Expand Down

0 comments on commit a8bb479

Please sign in to comment.