add an implementation of memory transactions + tests

Change-Id: Id901328da7d246268b7af951729acb1fada06836
diff --git a/aos/common/util/BUILD b/aos/common/util/BUILD
index 646f3bf..bd70463 100644
--- a/aos/common/util/BUILD
+++ b/aos/common/util/BUILD
@@ -172,3 +172,10 @@
     '//aos/testing:googletest',
   ],
 )
+
+cc_library(
+  name = 'compiler_memory_barrier',
+  hdrs = [
+    'compiler_memory_barrier.h',
+  ],
+)
diff --git a/aos/common/util/compiler_memory_barrier.h b/aos/common/util/compiler_memory_barrier.h
new file mode 100644
index 0000000..5126941
--- /dev/null
+++ b/aos/common/util/compiler_memory_barrier.h
@@ -0,0 +1,11 @@
+#ifndef AOS_COMMON_UTIL_COMPILER_MEMORY_BARRIER_H_
+#define AOS_COMMON_UTIL_COMPILER_MEMORY_BARRIER_H_
+
+// Prevents the compiler from reordering memory operations around this.
+// Using this function makes it clearer what you're doing and easier to be
+// portable.
+static inline void aos_compiler_memory_barrier(void) {
+  __asm__ __volatile__("" ::: "memory");
+}
+
+#endif  // AOS_COMMON_UTIL_COMPILER_MEMORY_BARRIER_H_