restorable: Remove unneeded mutex

This commit is contained in:
Hajime Hoshi 2018-03-25 23:40:33 +09:00
parent 97ce612785
commit c767c0631e

View File

@ -16,7 +16,6 @@ package restorable
import ( import (
"github.com/hajimehoshi/ebiten/internal/graphics" "github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/sync"
) )
// restoringEnabled indicates if restoring happens or not. // restoringEnabled indicates if restoring happens or not.
@ -41,7 +40,6 @@ func EnableRestoringForTesting() {
type images struct { type images struct {
images map[*Image]struct{} images map[*Image]struct{}
lastTarget *Image lastTarget *Image
m sync.Mutex
} }
// theImages represents the images for the current process. // theImages represents the images for the current process.
@ -75,23 +73,17 @@ func Restore() error {
// add adds img to the images. // add adds img to the images.
func (i *images) add(img *Image) { func (i *images) add(img *Image) {
i.m.Lock()
i.images[img] = struct{}{} i.images[img] = struct{}{}
i.m.Unlock()
} }
// remove removes img from the images. // remove removes img from the images.
func (i *images) remove(img *Image) { func (i *images) remove(img *Image) {
i.m.Lock()
i.makeStaleIfDependingOnImpl(img) i.makeStaleIfDependingOnImpl(img)
delete(i.images, img) delete(i.images, img)
i.m.Unlock()
} }
// resolveStaleImages resolves stale images. // resolveStaleImages resolves stale images.
func (i *images) resolveStaleImages() error { func (i *images) resolveStaleImages() error {
i.m.Lock()
defer i.m.Unlock()
i.lastTarget = nil i.lastTarget = nil
for img := range i.images { for img := range i.images {
if err := img.resolveStale(); err != nil { if err := img.resolveStale(); err != nil {
@ -107,9 +99,7 @@ func (i *images) resolveStaleImages() error {
// makeStaleIfDependingOn is called in such situation. // makeStaleIfDependingOn is called in such situation.
func (i *images) makeStaleIfDependingOn(target *Image) { func (i *images) makeStaleIfDependingOn(target *Image) {
// Avoid defer for performance // Avoid defer for performance
i.m.Lock()
i.makeStaleIfDependingOnImpl(target) i.makeStaleIfDependingOnImpl(target)
i.m.Unlock()
} }
func (i *images) makeStaleIfDependingOnImpl(target *Image) { func (i *images) makeStaleIfDependingOnImpl(target *Image) {
@ -129,8 +119,6 @@ func (i *images) makeStaleIfDependingOnImpl(target *Image) {
// //
// Restoring means to make all *graphics.Image objects have their textures and framebuffers. // Restoring means to make all *graphics.Image objects have their textures and framebuffers.
func (i *images) restore() error { func (i *images) restore() error {
i.m.Lock()
defer i.m.Unlock()
if !IsRestoringEnabled() { if !IsRestoringEnabled() {
panic("not reached") panic("not reached")
} }