Extend align.h
[lttng-ust.git] / include / lttng / core.h
1 #ifndef UST_CORE_H
2 #define UST_CORE_H
3
4 /*
5 * Copyright (C) 2010 Pierre-Marc Fournier
6 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; version 2.1 of
11 * the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <sys/types.h>
24 #include <lttng/config.h>
25 #include <urcu/arch.h>
26 #include <urcu/compiler.h>
27
28 /* Min / Max */
29
30 #define min_t(type, x, y) ({ \
31 type __min1 = (x); \
32 type __min2 = (y); \
33 __min1 < __min2 ? __min1: __min2; })
34
35 #define max_t(type, x, y) ({ \
36 type __max1 = (x); \
37 type __max2 = (y); \
38 __max1 > __max2 ? __max1: __max2; })
39
40
41 /* MALLOCATION */
42
43 #include <stdlib.h>
44
45 static inline
46 void *zmalloc(size_t len)
47 {
48 return calloc(1, len);
49 }
50
51 /* MATH */
52
53 static inline unsigned int hweight32(unsigned int w)
54 {
55 unsigned int res = w - ((w >> 1) & 0x55555555);
56 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
57 res = (res + (res >> 4)) & 0x0F0F0F0F;
58 res = res + (res >> 8);
59 return (res + (res >> 16)) & 0x000000FF;
60 }
61
62 #endif /* UST_CORE_H */
This page took 0.029878 seconds and 4 git commands to generate.