]> git.sesse.net Git - vlc/commit
likely, unlikely: convenience portability macros for branch prediction
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 6 Dec 2009 08:16:59 +0000 (10:16 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 6 Dec 2009 08:48:43 +0000 (10:48 +0200)
commit827b111356e910800788245bb1a2a22017fea857
treedc32b538e44c925da9f4f5ba61b537815fc871fa
parent87e6f1be1272e4a1e74fb23f5a97e71ad4c67006
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))
        branch_likely_taken();

    if (unlikely(condition))
        branch_unlikely_taken();

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;
include/vlc_common.h