giu
giu copied to clipboard
Introduce Context.WithLock
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:
- Texture load requests enqueued via EnqueueNewTextureFromRgba() are thread-safe
- Texture free requests triggered by finalizers are thread-safe
- 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