Skip to content

Commit 736db40

Browse files
kalkyljamesmunns
authored andcommitted
Add compiler fences
1 parent 5fd6d10 commit 736db40

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

nrf-hal-common/src/spis.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ where
156156
/// Requests acquiring the SPIS semaphore and waits until acquired.
157157
#[inline(always)]
158158
pub fn acquire(&self) -> &Self {
159-
self.enable();
159+
compiler_fence(Ordering::SeqCst);
160160
self.0.tasks_acquire.write(|w| unsafe { w.bits(1) });
161161
while self.0.events_acquired.read().bits() == 0 {}
162162
self
@@ -311,6 +311,7 @@ where
311311
if maxcnt > EASY_DMA_SIZE {
312312
return Err(Error::BufferTooLong);
313313
}
314+
compiler_fence(Ordering::SeqCst);
314315
self.0
315316
.txd
316317
.ptr
@@ -359,7 +360,7 @@ where
359360
if (tx_ptr as usize) < SRAM_LOWER || (tx_ptr as usize) > SRAM_UPPER {
360361
return Err(Error::DMABufferNotInDataMemory);
361362
}
362-
363+
compiler_fence(Ordering::SeqCst);
363364
self.0
364365
.txd
365366
.ptr
@@ -406,13 +407,13 @@ struct Inner<T: Instance, B> {
406407
impl<T: Instance, B> Transfer<T, B> {
407408
/// Blocks until the transfer is done and returns the buffer.
408409
pub fn wait(mut self) -> (B, Spis<T>) {
410+
compiler_fence(Ordering::SeqCst);
409411
let inner = self
410412
.inner
411413
.take()
412414
.unwrap_or_else(|| unsafe { core::hint::unreachable_unchecked() });
413415
while !inner.spis.is_done() {}
414416
inner.spis.acquire();
415-
compiler_fence(Ordering::Acquire);
416417
(inner.buffer, inner.spis)
417418
}
418419

@@ -430,9 +431,9 @@ impl<T: Instance, B> Transfer<T, B> {
430431
impl<T: Instance, B> Drop for Transfer<T, B> {
431432
fn drop(&mut self) {
432433
if let Some(inner) = self.inner.as_mut() {
434+
compiler_fence(Ordering::SeqCst);
433435
while !inner.spis.is_done() {}
434436
inner.spis.disable();
435-
compiler_fence(Ordering::Acquire);
436437
}
437438
}
438439
}
@@ -450,13 +451,13 @@ struct InnerSplit<T: Instance, TxB, RxB> {
450451
impl<T: Instance, TxB, RxB> TransferSplit<T, TxB, RxB> {
451452
/// Blocks until the transfer is done and returns the buffer.
452453
pub fn wait(mut self) -> (TxB, RxB, Spis<T>) {
454+
compiler_fence(Ordering::SeqCst);
453455
let inner = self
454456
.inner
455457
.take()
456458
.unwrap_or_else(|| unsafe { core::hint::unreachable_unchecked() });
457459
while !inner.spis.is_done() {}
458460
inner.spis.acquire();
459-
compiler_fence(Ordering::Acquire);
460461
(inner.tx_buffer, inner.rx_buffer, inner.spis)
461462
}
462463

@@ -474,9 +475,9 @@ impl<T: Instance, TxB, RxB> TransferSplit<T, TxB, RxB> {
474475
impl<T: Instance, TxB, RxB> Drop for TransferSplit<T, TxB, RxB> {
475476
fn drop(&mut self) {
476477
if let Some(inner) = self.inner.as_mut() {
478+
compiler_fence(Ordering::SeqCst);
477479
while !inner.spis.is_done() {}
478480
inner.spis.disable();
479-
compiler_fence(Ordering::Acquire);
480481
}
481482
}
482483
}

0 commit comments

Comments
 (0)