summaryrefslogtreecommitdiffhomepage
path: root/digital/ucoolib/ucoolib/common.hh
diff options
context:
space:
mode:
authorNicolas Schodet2012-11-21 22:38:31 +0100
committerNicolas Schodet2012-12-01 18:52:16 +0100
commita39a53cf167337edf8dc7be13925adb77cb6e7ad (patch)
tree0b58664a3e9bc971e8dac125f00586bfec511c7e /digital/ucoolib/ucoolib/common.hh
parent5cac146b50a70173a9007f698acd3d78357f6836 (diff)
digital/ucoolib: add assert function
No assert message, no file, no line number, no fat.
Diffstat (limited to 'digital/ucoolib/ucoolib/common.hh')
-rw-r--r--digital/ucoolib/ucoolib/common.hh35
1 files changed, 35 insertions, 0 deletions
diff --git a/digital/ucoolib/ucoolib/common.hh b/digital/ucoolib/ucoolib/common.hh
index a27dfe3b..5be6227f 100644
--- a/digital/ucoolib/ucoolib/common.hh
+++ b/digital/ucoolib/ucoolib/common.hh
@@ -35,6 +35,41 @@ barrier ()
__asm__ __volatile__("": : : "memory");
}
+/// Stop, abruptly.
+void
+halt () __attribute__ ((noreturn));
+
+/// Stop, try to output error description corresponding to errno.
+void
+halt_perror () __attribute__ ((noreturn));
+
+/// To be used to swear that the given condition is true. If this is not the
+/// case... well... you swore!
+extern inline void
+assert (bool condition)
+{
+ if (!condition)
+ halt ();
+}
+
+/// To be used to swear that this code can never be reached.
+void
+assert_unreachable () __attribute__ ((noreturn));
+extern inline void
+assert_unreachable ()
+{
+ halt ();
+}
+
+/// To be used to swear that the given condition is true, but print errno
+/// description anyway in case you lied.
+extern inline void
+assert_perror (bool condition)
+{
+ if (!condition)
+ halt_perror ();
+}
+
} // namespace ucoo
#endif // ucoolib_common_h