IsoSpec  2.1.3
platform.h
1 /*
2  * Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
3  *
4  * This file is part of IsoSpec.
5  *
6  * IsoSpec is free software: you can redistribute it and/or modify
7  * it under the terms of the Simplified ("2-clause") BSD licence.
8  *
9  * IsoSpec is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * You should have received a copy of the Simplified BSD Licence
14  * along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
15  */
16 
17 #pragma once
18 
19 #include "platform_incl.h"
20 
21 #if defined(__unix__) || defined(__unix) || \
22  (defined(__APPLE__) && defined(__MACH__))
23 #define ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY true
24 #define ISOSPEC_TEST_WE_ARE_ON_WINDOWS false /* CYGWIN doesn't really count as Windows for our purposes, we'll be using UNIX API anyway */
25 #define ISOSPEC_TEST_GOT_SYSTEM_MMAN true
26 #define ISOSPEC_TEST_GOT_MMAN true
27 #elif defined(__MINGW32__) || defined(_WIN32)
28 #define ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY false
29 #define ISOSPEC_TEST_WE_ARE_ON_WINDOWS true
30 #define ISOSPEC_TEST_GOT_SYSTEM_MMAN false
31 #define ISOSPEC_TEST_GOT_MMAN true
32 #else
33 #define ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY false /* Well, probably... */
34 #define ISOSPEC_TEST_WE_ARE_ON_WINDOWS false
35 #define ISOSPEC_TEST_GOT_SYSTEM_MMAN false
36 #define ISOSPEC_TEST_GOT_MMAN false
37 #endif
38 
39 #if !defined(ISOSPEC_WE_ARE_ON_UNIX_YAY)
40 #define ISOSPEC_WE_ARE_ON_UNIX_YAY ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY
41 #endif
42 
43 #if !defined(ISOSPEC_WE_ARE_ON_WINDOWS)
44 #define ISOSPEC_WE_ARE_ON_WINDOWS ISOSPEC_TEST_WE_ARE_ON_WINDOWS
45 #endif
46 
47 #if !defined(ISOSPEC_GOT_SYSTEM_MMAN)
48 #define ISOSPEC_GOT_SYSTEM_MMAN ISOSPEC_TEST_GOT_SYSTEM_MMAN
49 #endif
50 
51 #if !defined(ISOSPEC_GOT_MMAN)
52 #define ISOSPEC_GOT_MMAN ISOSPEC_TEST_GOT_MMAN
53 #endif
54 
55 
56 // Note: __GNUC__ is defined by clang and gcc
57 #ifdef __GNUC__
58 #define ISOSPEC_IMPOSSIBLE(condition) if(condition) __builtin_unreachable();
59 #define ISOSPEC_LIKELY(condition) __builtin_expect(static_cast<bool>(condition), 1)
60 #define ISOSPEC_UNLIKELY(condition) __builtin_expect(static_cast<bool>(condition), 0)
61 // For aggressive inlining
62 #define ISOSPEC_FORCE_INLINE __attribute__ ((always_inline)) inline
63 #elif defined _MSC_VER
64 #define ISOSPEC_IMPOSSIBLE(condition) __assume(!(condition));
65 #define ISOSPEC_LIKELY(condition) condition
66 #define ISOSPEC_UNLIKELY(condition) condition
67 #define ISOSPEC_FORCE_INLINE __forceinline inline
68 #else
69 #define ISOSPEC_IMPOSSIBLE(condition)
70 #define ISOSPEC_LIKELY(condition) condition
71 #define ISOSPEC_UNLIKELY(condition) condition
72 #define ISOSPEC_FORCE_INLINE inline
73 #endif
74 
75 #ifdef ISOSPEC_DEBUG
76 #undef ISOSPEC_IMPOSSIBLE
77 #include <cassert>
78 #define ISOSPEC_IMPOSSIBLE(condition) assert(!(condition));
79 #endif /* ISOSPEC_DEBUG */
80 
81 
82 #if ISOSPEC_GOT_MMAN
83  #if ISOSPEC_GOT_SYSTEM_MMAN
84  #include <sys/mman.h>
85  #else
86  #include "mman.h"
87  #endif
88 #else
89  #include <stdlib.h> /* malloc, free, rand */
90 #endif
91 
92 
93 #if defined(OPENMS_DLLAPI) /* IsoSpec is being built as a part of OpenMS: use their visibility macros */
94 #define ISOSPEC_EXPORT_SYMBOL OPENMS_DLLAPI
95 #else /* it's a can of worms we don't yet want to open ourselves though... */
96 #define ISOSPEC_EXPORT_SYMBOL
97 #endif
98 
99 #if !defined(__cpp_if_constexpr)
100 #define constexpr_if if
101 #define ISOSPEC_MAYBE_UNUSED
102 #else
103 #define constexpr_if if constexpr
104 #define ISOSPEC_MAYBE_UNUSED [[maybe_unused]]
105 #endif