mirror of
https://github.com/boostorg/regex.git
synced 2025-07-17 14:22:08 +02:00
Lockfree mem_block_cache only active if std::atomic is available
This commit is contained in:
@ -19,18 +19,12 @@
|
|||||||
#define BOOST_REGEX_V4_MEM_BLOCK_CACHE_HPP
|
#define BOOST_REGEX_V4_MEM_BLOCK_CACHE_HPP
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <boost/atomic/atomic.hpp>
|
|
||||||
|
|
||||||
#ifdef BOOST_HAS_ABI_HEADERS
|
#ifdef BOOST_HAS_ABI_HEADERS
|
||||||
# include BOOST_ABI_PREFIX
|
# include BOOST_ABI_PREFIX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_NO_CXX11_HDR_ATOMIC
|
#ifndef 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
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#if ATOMIC_POINTER_LOCK_FREE == 2
|
#if ATOMIC_POINTER_LOCK_FREE == 2
|
||||||
#define BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE
|
#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 */
|
#ifdef BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE /* lock free implementation */
|
||||||
struct mem_block_cache
|
struct mem_block_cache
|
||||||
{
|
{
|
||||||
BOOST_REGEX_ATOMIC_POINTER<void*> cache[BOOST_REGEX_MAX_CACHE_BLOCKS];
|
std::atomic<void*> 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()
|
~mem_block_cache()
|
||||||
{
|
{
|
||||||
for (size_t i = 0;i < BOOST_REGEX_MAX_CACHE_BLOCKS; ++i) {
|
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 */
|
#else /* lock-based implementation */
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p)
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#if defined(BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE)
|
#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)
|
#elif defined(BOOST_HAS_THREADS)
|
||||||
mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, };
|
mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, };
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user