Skip to content

Commit

Permalink
fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Feb 1, 2024
1 parent cca9945 commit 9f322e7
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions widget/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package widget

import (
"image/color"
"sync/atomic"
"time"

"fyne.io/fyne/v2"
Expand All @@ -19,7 +20,7 @@ var _ fyne.Widget = (*Activity)(nil)
type Activity struct {
BaseWidget

started bool
started atomic.Bool
}

// NewActivity returns a widget for indicating activity
Expand All @@ -39,29 +40,21 @@ func (a *Activity) MinSize() fyne.Size {

// Start the activity indicator animation
func (a *Activity) Start() {
a.propertyLock.Lock()
defer a.propertyLock.Unlock()

if a.started {
return
if !a.started.CompareAndSwap(false, true) {
return // already started
}

a.started = true
if r, ok := cache.Renderer(a.super()).(*activityRenderer); ok {
r.start()
}
}

// Stop the activity indicator animation
func (a *Activity) Stop() {
a.propertyLock.Lock()
defer a.propertyLock.Unlock()

if !a.started {
return
if !a.started.CompareAndSwap(true, false) {
return // already stopped
}

a.started = false
if r, ok := cache.Renderer(a.super()).(*activityRenderer); ok {
r.stop()
}
Expand All @@ -79,11 +72,9 @@ func (a *Activity) CreateRenderer() fyne.WidgetRenderer {
Tick: r.animate}
r.updateColor()

a.propertyLock.RLock()
if a.started {
if a.started.Load() {
r.start()
}
a.propertyLock.RUnlock()

return r
}
Expand Down

0 comments on commit 9f322e7

Please sign in to comment.