Atomically replace opcode only if it still matches `expected`. Returns true on success. Uses Release ordering on success. # Safety - `index` must be in bounds.
(
&self,
index: usize,
expected: Instruction,
new_op: Instruction,
)
| 662 | /// # Safety |
| 663 | /// - `index` must be in bounds. |
| 664 | pub unsafe fn compare_exchange_op( |
| 665 | &self, |
| 666 | index: usize, |
| 667 | expected: Instruction, |
| 668 | new_op: Instruction, |
| 669 | ) -> bool { |
| 670 | let units = unsafe { &*self.units.get() }; |
| 671 | let ptr = units.as_ptr().wrapping_add(index) as *const AtomicU8; |
| 672 | unsafe { &*ptr } |
| 673 | .compare_exchange( |
| 674 | expected.into(), |
| 675 | new_op.into(), |
| 676 | Ordering::Release, |
| 677 | Ordering::Relaxed, |
| 678 | ) |
| 679 | .is_ok() |
| 680 | } |
| 681 | |
| 682 | /// Atomically read the opcode at `index` with Acquire ordering. |
| 683 | /// Pairs with `replace_op` (Release) to ensure cache data visibility. |