From 13b02baa4f012e8be8527857a76ff4275b1e9161 Mon Sep 17 00:00:00 2001 From: mrbald Date: Wed, 18 Dec 2024 10:13:41 +0100 Subject: [PATCH] peer review feedback --- rtb/datacache/entity_cache.hpp | 6 ++++-- rtb/datacache/memory_types.hpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rtb/datacache/entity_cache.hpp b/rtb/datacache/entity_cache.hpp index 3eec15d..cb66a6d 100644 --- a/rtb/datacache/entity_cache.hpp +++ b/rtb/datacache/entity_cache.hpp @@ -119,6 +119,7 @@ struct retriever>> { inline constexpr size_t ENTITY_CACHE_DEFAULT_MEMORY_SIZE = 67108864 /* 64 MB*/; inline constexpr size_t ENTITY_CACHE_DEFAULT_MEMORY_GROW_INCREMENT = 67108864 /* 64 MB*/; +inline constexpr uint64_t ENTITY_CACHE_DEFAULT_LOCK_TIMEOUT_S = 10; template class Container, typename ...T> class entity_cache { @@ -134,7 +135,8 @@ class entity_cache /** Can set memory_grow_increment=0 to prevent cache from growing */ explicit entity_cache(std::string name, size_t const memory_size = ENTITY_CACHE_DEFAULT_MEMORY_SIZE, - size_t const memory_grow_increment = ENTITY_CACHE_DEFAULT_MEMORY_GROW_INCREMENT) + size_t const memory_grow_increment = ENTITY_CACHE_DEFAULT_MEMORY_GROW_INCREMENT, + uint32_t lock_timeout_s = ENTITY_CACHE_DEFAULT_LOCK_TIMEOUT_S) : _segment_ptr(), _container_ptr(), _store_name(), _cache_name(std::move(name)), _named_mutex(bip::open_or_create, (_cache_name + "_mutex").c_str()), _memory_grow_increment{memory_grow_increment} { @@ -143,7 +145,7 @@ class entity_cache std::string data_base_dir = "/tmp/CACHE"; auto guard = bip::scoped_lock{_named_mutex, bip::defer_lock}; - VAV_REQUIRE(guard.try_lock_for(boost::chrono::seconds(10))); + VAV_REQUIRE(guard.try_lock_for(boost::chrono::seconds(lock_timeout_s))); _store_name = Memory::convert_base_dir(data_base_dir) + _cache_name; _segment_ptr.reset(Memory::open_or_create_segment(_store_name.c_str(), memory_size)); diff --git a/rtb/datacache/memory_types.hpp b/rtb/datacache/memory_types.hpp index 1dc133f..af18d46 100644 --- a/rtb/datacache/memory_types.hpp +++ b/rtb/datacache/memory_types.hpp @@ -33,7 +33,7 @@ namespace mpclmi::ipc { * - simpler memory allocation algorithm suitable for segments storing a single node-based cotainer * - memory allocation is not thread safe, relying on external synchronization typical for entity_cache-based containers */ -struct SharedVL { +struct SharedSeqFitNoLock { using char_type = char; using mutex_family_type = boost::interprocess::null_mutex_family; using memory_algorithm_type = boost::interprocess::simple_seq_fit;