Skip to content

Commit

Permalink
minor perf improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
alphadose committed Jun 21, 2022
1 parent b6f84b2 commit efc9109
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions zenq.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ direct_send:
goto direct_send
}

slot := self.contents[(atomic.AddUint64(&self.writerIndex, 1)-1)&self.indexMask]
slot := self.contents[atomic.AddUint64(&self.writerIndex, 1)&self.indexMask]

// CAS -> change slot_state to busy if slot_state == empty
for !atomic.CompareAndSwapUint32(&slot.State, SlotEmpty, SlotBusy) {
Expand All @@ -180,7 +180,7 @@ direct_send:

// Read reads a value from the queue, you can once read once per object
func (self *ZenQ[T]) Read() (data T, queueOpen bool) {
slot := self.contents[(atomic.AddUint64(&self.readerIndex, 1)-1)&self.indexMask]
slot := self.contents[atomic.AddUint64(&self.readerIndex, 1)&self.indexMask]

// CAS -> change slot_state to busy if slot_state == committed
for !atomic.CompareAndSwapUint32(&slot.State, SlotCommitted, SlotBusy) {
Expand Down Expand Up @@ -227,7 +227,7 @@ func (self *ZenQ[T]) Close() (alreadyClosedForWrites bool) {
alreadyClosedForWrites = true
return
}
slot := self.contents[(atomic.AddUint64(&self.writerIndex, 1)-1)&self.indexMask]
slot := self.contents[atomic.AddUint64(&self.writerIndex, 1)&self.indexMask]

// CAS -> change slot_state to busy if slot_state == empty
for !atomic.CompareAndSwapUint32(&slot.State, SlotEmpty, SlotBusy) {
Expand Down

0 comments on commit efc9109

Please sign in to comment.