rcutils
master
C API providing common utilities and data structures.
include
rcutils
macros.h
Go to the documentation of this file.
1
// Copyright 2017 Open Source Robotics Foundation, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef RCUTILS__MACROS_H_
16
#define RCUTILS__MACROS_H_
17
18
#ifdef __cplusplus
19
extern
"C"
20
{
21
#endif
22
23
#ifndef _WIN32
24
#define RCUTILS_WARN_UNUSED __attribute__((warn_unused_result))
25
#else
26
#define RCUTILS_WARN_UNUSED _Check_return_
27
#endif
28
29
// Note: this block was migrated from rmw/macros.h
30
// This block either sets RCUTILS_THREAD_LOCAL or RCUTILS_THREAD_LOCAL_PTHREAD.
31
#if defined _WIN32 || defined __CYGWIN__
32
// Windows or Cygwin
33
#define RCUTILS_THREAD_LOCAL __declspec(thread)
34
#elif defined __APPLE__
35
// Apple OS's
36
#include <TargetConditionals.h>
37
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
38
// iOS Simulator or iOS device
39
#include <Availability.h>
40
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
41
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
42
// iOS >= 10, thread local storage was added in iOS 10
43
#define RCUTILS_THREAD_LOCAL _Thread_local
44
#else
45
// iOS < 10, no thread local storage, so use pthread instead
46
#define RCUTILS_THREAD_LOCAL_PTHREAD 1
47
#undef RCUTILS_THREAD_LOCAL
48
#endif
49
#else
50
#error "Unknown iOS version"
51
#endif
52
#elif TARGET_OS_MAC
53
// macOS
54
#define RCUTILS_THREAD_LOCAL _Thread_local
55
#else
56
#error "Unknown Apple platform"
57
#endif
58
#else
59
// Some other non-Windows, non-cygwin, non-apple OS
60
#define RCUTILS_THREAD_LOCAL _Thread_local
61
#endif
62
63
#define RCUTILS_STRINGIFY_IMPL(x) #x
64
#define RCUTILS_STRINGIFY(x) RCUTILS_STRINGIFY_IMPL(x)
65
#define RCUTILS_UNUSED(x) (void)(x)
66
67
#define RCUTILS_JOIN_IMPL(arg1, arg2) arg1 ## arg2
68
#define RCUTILS_JOIN(arg1, arg2) RCUTILS_JOIN_IMPL(arg1, arg2)
69
70
#if defined _WIN32 || defined __CYGWIN__
71
#define RCUTILS_ATTRIBUTE_PRINTF_FORMAT(format_string_index, first_to_check_index)
73
#else
74
94
#define RCUTILS_ATTRIBUTE_PRINTF_FORMAT(format_string_index, first_to_check_index) \
95
__attribute__ ((format(printf, format_string_index, first_to_check_index)))
96
#endif // !defined _WIN32 || defined __CYGWIN__
97
99
#ifndef _WIN32
100
# define RCUTILS_DEPRECATED __attribute__((deprecated))
101
#else
102
# define RCUTILS_DEPRECATED __declspec(deprecated)
103
#endif
104
106
#ifndef _WIN32
107
# define RCUTILS_DEPRECATED_WITH_MSG(msg) __attribute__((deprecated(msg)))
108
#else
109
# define RCUTILS_DEPRECATED_WITH_MSG(msg) __declspec(deprecated(msg))
110
#endif
111
112
// Provide the compiler with branch prediction information
113
#ifndef _WIN32
114
118
# define RCUTILS_LIKELY(x) __builtin_expect((x), 1)
119
123
# define RCUTILS_UNLIKELY(x) __builtin_expect((x), 0)
124
#else
125
129
# define RCUTILS_LIKELY(x) (x)
130
134
# define RCUTILS_UNLIKELY(x) (x)
135
#endif // _WIN32
136
137
#if defined RCUTILS_ENABLE_FAULT_INJECTION
138
#include "
rcutils/testing/fault_injection.h
"
139
181
# define RCUTILS_CAN_RETURN_WITH_ERROR_OF(error_return_value) \
182
RCUTILS_FAULT_INJECTION_MAYBE_RETURN_ERROR(error_return_value);
183
198
# define RCUTILS_CAN_FAIL_WITH(failure_code) \
199
RCUTILS_FAULT_INJECTION_MAYBE_FAIL(failure_code);
200
201
#else
202
# define RCUTILS_CAN_RETURN_WITH_ERROR_OF(error_return_value)
203
# define RCUTILS_CAN_FAIL_WITH(failure_code)
204
#endif // defined RCUTILS_ENABLE_FAULT_INJECTION
205
206
#ifdef __cplusplus
207
}
208
#endif
209
210
#endif // RCUTILS__MACROS_H_
fault_injection.h
Generated by
1.8.17