1616
1717package cats .effect .unsafe
1818
19+ import scala .scalanative .annotation .align
1920import scala .scalanative .libc .stdatomic ._
20- import scala .scalanative .libc .stdatomic .memory_order .memory_order_release
21+ import scala .scalanative .libc .stdatomic .memory_order ._
2122import scala .scalanative .runtime .{fromRawPtr , Intrinsics }
2223
2324// native mirror of LocalQueue.java
@@ -47,7 +48,7 @@ private class Head {
4748 * during this period, making sure to undo the changes to the ''steal'' tag of the head on
4849 * completion, action which ultimately signals that stealing is finished.
4950 */
50- @ volatile
51+ @ align( 128 )
5152 protected var head : Int = 0
5253
5354 {
@@ -60,12 +61,14 @@ private object Head {
6061 private [unsafe] object updater {
6162
6263 def get (obj : Head ): Int =
63- fromRawPtr[atomic_int](Intrinsics .classFieldRawPtr[Head ](obj, " head" )).atomic.load()
64+ fromRawPtr[atomic_int](Intrinsics .classFieldRawPtr[Head ](obj, " head" ))
65+ .atomic
66+ .load(memory_order_acquire)
6467
6568 def compareAndSet (obj : Head , oldHd : Int , newHd : Int ): Boolean =
6669 fromRawPtr[atomic_int](Intrinsics .classFieldRawPtr[Head ](obj, " head" ))
6770 .atomic
68- .compareExchangeStrong(oldHd, newHd)
71+ .compareExchangeStrong(oldHd, newHd, memory_order_acq_rel, memory_order_acquire )
6972 }
7073}
7174
@@ -81,6 +84,7 @@ private class Tail extends Head {
8184 * <p>Conceptually, it is an unsigned 16 bit value (the most significant 16 bits of the
8285 * integer value are ignored in most operations).
8386 */
87+ @ align(128 )
8488 protected var tail : Int = 0
8589}
8690
@@ -89,7 +93,9 @@ private object Tail {
8993 private [unsafe] object updater {
9094
9195 def get (obj : Tail ): Int =
92- fromRawPtr[atomic_int](Intrinsics .classFieldRawPtr[Tail ](obj, " tail" )).atomic.load()
96+ fromRawPtr[atomic_int](Intrinsics .classFieldRawPtr[Tail ](obj, " tail" ))
97+ .atomic
98+ .load(memory_order_acquire)
9399
94100 def lazySet (obj : Tail , newValue : Int ): Unit =
95101 fromRawPtr[atomic_int](Intrinsics .classFieldRawPtr[Tail ](obj, " tail" ))
@@ -98,4 +104,7 @@ private object Tail {
98104 }
99105}
100106
101- private class LocalQueuePadding extends Tail
107+ private class LocalQueuePadding extends Tail {
108+ @ align(128 )
109+ private val _padding : Long = 0L
110+ }
0 commit comments