Skip to content

Commit

Permalink
finally fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
troygilman0 committed Nov 3, 2024
1 parent 9ed8594 commit 004e578
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions actor/inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ const (
)

const (
new int32 = iota
stopped int32 = iota
starting
idle
running
stopped
)

type Scheduler interface {
Expand Down Expand Up @@ -56,7 +55,7 @@ func NewInbox(size int) *Inbox {
return &Inbox{
rb: ringbuffer.New[Envelope](int64(size)),
scheduler: NewScheduler(defaultThroughput),
procStatus: new,
procStatus: stopped,
}
}

Expand All @@ -73,7 +72,7 @@ func (in *Inbox) schedule() {

func (in *Inbox) process() {
in.run()
if in.procStatus != stopped {
if atomic.LoadInt32(&in.procStatus) != stopped {
atomic.StoreInt32(&in.procStatus, idle)
}
}
Expand All @@ -97,7 +96,7 @@ func (in *Inbox) run() {

func (in *Inbox) Start(proc Processer) {
// transition to "starting" and then "idle" to ensure no race condition on in.proc
if atomic.CompareAndSwapInt32(&in.procStatus, new, starting) {
if atomic.CompareAndSwapInt32(&in.procStatus, stopped, starting) {
in.proc = proc
atomic.SwapInt32(&in.procStatus, idle)
in.schedule()
Expand Down

0 comments on commit 004e578

Please sign in to comment.