Skip to content

Commit

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

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

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

Expand Down Expand Up @@ -96,7 +97,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, stopped, starting) {
if atomic.CompareAndSwapInt32(&in.procStatus, new, starting) {
in.proc = proc
atomic.SwapInt32(&in.procStatus, idle)
in.schedule()
Expand Down

0 comments on commit 9ed8594

Please sign in to comment.