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.
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() {

View File

@ -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)
})