Skip to content

Commit

Permalink
[Chore] Make isSleep uint32 instead of uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
maypok86 committed Mar 5, 2024
1 parent 21d0a9d commit 12be6ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/queue/mpsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type MPSC[T any] struct {
headPadding [xruntime.CacheLineSize - 8]byte
tail uint64
tailPadding [xruntime.CacheLineSize - 8]byte
isSleep uint64
sleepPadding [xruntime.CacheLineSize - 8]byte
isSleep uint32
sleepPadding [xruntime.CacheLineSize - 4]byte
slots []slot[T]
}

Expand Down Expand Up @@ -118,15 +118,15 @@ func (q *MPSC[T]) Capacity() int {
}

func (q *MPSC[T]) wakeUpConsumer() {
if atomic.LoadUint64(&q.isSleep) == 1 && atomic.CompareAndSwapUint64(&q.isSleep, 1, 0) {
if atomic.LoadUint32(&q.isSleep) == 1 && atomic.CompareAndSwapUint32(&q.isSleep, 1, 0) {
// if the consumer is asleep, we'll wake him up.
q.sleep <- struct{}{}
}
}

func (q *MPSC[T]) sleepConsumer() {
// if the queue's been empty for too long, we fall asleep.
atomic.StoreUint64(&q.isSleep, 1)
atomic.StoreUint32(&q.isSleep, 1)
<-q.sleep
}

Expand Down

0 comments on commit 12be6ef

Please sign in to comment.