shareable: Bug fix: mutex should not be used at finalizers

Updates #913
This commit is contained in:
Hajime Hoshi 2019-08-12 20:48:26 +09:00
parent 28dd2f6e19
commit cbf36734f8
2 changed files with 4 additions and 12 deletions

View File

@ -56,10 +56,8 @@ var theImages = &images{
// //
// ResolveStaleImages is intended to be called at the end of a frame. // ResolveStaleImages is intended to be called at the end of a frame.
func ResolveStaleImages() { func ResolveStaleImages() {
defer func() { // Until the begin o the frame (by RestoreIfNeeded, any operations are locked.
// Until the begin o the frame (by RestoreIfNeeded, any operations are deferred. defer theImages.m.Lock()
theImages.m.Lock()
}()
graphicscommand.FlushCommands() graphicscommand.FlushCommands()
if !needsRestoring() { if !needsRestoring() {

View File

@ -73,9 +73,6 @@ func init() {
} }
func resolveDeferred() { func resolveDeferred() {
deferredM.Lock()
defer deferredM.Unlock()
for _, f := range deferred { for _, f := range deferred {
f() f()
} }
@ -151,8 +148,7 @@ var (
imagesToMakeShared = map[*Image]struct{}{} imagesToMakeShared = map[*Image]struct{}{}
deferred []func() deferred []func()
deferredM sync.Mutex
) )
// isShareable reports whether the new allocation can use the shareable backends. // 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. // A function from finalizer must not be blocked, but disposing operation can be blocked.
// Defer this operation until it becomes safe. (#913) // Defer this operation until it becomes safe. (#913)
func (i *Image) disposeFromFinalizer() { func (i *Image) disposeFromFinalizer() {
deferredM.Lock() // deferred doesn't have to be, and should not be protected by a mutex.
defer deferredM.Unlock()
deferred = append(deferred, func() { deferred = append(deferred, func() {
i.dispose(true) i.dispose(true)
}) })