Skip to content

Commit

Permalink
Fix C++ tests compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexowens90 committed Oct 31, 2024
1 parent a1feaa2 commit 7cf53f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
21 changes: 15 additions & 6 deletions cpp/arcticdb/processing/component_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ std::vector<EntityId> ComponentManager::get_new_entity_ids(size_t count) {
return ids;
}

void ComponentManager::erase_entity(EntityId id) {
// Ideally would call registry_.destroy(id), or at least registry_.erase<std::shared_ptr<SegmentInMemory>>(id)
// at this point. However, they are both slower than this, so just decrement the ref count of the only
// sizeable component, so that when the shared pointer goes out of scope in the calling function, the
// memory is freed
registry_.get<std::shared_ptr<SegmentInMemory>>(id).reset();
void ComponentManager::decrement_entity_fetch_count(EntityId id) {
if (registry_.get<std::atomic<EntityFetchCount>>(id).fetch_sub(1) == 0) {
// This entity will never be accessed again
// Ideally would call registry_.destroy(id), or at least registry_.erase<std::shared_ptr<SegmentInMemory>>(id)
// at this point. However, they are both slower than this, and would require taking a unique_lock on the
// shared_mutex, so just decrement the ref count of the only sizeable component, so that when the shared pointer
// goes out of scope in the calling function, the memory is freed
registry_.get<std::shared_ptr<SegmentInMemory>>(id).reset();
debug::check<ErrorCode::E_ASSERTION_FAILURE>(!registry_.get<std::shared_ptr<SegmentInMemory>>(id),
"SegmentInMemory memory retained in ComponentManager");
}
}

void ComponentManager::update_entity_fetch_count(EntityId id, EntityFetchCount count) {
registry_.get<std::atomic<EntityFetchCount>>(id).store(count);
}


Expand Down
15 changes: 6 additions & 9 deletions cpp/arcticdb/processing/component_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <atomic>
#include <shared_mutex>

#include <entt/entity/registry.hpp>

Expand Down Expand Up @@ -84,7 +85,7 @@ class ComponentManager {
for (auto id: ids) {
registry_.replace<T>(id, value);
if constexpr (std::is_same_v<T, EntityFetchCount>) {
registry_.get<std::atomic<EntityFetchCount>>(id).store(value);
update_entity_fetch_count(id, value);
}
}
}
Expand All @@ -96,7 +97,7 @@ class ComponentManager {
for (auto [idx, id]: folly::enumerate(ids)) {
registry_.replace<T>(id, values[idx]);
if constexpr (std::is_same_v<T, EntityFetchCount>) {
registry_.get<std::atomic<EntityFetchCount>>(id).store(values[idx]);
update_entity_fetch_count(id, values[idx]);
}
}
}
Expand All @@ -115,12 +116,7 @@ class ComponentManager {
}
if (decrement_fetch_count) {
for (auto id: ids) {
// This entity will never be accessed again
if (registry_.get<std::atomic<EntityFetchCount>>(id).fetch_sub(1) == 0) {
erase_entity(id);
debug::check<ErrorCode::E_ASSERTION_FAILURE>(!registry_.get<std::shared_ptr<SegmentInMemory>>(id),
"SegmentInMemory memory retained in ComponentManager");
}
decrement_entity_fetch_count(id);
}
}
}
Expand All @@ -138,7 +134,8 @@ class ComponentManager {
}

private:
void erase_entity(EntityId id);
void decrement_entity_fetch_count(EntityId id);
void update_entity_fetch_count(EntityId id, EntityFetchCount count);

entt::registry registry_;
std::shared_mutex mtx_;
Expand Down

0 comments on commit 7cf53f3

Please sign in to comment.