Skip to content

Commit

Permalink
peer review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbald committed Dec 18, 2024
1 parent e1d503d commit d099e08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions rtb/datacache/entity_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ struct retriever<Tag,std::vector<std::shared_ptr<Serializable>>> {

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<typename Memory, template <class,class...> class Container, typename ...T>
class entity_cache
{
Expand All @@ -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} {
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions rtb/datacache/memory_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
namespace mpclmi::ipc {

/** A variation of the Shared:
* - simpler memory allocation algorithm suitable for segments storing a single node-based cotainer
* - simpler memory allocation algorithm suitable for segments storing a single node-based container
* - 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<mutex_family_type>;
Expand Down

0 comments on commit d099e08

Please sign in to comment.