]> git.saurik.com Git - apple/libdispatch.git/blame - os/linux_base.h
libdispatch-703.50.37.tar.gz
[apple/libdispatch.git] / os / linux_base.h
CommitLineData
beb15981
A
1/*
2 * This source file is part of the Swift.org open source project
3 *
4 * Copyright (c) 2015 Apple Inc. and the Swift project authors
5 *
6 * Licensed under Apache License v2.0 with Runtime Library Exception
7 *
8 * See http://swift.org/LICENSE.txt for license information
9 * See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 *
11 */
12
13#ifndef __OS_LINUX_BASE__
14#define __OS_LINUX_BASE__
15
16#include <sys/user.h>
17#include <sys/param.h>
18
19#if __GNUC__
20#define OS_EXPECT(x, v) __builtin_expect((x), (v))
21#else
22#define OS_EXPECT(x, v) (x)
23#endif
24
25#ifndef os_likely
26#define os_likely(x) OS_EXPECT(!!(x), 1)
27#endif
28#ifndef os_unlikely
29#define os_unlikely(x) OS_EXPECT(!!(x), 0)
30#endif
31
32#if __has_feature(assume_nonnull)
33#define OS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
34#define OS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
35#else
36#define OS_ASSUME_NONNULL_BEGIN
37#define OS_ASSUME_NONNULL_END
38#endif
39
40#if __has_builtin(__builtin_assume)
41#define OS_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr)
42#else
43#define OS_COMPILER_CAN_ASSUME(expr) ((void)(expr))
44#endif
45
46#if __has_feature(attribute_availability_swift)
47// equivalent to __SWIFT_UNAVAILABLE from Availability.h
48#define OS_SWIFT_UNAVAILABLE(_msg) \
49 __attribute__((__availability__(swift, unavailable, message=_msg)))
50#else
51#define OS_SWIFT_UNAVAILABLE(_msg)
52#endif
53
54#if __has_attribute(swift_private)
55# define OS_REFINED_FOR_SWIFT __attribute__((__swift_private__))
56#else
57# define OS_REFINED_FOR_SWIFT
58#endif
59
60#if __has_attribute(swift_name)
61# define OS_SWIFT_NAME(_name) __attribute__((__swift_name__(#_name)))
62#else
63# define OS_SWIFT_NAME(_name)
64#endif
65
66#define __OS_STRINGIFY(s) #s
67#define OS_STRINGIFY(s) __OS_STRINGIFY(s)
68#define __OS_CONCAT(x, y) x ## y
69#define OS_CONCAT(x, y) __OS_CONCAT(x, y)
70
71/*
72 * Stub out misc linking and compilation attributes
73 */
74
75#ifdef OS_EXPORT
76#undef OS_EXPORT
77#endif
78#define OS_EXPORT
79
80#ifdef OS_WARN_RESULT_NEEDS_RELEASE
81#undef OS_WARN_RESULT_NEEDS_RELEASE
82#endif
83
84#ifdef OS_WARN_RESULT
85#undef OS_WARN_RESULT
86#endif
87#define OS_WARN_RESULT
88
89#ifdef OS_NOTHROW
90#undef OS_NOTHROW
91#endif
92#define OS_NOTHROW
93
94#endif /* __OS_LINUX_BASE__ */