summaryrefslogtreecommitdiff
path: root/digital/ucoolib/ucoolib/common.hh
diff options
context:
space:
mode:
Diffstat (limited to 'digital/ucoolib/ucoolib/common.hh')
-rw-r--r--digital/ucoolib/ucoolib/common.hh11
1 files changed, 11 insertions, 0 deletions
diff --git a/digital/ucoolib/ucoolib/common.hh b/digital/ucoolib/ucoolib/common.hh
index 1f6d75ae..83763899 100644
--- a/digital/ucoolib/ucoolib/common.hh
+++ b/digital/ucoolib/ucoolib/common.hh
@@ -27,6 +27,9 @@
namespace ucoo {
+/// Integer which is read and written atomically.
+typedef int int_atomic_t;
+
/// Compiler barrier. Prevents the compiler from moving the memory accesses
/// from one side of it to the other side.
extern inline void
@@ -35,6 +38,14 @@ barrier ()
__asm__ __volatile__("": : : "memory");
}
+/// Ensure a single access is done, avoid compiler optimisations.
+template<typename T>
+extern inline volatile T &
+access_once (T &x)
+{
+ return *static_cast<volatile T *> (&x);
+}
+
/// Stop, abruptly.
void
halt () __attribute__ ((noreturn));