Skip to content

Commit

Permalink
Reorder shutdown functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Oct 20, 2023
1 parent 10c4cd9 commit 9cce72c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/worker/caged/libretro/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,12 @@ func (f *Frontend) SetOnAV(fn func()) { f.nano.OnSystemAvInfo = fn }
func (f *Frontend) Start() {
f.log.Debug().Msgf("frontend start")

f.done = make(chan struct{})
f.nano.LastFrameTime = time.Now().UnixNano()

f.mui.Lock()
defer f.Shutdown()
defer f.mui.Unlock()

f.done = make(chan struct{})
f.nano.LastFrameTime = time.Now().UnixNano()

if f.HasSave() {
// advance 1 frame for Mupen save state
if f.nano.LibCo {
Expand Down Expand Up @@ -306,17 +305,19 @@ func (f *Frontend) ViewportCalc() (nw int, nh int) {

func (f *Frontend) Close() {
f.log.Debug().Msgf("frontend close")

close(f.done)

f.mui.Lock()
defer f.mui.Unlock()
// Save game on quit if it was saved before (shared or click-saved).
if f.SaveOnClose && f.HasSave() {
f.log.Debug().Msg("Save on quit")
f.log.Debug().Msg("save on quit")
if err := f.Save(); err != nil {
f.log.Error().Err(err).Msg("save on quit failed")
}
}
f.Shutdown()
f.nano.Close()
f.log.Debug().Msgf("frontend closed")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/worker/caged/libretro/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func (emu *TestFrontend) Shutdown() {
_ = os.Remove(emu.HashPath())
_ = os.Remove(emu.SRAMPath())
emu.Frontend.Close()
emu.Frontend.Shutdown()
}

// dumpState returns both current and previous emulator save state as MD5 hash string.
Expand Down

0 comments on commit 9cce72c

Please sign in to comment.