loop: Reduce defer for performance and readability

This commit is contained in:
Hajime Hoshi 2017-08-05 20:19:08 +09:00
parent 9f98ccc611
commit 56a17a7f79

View File

@ -47,26 +47,28 @@ var (
func (c *runContext) startRunning() {
c.m.Lock()
defer c.m.Unlock()
c.running = true
c.m.Unlock()
}
func (c *runContext) isRunning() bool {
c.m.RLock()
defer c.m.RUnlock()
return c.running
v := c.running
c.m.RUnlock()
return v
}
func (c *runContext) endRunning() {
c.m.Lock()
defer c.m.Unlock()
c.running = false
c.m.Unlock()
}
func (c *runContext) getCurrentFPS() float64 {
c.m.RLock()
defer c.m.RUnlock()
if !c.running {
v := c.running
c.m.RUnlock()
if !v {
// TODO: Should panic here?
return 0
}
@ -75,8 +77,8 @@ func (c *runContext) getCurrentFPS() float64 {
func (c *runContext) updateFPS(fps float64) {
c.m.Lock()
defer c.m.Unlock()
c.currentFPS = fps
c.m.Unlock()
}
type GraphicsContext interface {