Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

If required, lock the main video surface while blitting (this enables…

… to call 'sdl.Surface.Blit' from one goroutine and 'sdl.SetVideoMode' from another goroutine, while the two goroutines are allowed to execute in parallel, without requiring a mutex in the two goroutines)
  • Loading branch information...
commit aebe60ff9bf2a67587112a6303ea628af4e62399 1 parent 58be877
Tul project tul-project authored

Showing 1 changed file with 28 additions and 11 deletions. Show diff stats Hide diff stats

  1. +28 11 sdl/sdl.go
39 sdl/sdl.go
@@ -422,18 +422,35 @@ func (screen *Surface) Unlock() {
422 422 }
423 423
424 424 func (dst *Surface) Blit(dstrect *Rect, src *Surface, srcrect *Rect) int {
425   - src.mutex.RLock()
426   - dst.mutex.Lock()
427   -
428   - var ret = C.SDL_UpperBlit(
429   - src.cSurface,
430   - (*C.SDL_Rect)(cast(srcrect)),
431   - dst.cSurface,
432   - (*C.SDL_Rect)(cast(dstrect)))
433   -
434   - dst.mutex.Unlock()
435   - src.mutex.RUnlock()
  425 + GlobalMutex.Lock()
  426 + global := true
  427 + if (src != currentVideoSurface) && (dst != currentVideoSurface) {
  428 + GlobalMutex.Unlock()
  429 + global = false
  430 + }
  431 +
  432 + // At this point: GlobalMutex is locked only if at least one of 'src' or 'dst'
  433 + // was identical to 'currentVideoSurface'
  434 +
  435 + var ret C.int
  436 + {
  437 + src.mutex.RLock()
  438 + dst.mutex.Lock()
  439 +
  440 + ret = C.SDL_UpperBlit(
  441 + src.cSurface,
  442 + (*C.SDL_Rect)(cast(srcrect)),
  443 + dst.cSurface,
  444 + (*C.SDL_Rect)(cast(dstrect)))
  445 +
  446 + dst.mutex.Unlock()
  447 + src.mutex.RUnlock()
  448 + }
436 449
  450 + if global {
  451 + GlobalMutex.Unlock()
  452 + }
  453 +
437 454 return int(ret)
438 455 }
439 456

0 comments on commit aebe60f

Please sign in to comment.
Something went wrong with that request. Please try again.