diff --git a/src/asmjit/core/cpuinfo.cpp b/src/asmjit/core/cpuinfo.cpp index d66070c..c6d3545 100644 --- a/src/asmjit/core/cpuinfo.cpp +++ b/src/asmjit/core/cpuinfo.cpp @@ -7,6 +7,8 @@ #include "../core/cpuinfo.h" #include "../core/support.h" +#include + // Required by `__cpuidex()` and `_xgetbv()`. #if ASMJIT_ARCH_X86 #if defined(_MSC_VER) @@ -1969,13 +1971,13 @@ static ASMJIT_FAVOR_SIZE void detectARMCpu(CpuInfo& cpu) noexcept { // CpuInfo - Detect - Host // ======================= -static uint32_t cpuInfoInitialized; -static CpuInfo cpuInfoGlobal(Globals::NoInit); - const CpuInfo& CpuInfo::host() noexcept { - // This should never cause a problem as the resulting information should always be the same. - // In the worst case it would just be overwritten non-atomically. - if (!cpuInfoInitialized) { + static std::atomic cpuInfoInitialized; + static CpuInfo cpuInfoGlobal(Globals::NoInit); + + // This should never cause a problem as the resulting information should always + // be the same. In the worst case it would just be overwritten non-atomically. + if (!cpuInfoInitialized.load(std::memory_order_relaxed)) { CpuInfo cpuInfoLocal; cpuInfoLocal._arch = Arch::kHost; @@ -1989,7 +1991,7 @@ const CpuInfo& CpuInfo::host() noexcept { cpuInfoLocal._hwThreadCount = detectHWThreadCount(); cpuInfoGlobal = cpuInfoLocal; - cpuInfoInitialized = 1; + cpuInfoInitialized.store(1, std::memory_order_seq_cst); } return cpuInfoGlobal; diff --git a/src/asmjit/core/cpuinfo.h b/src/asmjit/core/cpuinfo.h index 9e0c41f..2638146 100644 --- a/src/asmjit/core/cpuinfo.h +++ b/src/asmjit/core/cpuinfo.h @@ -22,11 +22,6 @@ ASMJIT_BEGIN_NAMESPACE //! Each feature is represented by a single bit in an embedded bit array. class CpuFeatures { public: - //! A word that is used to represents feature bits. - typedef Support::BitWord BitWord; - //! Iterator that can iterate all CPU features set. - typedef Support::BitVectorIterator Iterator; - //! \name Constants //! \{ @@ -37,6 +32,13 @@ public: }; //! \endcond + //! A word that is used to represents feature bits. + typedef Support::BitWord BitWord; + //! Iterator that can iterate all CPU features set. + typedef Support::BitVectorIterator Iterator; + + typedef Support::Array Bits; + //! \} //! \name Data @@ -48,7 +50,7 @@ public: //! \{ //! Data bits. - Support::Array _bits; + Bits _bits; //! \} @@ -178,8 +180,7 @@ public: #endif // !ASMJIT_NO_DEPRECATED //! \} - - }; + }; //! X86 specific features data. struct X86 : public Data { @@ -948,6 +949,7 @@ public: ASMJIT_INLINE_NODEBUG CpuFeatures() noexcept {} ASMJIT_INLINE_NODEBUG CpuFeatures(const CpuFeatures& other) noexcept = default; + ASMJIT_INLINE_NODEBUG explicit CpuFeatures(const Data& other) noexcept : _data{other._bits} {} ASMJIT_INLINE_NODEBUG explicit CpuFeatures(Globals::NoInit_) noexcept {} //! \}