libaacs | branch: master | npzacs <npz...@gmail.com> | Mon Oct  7 13:18:53 2013 
+0300| [e274ebb0924d1f0367833be99f2bbbac0b454465] | committer: npzacs

Simple logging optimization

> http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=e274ebb0924d1f0367833be99f2bbbac0b454465
---

 src/util/attributes.h |   14 +++++++++++---
 src/util/logging.c    |    2 +-
 src/util/logging.h    |    9 ++++++++-
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/util/attributes.h b/src/util/attributes.h
index f37c870..6fa2247 100644
--- a/src/util/attributes.h
+++ b/src/util/attributes.h
@@ -17,8 +17,8 @@
  * <http://www.gnu.org/licenses/>.
  */
 
-#ifndef LIBBLURAY_ATTRIBUTES_H_
-#define LIBBLURAY_ATTRIBUTES_H_
+#ifndef LIBAACS_ATTRIBUTES_H_
+#define LIBAACS_ATTRIBUTES_H_
 
 #if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 
3 ))
 #    define AACS_ATTR_FORMAT_PRINTF(format,var) \
@@ -47,4 +47,12 @@
 #    define AACS_PRIVATE
 #endif
 
-#endif /* LIBBLURAY_ATTRIBUTES_H_ */
+#if !defined(__GNUC__) || __GNUC__ < 3
+#  define AACS_LIKELY(x)   (x)
+#  define AACS_UNLIKELY(x) (x)
+#else
+#  define AACS_LIKELY(x)   __builtin_expect((x),1)
+#  define AACS_UNLIKELY(x) __builtin_expect((x),0)
+#endif
+
+#endif /* LIBAACS_ATTRIBUTES_H_ */
diff --git a/src/util/logging.c b/src/util/logging.c
index 702d75f..b20475e 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -24,7 +24,7 @@
 #include <stdarg.h>
 #include <string.h>
 
-static debug_mask_t debug_mask = DBG_CRIT;
+uint32_t debug_mask = (uint32_t)-1; /* set all bits to make sure aacs_debug() 
is called for initialization */
 
 char *print_hex(char *out, const uint8_t *buf, int count)
 {
diff --git a/src/util/logging.h b/src/util/logging.h
index 68eb93a..53e1dd1 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -24,7 +24,14 @@
 
 #include <stdint.h>
 
-#define DEBUG(MASK,...) aacs_debug(__FILE__,__LINE__,MASK,##__VA_ARGS__)
+AACS_PRIVATE extern uint32_t debug_mask;
+
+#define DEBUG(MASK,...)                                 \
+  do {                                                  \
+    if (AACS_UNLIKELY((MASK) & debug_mask)) {           \
+      aacs_debug(__FILE__,__LINE__,MASK,__VA_ARGS__);   \
+    }                                                   \
+  } while (0)
 
 enum debug_mask_enum {
     DBG_RESERVED   = 0x0001,

_______________________________________________
libaacs-devel mailing list
libaacs-devel@videolan.org
https://mailman.videolan.org/listinfo/libaacs-devel

Reply via email to