Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
barrier.hpp
Go to the documentation of this file.
1/**
2 * @file barrier.hpp
3 * @brief ARM Cortex-M memory barrier primitives
4 * @ingroup hal
5 *
6 * Direct memory barrier operations for ARM Cortex-M processors.
7 * No templates - just hardware primitives that compile to single instructions.
8 */
9
10#ifndef SBL_HAL_MEMORY_BARRIER_HPP_
11#define SBL_HAL_MEMORY_BARRIER_HPP_
12
13namespace sbl {
14namespace core {
15namespace hal {
16namespace memory {
17
18/**
19 * @brief Compiler memory barrier
20 *
21 * Prevents compiler from reordering memory operations.
22 * Sufficient for single-core ARM Cortex-M systems.
23 * Compiles to no instructions - affects compiler optimization only.
24 */
25inline void compiler_barrier() {
26 asm volatile("" ::: "memory");
27}
28
29/**
30 * @brief Data Memory Barrier (ARM DMB instruction)
31 *
32 * Ensures all memory operations before the barrier complete
33 * before any memory operations after the barrier begin.
34 * Compiles to single ARM DMB instruction.
35 */
36inline void data_barrier() {
37#ifdef __ARM_ARCH
38 asm volatile("dmb" ::: "memory");
39#else
40 compiler_barrier(); // Fallback for non-ARM builds
41#endif
42}
43
44/**
45 * @brief Data Synchronization Barrier (ARM DSB instruction)
46 *
47 * Ensures all memory operations and instructions complete
48 * before proceeding. Stronger than DMB.
49 * Compiles to single ARM DSB instruction.
50 */
51inline void sync_barrier() {
52#ifdef __ARM_ARCH
53 asm volatile("dsb" ::: "memory");
54#else
55 compiler_barrier(); // Fallback for non-ARM builds
56#endif
57}
58
59/**
60 * @brief Instruction Synchronization Barrier (ARM ISB instruction)
61 *
62 * Flushes pipeline and ensures all subsequent instructions
63 * are fetched from cache/memory after barrier effects complete.
64 * Compiles to single ARM ISB instruction.
65 */
66inline void instruction_barrier() {
67#ifdef __ARM_ARCH
68 asm volatile("isb" ::: "memory");
69#else
70 compiler_barrier(); // Fallback for non-ARM builds
71#endif
72}
73
74} // namespace memory
75} // namespace hal
76} // namespace core
77} // namespace sbl
78
79#endif // SBL_HAL_MEMORY_BARRIER_HPP_
void instruction_barrier()
Instruction Synchronization Barrier (ARM ISB instruction)
Definition barrier.hpp:66
void sync_barrier()
Data Synchronization Barrier (ARM DSB instruction)
Definition barrier.hpp:51
void compiler_barrier()
Compiler memory barrier.
Definition barrier.hpp:25
void data_barrier()
Data Memory Barrier (ARM DMB instruction)
Definition barrier.hpp:36
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24