[libbluray-devel] Optimized bd_debug calling: check debug mask before calling the function. Optimize branches for no logging.
hpi1
git at videolan.org
Sun Mar 10 18:38:09 CET 2013
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun Mar 10 19:35:46 2013 +0200| [733d98129dab66f55227d978c7743416eb3e81f7] | committer: hpi1
Optimized bd_debug calling: check debug mask before calling the function. Optimize branches for no logging.
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=733d98129dab66f55227d978c7743416eb3e81f7
---
src/util/attributes.h | 8 ++++++++
src/util/logging.c | 2 +-
src/util/logging.h | 10 ++++++++--
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/util/attributes.h b/src/util/attributes.h
index cbaade6..c16853e 100644
--- a/src/util/attributes.h
+++ b/src/util/attributes.h
@@ -46,4 +46,12 @@
# define BD_PRIVATE
#endif
+#if !defined(__GNUC__) || __GNUC__ < 3
+# define BD_LIKELY(x) (x)
+# define BD_UNLIKELY(x) (x)
+#else
+# define BD_LIKELY(x) __builtin_expect((x),1)
+# define BD_UNLIKELY(x) __builtin_expect((x),0)
+#endif
+
#endif /* LIBBLURAY_ATTRIBUTES_H_ */
diff --git a/src/util/logging.c b/src/util/logging.c
index 1fa63d0..d881478 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -25,7 +25,7 @@
#include <stdarg.h>
#include <string.h>
-static uint32_t debug_mask = DBG_CRIT;
+uint32_t debug_mask = DBG_CRIT;
static BD_LOG_FUNC log_func = NULL;
void bd_set_debug_handler(BD_LOG_FUNC f)
diff --git a/src/util/logging.h b/src/util/logging.h
index 2c281be..6c68eff 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -27,8 +27,14 @@
#include <stdint.h>
-#define BD_DEBUG(MASK,...) bd_debug(__FILE__,__LINE__,MASK,__VA_ARGS__)
-
+BD_PRIVATE extern uint32_t debug_mask;
+
+#define BD_DEBUG(MASK,...) \
+ do { \
+ if (BD_UNLIKELY((MASK) & debug_mask)) { \
+ bd_debug(__FILE__,__LINE__,MASK,__VA_ARGS__); \
+ } \
+ } while (0)
BD_PRIVATE char *print_hex(char *out, const uint8_t *str, int count);
BD_PRIVATE void bd_debug(const char *file, int line, uint32_t mask, const char *format, ...) BD_ATTR_FORMAT_PRINTF(4,5);
More information about the libbluray-devel
mailing list