[NFC] Replace HEADER_GLOBAL with inline (C++17).
HEADER_GLOBAL was using non-standard attributes to achieve what C++17 now permits with a keyword. Use the standard formulation. Update the README to note that gcc is still not recommended, but because of its poor codegen for 128-bit atomic compare and exchange, rather than because it doesn't support the attribute used for HEADER_GLOBAL.
This commit is contained in:
committed by
David Chisnall
parent
bbf016bac8
commit
6dbe24da2e
@@ -50,9 +50,8 @@ To use snmalloc on NetBSD, you must either acquire a `libatomic` implementation
|
||||
|
||||
snmalloc has very few dependencies, CMake, Ninja, Clang 6.0 or later and a C++17
|
||||
standard library.
|
||||
Building with GCC is currently not recommended because GCC lacks support for the
|
||||
`selectany` attribute to specify variables in a COMDAT.
|
||||
It will build with GCC-7, but some of global variables will be preemptible.
|
||||
Building with GCC is currently not recommended because GCC emits calls to
|
||||
libatomic for 128-bit atomic operations.
|
||||
|
||||
To build a debug configuration:
|
||||
```
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#ifdef _MSC_VER
|
||||
# define ALWAYSINLINE __forceinline
|
||||
# define NOINLINE __declspec(noinline)
|
||||
# define HEADER_GLOBAL __declspec(selectany)
|
||||
# define likely(x) !!(x)
|
||||
# define unlikely(x) !!(x)
|
||||
# define SNMALLOC_SLOW_PATH NOINLINE
|
||||
@@ -17,13 +16,6 @@
|
||||
# define SNMALLOC_SLOW_PATH NOINLINE
|
||||
# define SNMALLOC_FAST_PATH inline ALWAYSINLINE
|
||||
# define SNMALLOC_PURE __attribute__((const))
|
||||
# ifdef __clang__
|
||||
# define HEADER_GLOBAL __attribute__((selectany))
|
||||
# else
|
||||
// GCC does not support selectany, weak is almost the correct
|
||||
// attribute, but leaves the global variable preemptible.
|
||||
# define HEADER_GLOBAL __attribute__((weak))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __has_builtin
|
||||
|
||||
@@ -405,5 +405,5 @@ namespace snmalloc
|
||||
* The memory provider that will be used if no other provider is explicitly
|
||||
* passed as an argument.
|
||||
*/
|
||||
HEADER_GLOBAL GlobalVirtual default_memory_provider;
|
||||
inline GlobalVirtual default_memory_provider;
|
||||
} // namespace snmalloc
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace snmalloc
|
||||
* replace itself with the thread-local allocator, allocating one if
|
||||
* required. This avoids a branch on the fast path.
|
||||
*/
|
||||
HEADER_GLOBAL Alloc GlobalPlaceHolder(
|
||||
inline Alloc GlobalPlaceHolder(
|
||||
default_memory_provider, SNMALLOC_DEFAULT_PAGEMAP(), nullptr, true);
|
||||
|
||||
#ifdef SNMALLOC_EXTERNAL_THREAD_ALLOC
|
||||
|
||||
@@ -231,8 +231,8 @@ namespace snmalloc
|
||||
}
|
||||
# endif
|
||||
};
|
||||
HEADER_GLOBAL std::atomic<uint64_t> PALWindows::pressure_epoch;
|
||||
HEADER_GLOBAL std::atomic<bool> PALWindows::registered_for_notifications;
|
||||
HEADER_GLOBAL HANDLE PALWindows::lowMemoryObject;
|
||||
inline std::atomic<uint64_t> PALWindows::pressure_epoch;
|
||||
inline std::atomic<bool> PALWindows::registered_for_notifications;
|
||||
inline HANDLE PALWindows::lowMemoryObject;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user