From cbf36734f80f558c76b5fb7ffa9bb3d88ae98d4b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 12 Aug 2019 20:48:26 +0900 Subject: [PATCH] shareable: Bug fix: mutex should not be used at finalizers Updates #913 --- internal/restorable/images.go | 6 ++---- internal/shareable/shareable.go | 10 ++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/internal/restorable/images.go b/internal/restorable/images.go index 44a6549fa..2e2f1ba94 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -56,10 +56,8 @@ var theImages = &images{ // // ResolveStaleImages is intended to be called at the end of a frame. func ResolveStaleImages() { - defer func() { - // Until the begin o the frame (by RestoreIfNeeded, any operations are deferred. - theImages.m.Lock() - }() + // Until the begin o the frame (by RestoreIfNeeded, any operations are locked. + defer theImages.m.Lock() graphicscommand.FlushCommands() if !needsRestoring() { diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index ef6427b40..6382aa902 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -73,9 +73,6 @@ func init() { } func resolveDeferred() { - deferredM.Lock() - defer deferredM.Unlock() - for _, f := range deferred { f() } @@ -151,8 +148,7 @@ var ( imagesToMakeShared = map[*Image]struct{}{} - deferred []func() - deferredM sync.Mutex + deferred []func() ) // isShareable reports whether the new allocation can use the shareable backends. @@ -388,9 +384,7 @@ func (i *Image) at(x, y int) (byte, byte, byte, byte) { // A function from finalizer must not be blocked, but disposing operation can be blocked. // Defer this operation until it becomes safe. (#913) func (i *Image) disposeFromFinalizer() { - deferredM.Lock() - defer deferredM.Unlock() - + // deferred doesn't have to be, and should not be protected by a mutex. deferred = append(deferred, func() { i.dispose(true) })