Skip to content

Commit

Permalink
internal/driver: allow graceful receiving
Browse files Browse the repository at this point in the history
  • Loading branch information
changkun authored and andydotxyz committed Oct 18, 2021
1 parent da91097 commit 3a9d1d3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/driver/common/canvas.go
@@ -1,6 +1,7 @@
package common

import (
"runtime"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -202,7 +203,17 @@ func (c *Canvas) FreeDirtyTextures() uint64 {
// in a frame. Use a counter to guarantee that all desired tasks are
// processed. See https://github.com/fyne-io/fyne/issues/2548.
for atomic.LoadUint64(&c.refreshCount) > 0 {
object := <-c.refreshQueue.Out()
var object fyne.CanvasObject
select {
case object = <-c.refreshQueue.Out():
default:
// If refreshCount is positive but we cannot receive any object
// from the refreshQueue, this means that the refresh task is
// not yet ready to receive, continue until we can receive it.
// Furthermore, we use Gosched to avoid CPU spin.
runtime.Gosched()
continue
}
atomic.AddUint64(&c.refreshCount, ^uint64(0))
freed++
freeWalked := func(obj fyne.CanvasObject, _ fyne.Position, _ fyne.Position, _ fyne.Size) bool {
Expand Down

0 comments on commit 3a9d1d3

Please sign in to comment.