@@ -75,12 +75,12 @@ type (
75
75
_p2 [constants .CacheLinePadSize - unsafe .Sizeof (uint32 (0 ))]byte
76
76
globalState uint32
77
77
indexMask uint32
78
- strideLength uintptr
78
+ strideLength uint16
79
79
contents unsafe.Pointer
80
80
// memory pool refs for storing and leasing parking spots for goroutines
81
81
alloc func () any
82
82
free func (any )
83
- _p3 [constants .CacheLinePadSize - 2 * unsafe .Sizeof (uint32 (0 )) - 2 * unsafe .Sizeof (func () {}) - unsafe .Sizeof ( unsafe . Pointer (nil )) - unsafe . Sizeof ( uintptr ( 0 ))]byte
83
+ _p3 [constants .CacheLinePadSize - 2 * unsafe .Sizeof (uint32 (0 )) - 4 * unsafe .Sizeof (unsafe .Pointer (nil ))]byte
84
84
selectFactory
85
85
_p4 [constants .CacheLinePadSize - unsafe .Sizeof (selectFactory {})]byte
86
86
}
@@ -104,7 +104,7 @@ func New[T any](size uint32) *ZenQ[T] {
104
104
contents [idx ].writeParker = NewThreadParker [T ](unsafe .Pointer (n ))
105
105
}
106
106
zenq := & ZenQ [T ]{
107
- strideLength : unsafe .Sizeof (slot [T ]{}),
107
+ strideLength : uint16 ( unsafe .Sizeof (slot [T ]{}) ),
108
108
contents : unsafe .Pointer (& contents [0 ]),
109
109
alloc : parkPool .Get ,
110
110
free : parkPool .Put ,
@@ -150,7 +150,7 @@ direct_send:
150
150
goto direct_send
151
151
}
152
152
153
- slot := (* slot [T ])(unsafe .Pointer (uintptr (atomic .AddUint32 (& self .writerIndex , 1 )& self .indexMask )* self .strideLength + uintptr (self .contents )))
153
+ slot := (* slot [T ])(unsafe .Pointer (uintptr (( atomic .AddUint32 (& self .writerIndex , 1 )& self .indexMask )) * uintptr ( self .strideLength ) + uintptr (self .contents )))
154
154
155
155
// CAS -> change slot_state to busy if slot_state == empty
156
156
for ! atomic .CompareAndSwapUint32 (& slot .state , SlotEmpty , SlotBusy ) {
@@ -176,7 +176,7 @@ direct_send:
176
176
177
177
// Read reads a value from the queue, you can once read once per object
178
178
func (self * ZenQ [T ]) Read () (data T , queueOpen bool ) {
179
- slot := (* slot [T ])(unsafe .Pointer (uintptr (atomic .AddUint32 (& self .readerIndex , 1 )& self .indexMask )* self .strideLength + uintptr (self .contents )))
179
+ slot := (* slot [T ])(unsafe .Pointer (uintptr (atomic .AddUint32 (& self .readerIndex , 1 )& self .indexMask )* uintptr ( self .strideLength ) + uintptr (self .contents )))
180
180
181
181
// CAS -> change slot_state to busy if slot_state == committed
182
182
for ! atomic .CompareAndSwapUint32 (& slot .state , SlotCommitted , SlotBusy ) {
@@ -225,7 +225,7 @@ func (self *ZenQ[T]) Close() (alreadyClosedForWrites bool) {
225
225
alreadyClosedForWrites = true
226
226
return
227
227
}
228
- slot := (* slot [T ])(unsafe .Pointer (uintptr (atomic .AddUint32 (& self .writerIndex , 1 )& self .indexMask )* self .strideLength + uintptr (self .contents )))
228
+ slot := (* slot [T ])(unsafe .Pointer (uintptr (atomic .AddUint32 (& self .writerIndex , 1 )& self .indexMask )* uintptr ( self .strideLength ) + uintptr (self .contents )))
229
229
230
230
// CAS -> change slot_state to busy if slot_state == empty
231
231
for ! atomic .CompareAndSwapUint32 (& slot .state , SlotEmpty , SlotBusy ) {
0 commit comments