common: added a macro to run code depending on debug settings.
authorKrisztian Litkey <krisztian.litkey@intel.com>
Fri, 2 May 2014 14:32:34 +0000 (17:32 +0300)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Fri, 2 May 2014 14:39:25 +0000 (17:39 +0300)
src/common/debug.h

index 1beecc6..7db9bd7 100644 (file)
@@ -78,6 +78,25 @@ MRP_CDECL_BEGIN
     } while (0)
 
 
+#define mrp_debug_code(...)         do {                                  \
+        static const char *__site =                                       \
+            MRP_DEBUG_SITE(__FILE__, __LINE__, __FUNCTION__);             \
+        static int __site_stamp = -1;                                     \
+        static int __site_enabled;                                        \
+                                                                          \
+        if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) {              \
+            __site_enabled = mrp_debug_check(__FUNCTION__,                \
+                                             __FILE__, __LINE__);         \
+            __site_stamp   = mrp_debug_stamp;                             \
+        }                                                                 \
+                                                                          \
+        MRP_UNUSED(__site);                                               \
+                                                                          \
+        if (MRP_UNLIKELY(__site_enabled)) {                               \
+            __VA_ARGS__;                                                  \
+        }                                                                 \
+    } while (0)
+
 /** Global debug configuration stamp, exported for minimum-overhead checking. */
 extern int mrp_debug_stamp;