aboutsummaryrefslogtreecommitdiff
path: root/src/common/util_bug.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-04-15 09:12:03 -0400
committerNick Mathewson <nickm@torproject.org>2016-04-15 09:12:03 -0400
commit381dae43b6ecd5134820cd8212c71a6d7a56c36d (patch)
tree018121bdfce64c273241bbb75a40123504f7b3ad /src/common/util_bug.h
parent0e354ad45966d29ff4cd75854dbd1715270a2168 (diff)
downloadtor-381dae43b6ecd5134820cd8212c71a6d7a56c36d.tar.gz
tor-381dae43b6ecd5134820cd8212c71a6d7a56c36d.zip
Add branch prediction to util_bug.h, and fix a bug.
Diffstat (limited to 'src/common/util_bug.h')
-rw-r--r--src/common/util_bug.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/common/util_bug.h b/src/common/util_bug.h
index 26134502c6..36056aa4bd 100644
--- a/src/common/util_bug.h
+++ b/src/common/util_bug.h
@@ -64,7 +64,7 @@
#define tor_assert_nonfatal_unreached_once() tor_assert(0)
#define tor_assert_nonfatal_once(cond) tor_assert((cond))
#define BUG(cond) \
- ((cond) ? \
+ (PREDICT_UNLIKELY(cond) ? \
(tor_assertion_failed_(SHORT_FILE__,__LINE__,__func__,#cond), abort(), 1) \
: 0)
#elif defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS)
@@ -72,7 +72,7 @@
#define tor_assert_nonfatal(cond) ((void)(cond))
#define tor_assert_nonfatal_unreached_once() STMT_NIL
#define tor_assert_nonfatal_once(cond) ((void)(cond))
-#define BUG(cond) ((cond) ? 1 : 0)
+#define BUG(cond) (PREDICT_UNLIKELY(cond) ? 1 : 0)
#else /* Normal case, !ALL_BUGS_ARE_FATAL, !DISABLE_ASSERTS_IN_UNIT_TESTS */
#define tor_assert_nonfatal_unreached() STMT_BEGIN \
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, NULL, 0); \
@@ -97,7 +97,7 @@
} \
STMT_END
#define BUG(cond) \
- ((cond) ? \
+ (PREDICT_UNLIKELY(cond) ? \
(tor_bug_occurred_(SHORT_FILE__,__LINE__,__func__,#cond,0), 1) \
: 0)
#endif
@@ -107,15 +107,15 @@
if (({ \
static int var = 0; \
int bool_result = (cond); \
- if (bool_result && !var) { \
+ if (PREDICT_UNLIKELY(bool_result) && !var) { \
var = 1; \
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, #cond, 1); \
} \
- var; }))
+ PREDICT_UNLIKELY(bool_result); }))
#else
#define IF_BUG_ONCE__(cond,var) \
static int var = 0; \
- if ((cond) ? \
+ if (PREDICT_UNLIKELY(cond)) ? \
(var ? 1 : \
(var=1, \
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, #cond, 1), \