Commit | Line | Data |
---|---|---|
4477a870 MD |
1 | #ifndef _URCU_UTILS_H |
2 | #define _URCU_UTILS_H | |
3 | ||
4 | /* | |
5 | * urcu-utils.h | |
6 | * | |
7 | * Userspace RCU library internal utils | |
8 | * | |
9 | * Copyright (c) 2018 Michael Jeanson <mjeanson@efficios.com> | |
10 | * | |
11 | * This library is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License as published by the Free Software Foundation; either | |
14 | * version 2.1 of the License, or (at your option) any later version. | |
15 | * | |
16 | * This library is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * Lesser General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU Lesser General Public | |
22 | * License along with this library; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
24 | */ | |
25 | ||
c6bc6503 MJ |
26 | #include <urcu/config.h> |
27 | ||
4477a870 MD |
28 | #define urcu_stringify(a) _urcu_stringify(a) |
29 | #define _urcu_stringify(a) #a | |
30 | ||
83e334d0 MJ |
31 | #define max_t(type, x, y) \ |
32 | ({ \ | |
33 | type __max1 = (x); \ | |
34 | type __max2 = (y); \ | |
35 | __max1 > __max2 ? __max1: __max2; \ | |
36 | }) | |
37 | ||
38 | #define min_t(type, x, y) \ | |
39 | ({ \ | |
40 | type __min1 = (x); \ | |
41 | type __min2 = (y); \ | |
42 | __min1 <= __min2 ? __min1: __min2; \ | |
43 | }) | |
44 | ||
ce28e67a MJ |
45 | /* There is no concept of symbol aliases on MacOS */ |
46 | #ifdef __APPLE__ | |
47 | #define URCU_ATTR_ALIAS(x) | |
48 | #else | |
49 | #define URCU_ATTR_ALIAS(x) __attribute__((alias(x))) | |
50 | #endif | |
51 | ||
99bfa9e9 MJ |
52 | #ifdef CONFIG_RCU_TLS |
53 | #define DEFINE_URCU_TLS_ALIAS_1(type, name, alias) \ | |
54 | URCU_ATTR_ALIAS(#name) \ | |
55 | extern type alias | |
56 | ||
57 | #else | |
58 | #define DEFINE_URCU_TLS_ALIAS_1(type, name, alias) \ | |
59 | URCU_ATTR_ALIAS("*__tls_access_" #name) \ | |
60 | type *__tls_access_ ## alias() | |
61 | #endif | |
62 | ||
63 | #define DEFINE_URCU_TLS_ALIAS(type, name, alias) \ | |
64 | DEFINE_URCU_TLS_ALIAS_1(type, name, alias) | |
65 | ||
4477a870 | 66 | #endif /* _URCU_UTILS_H */ |