From a0dfd815169138ff5e63b8bcf06ed1d47edcd8f4 Mon Sep 17 00:00:00 2001 From: Yucheng Low Date: Thu, 31 Dec 2015 15:46:20 -0800 Subject: [PATCH] Lockfree mem_block_cache only active if std::atomic is available --- include/boost/regex/v4/mem_block_cache.hpp | 17 ++--------------- src/regex.cpp | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/include/boost/regex/v4/mem_block_cache.hpp b/include/boost/regex/v4/mem_block_cache.hpp index 6703ccf1..3457e9a5 100644 --- a/include/boost/regex/v4/mem_block_cache.hpp +++ b/include/boost/regex/v4/mem_block_cache.hpp @@ -19,18 +19,12 @@ #define BOOST_REGEX_V4_MEM_BLOCK_CACHE_HPP #include -#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX #endif -#ifdef BOOST_NO_CXX11_HDR_ATOMIC - #if BOOST_ATOMIC_POINTER_LOCK_FREE == 2 - #define BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE - #define BOOST_REGEX_ATOMIC_POINTER boost::atomic - #endif -#else // BOOST_NOCXX11_HDR_ATOMIC not defined +#ifndef BOOST_NO_CXX11_HDR_ATOMIC #include #if ATOMIC_POINTER_LOCK_FREE == 2 #define BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE @@ -44,14 +38,8 @@ namespace BOOST_REGEX_DETAIL_NS{ #ifdef BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE /* lock free implementation */ struct mem_block_cache { - BOOST_REGEX_ATOMIC_POINTER cache[BOOST_REGEX_MAX_CACHE_BLOCKS]; + std::atomic cache[BOOST_REGEX_MAX_CACHE_BLOCKS]; - mem_block_cache() { - for (size_t i = 0;i < BOOST_REGEX_MAX_CACHE_BLOCKS; ++i) { - cache[i].store(NULL); - } - - } ~mem_block_cache() { for (size_t i = 0;i < BOOST_REGEX_MAX_CACHE_BLOCKS; ++i) { @@ -80,7 +68,6 @@ struct mem_block_cache } }; -#undef BOOST_REGEX_ATOMIC_POINTER #else /* lock-based implementation */ diff --git a/src/regex.cpp b/src/regex.cpp index 560d3be2..e9e97627 100644 --- a/src/regex.cpp +++ b/src/regex.cpp @@ -192,7 +192,7 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p) #else #if defined(BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE) -mem_block_cache block_cache; +mem_block_cache block_cache = { { {nullptr} } } ; #elif defined(BOOST_HAS_THREADS) mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, }; #else