Addressing OE linking issues when built with GCC (#167)

* Use C++17 inline statics

This leads to better codegen in GCC, and fixes some linking issues in OE.

* Detect GCC and OE combination and fall-back to lock based ABA.

* clangformat
This commit is contained in:
Matthew Parkinson
2020-04-10 13:49:39 +01:00
committed by GitHub
parent c09b2468f9
commit cf9c2eb9d9
3 changed files with 17 additions and 7 deletions

View File

@@ -13,18 +13,18 @@ namespace snmalloc
template<class Object, Object init() noexcept>
class Singleton
{
inline static std::atomic_flag flag;
inline static std::atomic<bool> initialised = false;
inline static Object obj;
public:
/**
* If argument is non-null, then it is assigned the value
* true, if this is the first call to get.
* At most one call will be first.
*/
inline static Object& get(bool* first = nullptr)
inline SNMALLOC_SLOW_PATH static Object& get(bool* first = nullptr)
{
static std::atomic_flag flag;
static std::atomic<bool> initialised;
static Object obj;
// If defined should be initially false;
SNMALLOC_ASSERT(first == nullptr || *first == false);