Changing 64bit atomics to 32bit for alignment on ARM. (#2066)
This commit is contained in:
parent
f731267e8c
commit
dc2e6b9370
@ -19,13 +19,14 @@ import (
|
|||||||
//
|
//
|
||||||
// Start or Run (only of of them, not both) must be only called once.
|
// Start or Run (only of of them, not both) must be only called once.
|
||||||
type Cycle struct {
|
type Cycle struct {
|
||||||
|
stopsent int32
|
||||||
|
runexec int32
|
||||||
|
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
|
|
||||||
ticker *time.Ticker
|
ticker *time.Ticker
|
||||||
control chan interface{}
|
control chan interface{}
|
||||||
|
|
||||||
stopsent int64
|
|
||||||
runexec int64
|
|
||||||
stopping chan struct{}
|
stopping chan struct{}
|
||||||
stopped chan struct{}
|
stopped chan struct{}
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ func (cycle *Cycle) initialize() {
|
|||||||
|
|
||||||
// Start runs the specified function with an errgroup.
|
// Start runs the specified function with an errgroup.
|
||||||
func (cycle *Cycle) Start(ctx context.Context, group *errgroup.Group, fn func(ctx context.Context) error) {
|
func (cycle *Cycle) Start(ctx context.Context, group *errgroup.Group, fn func(ctx context.Context) error) {
|
||||||
atomic.CompareAndSwapInt64(&cycle.runexec, 0, 1)
|
atomic.CompareAndSwapInt32(&cycle.runexec, 0, 1)
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
return cycle.Run(ctx, fn)
|
return cycle.Run(ctx, fn)
|
||||||
})
|
})
|
||||||
@ -75,7 +76,7 @@ func (cycle *Cycle) Start(ctx context.Context, group *errgroup.Group, fn func(ct
|
|||||||
//
|
//
|
||||||
// Run PANICS if it's called after Stop has been called.
|
// Run PANICS if it's called after Stop has been called.
|
||||||
func (cycle *Cycle) Run(ctx context.Context, fn func(ctx context.Context) error) error {
|
func (cycle *Cycle) Run(ctx context.Context, fn func(ctx context.Context) error) error {
|
||||||
atomic.CompareAndSwapInt64(&cycle.runexec, 0, 1)
|
atomic.CompareAndSwapInt32(&cycle.runexec, 0, 1)
|
||||||
cycle.initialize()
|
cycle.initialize()
|
||||||
defer close(cycle.stopped)
|
defer close(cycle.stopped)
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ func (cycle *Cycle) Run(ctx context.Context, fn func(ctx context.Context) error)
|
|||||||
func (cycle *Cycle) Close() {
|
func (cycle *Cycle) Close() {
|
||||||
cycle.Stop()
|
cycle.Stop()
|
||||||
|
|
||||||
if atomic.LoadInt64(&cycle.runexec) == 1 {
|
if atomic.LoadInt32(&cycle.runexec) == 1 {
|
||||||
<-cycle.stopped
|
<-cycle.stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ func (cycle *Cycle) sendControl(message interface{}) {
|
|||||||
// Stop stops the cycle permanently
|
// Stop stops the cycle permanently
|
||||||
func (cycle *Cycle) Stop() {
|
func (cycle *Cycle) Stop() {
|
||||||
cycle.initialize()
|
cycle.initialize()
|
||||||
if atomic.CompareAndSwapInt64(&cycle.stopsent, 0, 1) {
|
if atomic.CompareAndSwapInt32(&cycle.stopsent, 0, 1) {
|
||||||
close(cycle.stopping)
|
close(cycle.stopping)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user