giu icon indicating copy to clipboard operation
giu copied to clipboard

Introduce Context.WithLock

Open dizzyd opened this issue 4 months ago • 0 comments

Summary

  • Introduces Context.WithLock() method to provide thread-safe access to context operations
  • Wraps texture loading and freeing queue operations with proper mutex protection
  • Prevents race conditions when multiple threads enqueue texture operations simultaneously

The texture loading and freeing queues were not thread-safe when accessed from multiple goroutines. This could lead to queue corruption and unpredictable behavior when textures were being loaded or freed concurrently.

Thus, I added a WithLock() method to the GIUContext that safely executes functions while holding the context mutex. This ensures that:

  1. Texture load requests enqueued via EnqueueNewTextureFromRgba() are thread-safe
  2. Texture free requests triggered by finalizers are thread-safe
  3. Queue processing in the render loop is protected from concurrent modifications

Files modified:

  • Context.go: Added WithLock() method for safe mutex-protected operations
  • MasterWindow.go: Wrapped texture queue processing in WithLock() during render
  • Texture.go: Protected queue operations in both EnqueueNewTextureFromRgba() and the texture finalizer

dizzyd avatar Aug 23 '25 17:08 dizzyd