Commit 827b1113 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

likely, unlikely: convenience portability macros for branch prediction

Those are the same as the Linux kernel macros, and probably a bunch of
other projects. Usage:

    if (likely(condition))

    if (unlikely(condition))

Attention: those two macros convert the predicate to a boolean value.
Therefore you generally cannot use them for assignments like this:
    void *p_sys = likely (malloc (sizeof (*p_sys)));
    if (!p_sys)
        return VLC_ENOMEM;
Instead you can do this:
    void *p_sys = malloc (sizeof (*p_sys));
    if (unlikely (!p_sys))
        return VLC_ENOMEM;
parent 87e6f1be
......@@ -69,6 +69,15 @@
/* Branch prediction */
#ifdef __GNUC__
# define likely(p) __builtin_expect(!!(p), 1)
# define unlikely(p) __builtin_expect(!!(p), 0)
# define likely(p) (!!(p))
# define unlikely(p) (!!(p))
* Basic types definitions
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment