Skip to content

Commit

Permalink
Merge pull request #53 from qmuntal/fix-ops
Browse files Browse the repository at this point in the history
Fix unaligned panic on 32 bit arm
  • Loading branch information
qmuntal committed Feb 3, 2023
2 parents dace3b9 + 9a8022e commit c18926d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
go-version: [1.19.x, 1.20.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/qmuntal/stateless

go 1.17
go 1.19

require github.com/stretchr/testify v1.8.1

Expand Down
9 changes: 4 additions & 5 deletions statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func callEvents(events []TransitionFunc, ctx context.Context, transition Transit
// It is safe to use the StateMachine concurrently, but non of the callbacks (state manipulation, actions, events, ...) are guarded,
// so it is up to the client to protect them against race conditions.
type StateMachine struct {
// ops is accessed atomically so we put it at the beginning of the struct to achieve 64 bit alignment
ops uint64
ops atomic.Uint64
stateConfig map[State]*stateRepresentation
triggerConfig map[Trigger]triggerWithParameters
stateAccessor func(context.Context) (State, error)
Expand Down Expand Up @@ -276,7 +275,7 @@ func (sm *StateMachine) Configure(state State) *StateConfiguration {

// Firing returns true when the state machine is processing a trigger.
func (sm *StateMachine) Firing() bool {
return atomic.LoadUint64(&sm.ops) != 0
return sm.ops.Load() != 0
}

// String returns a human-readable representation of the state machine.
Expand Down Expand Up @@ -356,8 +355,8 @@ func (sm *StateMachine) internalFireQueued(ctx context.Context, trigger Trigger,
}

func (sm *StateMachine) internalFireOne(ctx context.Context, trigger Trigger, args ...interface{}) (err error) {
atomic.AddUint64(&sm.ops, 1)
defer atomic.AddUint64(&sm.ops, ^uint64(0))
sm.ops.Add(1)
defer sm.ops.Add(^uint64(0))
var (
config triggerWithParameters
ok bool
Expand Down

0 comments on commit c18926d

Please sign in to comment.