suricata
util-optimize.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #ifndef SURICATA_UTIL_OPTIMIZE_H
19 #define SURICATA_UTIL_OPTIMIZE_H
20 
21 /**
22  * \file
23  *
24  * \author Victor Julien <victor@inliniac.net>
25  */
26 
27 #if CPPCHECK==1
28 #define likely
29 #define unlikely
30 #else
31 #ifndef likely
32 #define likely(expr) __builtin_expect(!!(expr), 1)
33 #endif
34 #ifndef unlikely
35 #define unlikely(expr) __builtin_expect(!!(expr), 0)
36 #endif
37 #endif
38 
39 /** from http://en.wikipedia.org/wiki/Memory_ordering
40  *
41  * C Compiler memory barrier
42  */
43 #define cc_barrier() __asm__ __volatile__("": : :"memory")
44 
45 /** from http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html
46  *
47  * Hardware memory barrier
48  */
49 #define hw_barrier() __sync_synchronize()
50 
51 #endif /* SURICATA_UTIL_OPTIMIZE_H */