debug.h 913 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "log.h"
  2. #if defined(__GNUC__) && (__GNUC__ >= 3)
  3. #define likely(_x) __builtin_expect(!!(_x), 1)
  4. #define unlikely(_x) __builtin_expect(!!(_x), 0)
  5. #else
  6. #define likely(_x) !!(_x)
  7. #define unlikely(_x) !!(_x)
  8. #endif
  9. #define NHRP_DEBUG_COMMON (1 << 0)
  10. #define NHRP_DEBUG_KERNEL (1 << 1)
  11. #define NHRP_DEBUG_IF (1 << 2)
  12. #define NHRP_DEBUG_ROUTE (1 << 3)
  13. #define NHRP_DEBUG_VICI (1 << 4)
  14. #define NHRP_DEBUG_EVENT (1 << 5)
  15. #define NHRP_DEBUG_ALL (0xFFFF)
  16. extern unsigned int debug_flags;
  17. #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  18. #define debugf(level, ...) \
  19. do { \
  20. if (unlikely(debug_flags & level)) \
  21. zlog_debug(__VA_ARGS__); \
  22. } while(0)
  23. #elif defined __GNUC__
  24. #define debugf(level, _args...) \
  25. do { \
  26. if (unlikely(debug_flags & level)) \
  27. zlog_debug(_args); \
  28. } while(0)
  29. #else
  30. static inline void debugf(int level, const char *format, ...) { }
  31. #endif