summaryrefslogtreecommitdiff
path: root/ucoolib/common.hh
diff options
context:
space:
mode:
authorNicolas Schodet2012-12-15 16:06:59 +0100
committerNicolas Schodet2019-10-06 23:29:59 +0200
commit2556b8e081cd0d5c7b5a4f95b64280f94bf12123 (patch)
tree213dd080ad63fd580fe35fa9908445edcf9e811e /ucoolib/common.hh
parent1c8eafd80ef2b6db5148c747b45198b5d86924a8 (diff)
ucoolib/utils: add fifo low level container
Diffstat (limited to 'ucoolib/common.hh')
-rw-r--r--ucoolib/common.hh11
1 files changed, 11 insertions, 0 deletions
diff --git a/ucoolib/common.hh b/ucoolib/common.hh
index 1f6d75a..8376389 100644
--- a/ucoolib/common.hh
+++ b/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));