Copyright 2012 -> 2013
[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_SCHED_H
23  #include <sched.h>
24  #ifndef FOLLY_HAVE_PTHREAD_YIELD
25   #define pthread_yield sched_yield
26  #endif
27 #endif
28
29 // Define macro wrappers for C++11's "final" and "override" keywords, which
30 // are supported in gcc 4.7 but not gcc 4.6.
31 //
32 // TODO(tudorb/agallagher): Autotoolize this.
33 #undef FOLLY_FINAL
34 #undef FOLLY_OVERRIDE
35
36 #if defined(__clang__)
37 #  define FOLLY_FINAL final
38 #  define FOLLY_OVERRIDE override
39 #elif defined(__GNUC__)
40 # include <features.h>
41 # if __GNUC_PREREQ(4,7)
42 #  define FOLLY_FINAL final
43 #  define FOLLY_OVERRIDE override
44 # endif
45 #endif
46
47 #ifndef FOLLY_FINAL
48 # define FOLLY_FINAL
49 #endif
50
51 #ifndef FOLLY_OVERRIDE
52 # define FOLLY_OVERRIDE
53 #endif
54
55
56 // MaxAlign: max_align_t isn't supported by gcc
57 #ifdef __GNUC__
58 struct MaxAlign { char c; } __attribute__((aligned));
59 #else /* !__GNUC__ */
60 # error Cannot define MaxAlign on this platform
61 #endif
62
63 #endif // FOLLY_PORTABILITY_H_