Unbreak build on glibc 2.5.1
[folly.git] / folly / Portability.h
1 /*
2  * Copyright 2013 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef FOLLY_PORTABILITY_H_
18 #define FOLLY_PORTABILITY_H_
19
20 #include "folly-config.h"
21
22 #ifdef FOLLY_HAVE_FEATURES_H
23 #include <features.h>
24 #endif
25
26
27 #ifdef FOLLY_HAVE_SCHED_H
28  #include <sched.h>
29  #ifndef FOLLY_HAVE_PTHREAD_YIELD
30   #define pthread_yield sched_yield
31  #endif
32 #endif
33
34
35 // MaxAlign: max_align_t isn't supported by gcc
36 #ifdef __GNUC__
37 struct MaxAlign { char c; } __attribute__((aligned));
38 #else /* !__GNUC__ */
39 # error Cannot define MaxAlign on this platform
40 #endif
41
42
43 // noreturn
44 #if defined(__clang__) || defined(__GNUC__)
45 # define FOLLY_NORETURN __attribute__((noreturn))
46 #else
47 # define FOLLY_NORETURN
48 #endif
49
50
51 /* Define macro wrappers for C++11's "final" and "override" keywords, which
52  * are supported in gcc 4.7 but not gcc 4.6. */
53 #if !defined(FOLLY_FINAL) && !defined(FOLLY_OVERRIDE)
54 # if defined(__clang__) || \
55      (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
56       ((__GNUC__ << 16) + __GNUC_MINOR__) >= ((4 << 16) + 7))
57 #  define FOLLY_FINAL final
58 #  define FOLLY_OVERRIDE override
59 # else
60 #  define FOLLY_FINAL /**/
61 #  define FOLLY_OVERRIDE /**/
62 # endif
63 #endif
64
65
66 // Define to 1 if you have the `preadv' and `pwritev' functions, respectively
67 #if !defined(FOLLY_HAVE_PREADV) && !defined(FOLLY_HAVE_PWRITEV)
68 # if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
69 #  define FOLLY_HAVE_PREADV 1
70 #  define FOLLY_HAVE_PWRITEV 1
71 # endif
72 #endif
73
74 #endif // FOLLY_PORTABILITY_H_