Fix deadlock in Stop
This commit is contained in:
22
tomo.go
22
tomo.go
@@ -1,15 +1,37 @@
|
||||
package tomo
|
||||
|
||||
import "sync"
|
||||
import "image"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
|
||||
// TODO this really sucks. It might be a good idea to have Do be the entry point
|
||||
// for every off-thread call, and Stop should just call backend.Stop within
|
||||
// backend.Do. This is because Do is a queue and is not vulnerable to recursive
|
||||
// locking.
|
||||
|
||||
var stopping bool
|
||||
var stoppingLock sync.Mutex
|
||||
func isStopping () bool {
|
||||
stoppingLock.Lock()
|
||||
defer stoppingLock.Unlock()
|
||||
return stopping
|
||||
}
|
||||
func setStopping (is bool) {
|
||||
stoppingLock.Lock()
|
||||
defer stoppingLock.Unlock()
|
||||
stopping = is
|
||||
}
|
||||
|
||||
// Stop stops the currently running backend.
|
||||
func Stop () {
|
||||
if isStopping() { return }
|
||||
setStopping(true)
|
||||
backendLock.Lock()
|
||||
defer backendLock.Unlock()
|
||||
if backend == nil { return }
|
||||
backend.Stop()
|
||||
backend = nil
|
||||
setStopping(false)
|
||||
}
|
||||
|
||||
// Do performs a callback function in the event loop thread as soon as possible.
|
||||
|
||||
Reference in New Issue
Block a user