esp_common: Don't redefine likely/unlikely if already defined

As these macros aren't namespaced, they may have been defined by another header.

Also reported in https://github.com/espressif/esp-idf/issues/6445
This commit is contained in:
Angus Gratton
2021-02-12 15:23:36 +11:00
parent 7778779489
commit e3b7337f03

View File

@@ -23,12 +23,20 @@
* code.
*/
#if (CONFIG_COMPILER_OPTIMIZATION_PERF)
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#else
#ifndef likely
#define likely(x) (x)
#endif
#ifndef unlikely
#define unlikely(x) (x)
#endif
#endif
/*
* Utility macros used for designated initializers, which work differently